public int ConfirmOrder(ref Cart cart) { var orderId = 0; using (var transacton = _ordersRepository.DataContext.Database.BeginTransaction()) { try { var order = new Order { MemberId = cart.MemberId, OrderValue = cart.CartTotalPriceOut, CreationDate = DateTime.Now }; _ordersRepository.Add(order); _ordersRepository.DataContext.SaveChanges(); var orderOrderStatus = new OrderOrderStatus { OrderId = order.OrderId, OrderOrderStatusId = (int)OrderStatusType.Confirmed, CreationDate = DateTime.Now }; _orderOrderStatusRepository.Add(orderOrderStatus); _orderOrderStatusRepository.DataContext.SaveChanges(); order.LatestOrderStatusId = orderOrderStatus.OrderOrderStatusId; _ordersRepository.DataContext.SaveChanges(); if (order.OrderId > 0 && cart.Items != null) { foreach (var item in cart.Items) { var orderItem = new OrderItem { OrderId = order.OrderId, ProductId = item.ProductId, ProductCount = item.ProductCount, PriceOut = item.PriceOut, TotalPriceOut = item.TotalPriceOut, CreationDate = DateTime.Now }; _orderItemRepository.Add(orderItem); _orderItemRepository.DataContext.SaveChanges(); } } transacton.Commit(); ClearCart(ref cart); orderId = order.OrderId; } catch (Exception) { transacton.Rollback(); } } return orderId; }
public void SaveCart(Cart cart) { if (cart.MemberId > 0) { var repository = new MongoRepository<Cart>(); if (string.IsNullOrEmpty(cart.Id)) { repository.Add(cart); } else { repository.Update(cart); } } }
public static CartModel Map(Cart cart) { var model = new CartModel(); if (cart != null) { model.MemberId = cart.MemberId; model.CartProductCount = cart.CartProductCount; model.CartTotalCbm = cart.CartTotalCbm; model.CartTotalPriceOut = cart.CartTotalPriceOut; if (cart.Items != null) { foreach (var cartItem in cart.Items) { model.CartItems.Add(CartItemModelMapper.Map(cartItem)); } } } return model; }
public void ChangeProductCount(int productId, int productCount, Cart cart) { var product = _productHandler.GetById(productId); if (product != null) { if (cart.Items == null) { cart.Items = new List<CartItem>(); } var item = cart.Items.Find(p => p.ProductId == productId); if (item != null) { item.ProductCount = productCount; if (productCount == 0) { cart.Items.Remove(item); } } SaveCart(cart); } }
public void AddProduct(int productId, int productCount, Cart cart) { var product = _productHandler.GetById(productId); if (product != null) { if (cart.Items == null) { cart.Items = new List<CartItem>(); } var item = cart.Items.Find(p => p.ProductId == productId); if (item != null) { item.ProductCount += productCount; } else { var newItem = CartItem(product, productCount); cart.Items.Add(newItem); } SaveCart(cart); } }
public void SaveCart(Cart cart) { _cartRepository.SaveCart(cart); }
private Cart GetCart() { var member = PublicUser.GetCurrentUser(); if (member != null && member.MemberId > 0) { return CartHandler.GetCart(member.MemberId); } var cart = (Cart)Session[Constants.CartKeyName]; if (cart == null) { cart = new Cart(); Session[Constants.CartKeyName] = cart; } return cart; }
private void ClearCart(ref Cart cart) { cart = new Cart { Id = cart.Id, MemberId = cart.MemberId }; }