Skip to content

Instantly share code, notes, and snippets.

@abel-masila
Created October 6, 2017 14:32
Show Gist options
  • Save abel-masila/8ad6e0a4225753b27d9817437cc99d83 to your computer and use it in GitHub Desktop.
Save abel-masila/8ad6e0a4225753b27d9817437cc99d83 to your computer and use it in GitHub Desktop.
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