void AddToNewCart(HttpCookie cookie, int count, int?id) { var product = ArtContext.Products.Single(id); // ** Unit of Work Pattern using (var uow = new ArtUnitOfWork()) { // ** Prototype Pattern var cart = new Cart(true) { Cookie = cookie.Value }; uow.Insert(cart); // ** Prototype Pattern var item = new CartItem(true) { CartId = cart.Id, Quantity = count, ProductId = id, Price = product.Price }; uow.Insert(item); } }
// creates an order by adding records to order tables and deleting record from cart tables. public static void CreateOrder(Order order, IEnumerable <OrderDetail> details, Cart cart, IEnumerable <CartItem> items) { // ** Unit of Work pattern using (var uow = new ArtUnitOfWork()) { // insert order and order details uow.Insert(order); details.ForEach(d => { d.OrderId = order.Id; uow.Insert(d); }); // delete cartitems and cart items.ForEach(i => uow.Delete(i)); uow.Delete(cart); } }