public static void Add(List<Cart> items, string itemId, int uniqueId, bool isShoppingCart) { int index = 0; bool found = false; using (var context = new PetShopDataContext()) { var options = new DataLoadOptions(); options.LoadWith<Item>(i => i.Product); var item = items.FirstOrDefault(i => i.ItemId == itemId); if (item != null) { context.Cart.Attach(item); item.Quantity++; } else { var cartItem = context.Item.GetByKey(itemId); var cart = new Cart(); cart.UniqueID = uniqueId; cart.ItemId = itemId; cart.Name = cartItem.Name; cart.ProductId = cartItem.ProductId; cart.IsShoppingCart = isShoppingCart; cart.Price = cartItem.ListPrice ?? cartItem.UnitCost ?? 0; cart.Type = cartItem.Product.Name; cart.CategoryId = cartItem.Product.CategoryId; cart.Quantity = 1; items.Add(cart); context.Cart.InsertOnSubmit(cart); } context.SubmitChanges(); } }
private void OnCartListRemove(Cart entity) { SendPropertyChanging(null); entity.Profile = null; SendPropertyChanged(null); }
private void OnCartListAdd(Cart entity) { SendPropertyChanging(null); entity.Profile = this; SendPropertyChanged(null); }