Created
October 6, 2017 14:32
-
-
Save abel-masila/8ad6e0a4225753b27d9817437cc99d83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int UpdateCartCount(int? id, int cartCount) | |
{ | |
// Get the cart | |
var cartItem = db.CartItem.Single( | |
cart => cart.cart_id == ShoppingCartId | |
&& cart.item_id == id); | |
int itemCount = 0; | |
//get Promos | |
var promos = db.Promotions.Single(promo=>promo.Buy_ItemId==id); | |
if (cartItem != null) | |
{ | |
if (cartCount > 0) | |
{ | |
cartItem.Count = cartCount; | |
itemCount = cartItem.Count; | |
if (cartCount >= promos.BuyX_Qty) | |
{ | |
var NewCartItem = new CartItem | |
{ | |
item_id = promos.GetYId, | |
product_no = promos.ItemsEntity.product_no, | |
cart_id = ShoppingCartId, | |
Quantity = promos.GetY_Qty, | |
Count = promos.GetY_Qty, | |
Cart_type = "Promotion", | |
DateCreated = DateTime.Now | |
}; | |
db.CartItem.Add(NewCartItem); | |
} | |
} | |
else | |
{ | |
db.CartItem.Remove(cartItem); | |
} | |
// Save changes | |
db.SaveChanges(); | |
} | |
return itemCount; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment