public void InsertCart(CartInfo obj_cart) { using (OnlineShoppingDataContext db = new OnlineShoppingDataContext()) { tbl_cart table_cart = (from a in db.tbl_carts where a.CustomerID == obj_cart.CustomerID && a.ProductID == obj_cart.ProductID select a).FirstOrDefault(); if (table_cart != null) { table_cart.Quantity = Convert.ToInt32(table_cart.Quantity) + obj_cart.Quantity; db.SubmitChanges(); } else { tbl_cart table_Cart = new tbl_cart(); Guid id = Guid.NewGuid(); table_Cart.CartID = id.ToString(); table_Cart.ProductID = obj_cart.ProductID; table_Cart.CustomerID = obj_cart.CustomerID; table_Cart.Quantity = obj_cart.Quantity; db.tbl_carts.InsertOnSubmit(table_Cart); db.SubmitChanges(); } } }
public void UpdateCart(CartInfo obj_cart) { using (OnlineShoppingDataContext db = new OnlineShoppingDataContext()) { tbl_cart table_cart = (from a in db.tbl_carts where a.CartID == obj_cart.CartID select a).FirstOrDefault(); if (table_cart != null) { table_cart.Quantity = obj_cart.Quantity; db.SubmitChanges(); } } }
public void DeleteAllCartByCustomerID(string customerID) { using (OnlineShoppingDataContext db = new OnlineShoppingDataContext()) { var table_carts = (from a in db.tbl_carts where a.CustomerID == customerID select a).ToList(); foreach (var obj in table_carts) { tbl_cart table_cart = (from a in db.tbl_carts where a.CartID == obj.CartID select a).FirstOrDefault(); db.tbl_carts.DeleteOnSubmit(table_cart); db.SubmitChanges(); } } }