public CartItem Add(int partID = 0, int quantity = 1) { APIPart part = CURTAPI.GetPart(partID); string upcval = part.attributes.Where(x => x.key.ToLower().Equals("upc")).Select(x => x.value).FirstOrDefault(); CartItem i = new CartItem(partID, quantity, Convert.ToDecimal(part.listPrice.Replace("$", "")), part.shortDesc, upcval); EcommercePlatformDataContext db = new EcommercePlatformDataContext(); try { CartItem item = db.CartItems.Where(x => x.partID == partID).Where(x => x.order_id == this.ID).First<CartItem>(); item.quantity += quantity; } catch { i.order_id = this.ID; db.CartItems.InsertOnSubmit(i); }; db.SubmitChanges(); if (this.CartItems.Any(item => item.partID == i.partID)) { this.CartItems.Where(x => x.partID.Equals(partID)).FirstOrDefault<CartItem>().quantity += quantity; } else { this.CartItems.Add(i); } return i; }
partial void DeleteCartItem(CartItem instance);
partial void UpdateCartItem(CartItem instance);
partial void InsertCartItem(CartItem instance);
private void detach_CartItems(CartItem entity) { this.SendPropertyChanging(); entity.Cart = null; }
private void attach_CartItems(CartItem entity) { this.SendPropertyChanging(); entity.Cart = this; }