public void ProcessOrder(List <ShopCartLineDTO> cart, ShoppingDetailsDTO shoppingDetails, int businessEntityID, string email) { ShopCartItem shopCart = GetCartItem(cart); ShoppingDetails shopDetails = GetShoppingDetails(shoppingDetails); orderProcessor.ProcessOrder(shopCart, shopDetails, businessEntityID, email); }
public async Task <bool> AddToCartAsync(int productId, int shopCartId) { bool operationResult = false; var productToAdd = await _products.GetByIdAsync(productId); if (productToAdd.Amount > 0) { var item = await _items.FindOne(x => x.ProductId == productId && x.ShopCartId == shopCartId); if (item == null) { ShopCartItem newItem = new ShopCartItem() { ShopCartId = shopCartId, Product = productToAdd, Quantity = 1 }; operationResult = await _items.AddAsync(newItem); } else { item.Quantity++; operationResult = await _items.UpdateAsync(item); } productToAdd.Amount--; await _products.UpdateAsync(productToAdd); } return(operationResult); }
public async Task <IActionResult> UpdateShopCartItem(Guid productId, ShopCartItem item) { var shopCart = await GetShopCartClient(); var itemShopCart = await GetValidShopCartItem(productId, shopCart, item); if (itemShopCart == null) { return(CustomResponse()); } shopCart.UpdateUnits(item, item.Quantity); ValidatingShopCart(shopCart); if (!ValidOperation()) { return(CustomResponse()); } _context.ShopCartItems.Update(itemShopCart); _context.ShopCartClients.Update(shopCart); await PersistData(); return(CustomResponse()); }
private void HandleNewCartItem(ShopCartItem item) { var cartItem = new ShopCartClient(_user.GetUserId()); cartItem.AddItem(item); ValidatingShopCart(cartItem); _context.ShopCartClients.Add(cartItem); }
public RedirectToActionResult RemoveFromCart(int id) { ShopCartItem item = _shopCart.Find(id); _shopCart.RemoveFromCart(item); return(RedirectToAction("Index")); }
public ActionResult Payment(long?sp) { ViewBag.TotalMoney = 0; ViewBag.TotalGram = 0; LoadDropdown loadDropdown = new LoadDropdown(); ViewBag.Location = loadDropdown.SearchLocationParenId(1, null); if (Session != null) { var entity = NlCheckout.GetSessionCard(Session); List <ShopCartItem> shopCartItems = new List <ShopCartItem>(); List <long> listIdShop = new List <long>(); if (sp == null) { foreach (var item in entity) { if (!listIdShop.Exists(x => x.Equals(item.Product.MemberId))) { listIdShop.Add(item.Product.MemberId); var shop = shopsBusiness.GetById(item.Product.MemberId); ShopCartItem shopCartItem = new ShopCartItem(); shopCartItem.ShopCart = shop; var listCart = entity.Where(x => x.Product.MemberId == item.Product.MemberId).ToList(); shopCartItem.ListCartItems = listCart; shopCartItems.Add(shopCartItem); } } } else { foreach (var item in entity) { if (!listIdShop.Exists(x => x.Equals(sp))) { listIdShop.Add(item.Product.MemberId); var shop = shopsBusiness.GetById((long)sp); ShopCartItem shopCartItem = new ShopCartItem(); shopCartItem.ShopCart = shop; var listCart = entity.Where(x => x.Product.MemberId == sp).ToList(); shopCartItem.ListCartItems = listCart; shopCartItems.Add(shopCartItem); } } var shopCartItemsentity = shopCartItems.FirstOrDefault(); ViewBag.TotalMoney = shopCartItemsentity.ListCartItems.Sum(x => x.Product.Price); var totalWeghit = 0.0; foreach (var listCartItem in shopCartItemsentity.ListCartItems) { totalWeghit += listCartItem.Quantity * listCartItem.Product.Weight; } ViewBag.TotalGram = totalWeghit; } return(View(shopCartItems)); } return(RedirectToRoute(new { controller = "Home", action = "Index" })); }
public async Task <bool> UpdateAsync(ShopCartItem item) { bool result = false; if (await _db.ShopCartItems.AnyAsync(x => x.Id == item.Id)) { _db.Entry(item).State = EntityState.Modified; result = await _db.SaveChangesAsync() > 0; } return(result); }
public void ProcessOrder(ShopCartItem cart, ShoppingDetails shoppingDetails, int businessEntityID, string email) { using (var scope = new TransactionScope()) { InsertAddress(shoppingDetails, businessEntityID); int workerID = MinSalesWorker(shoppingDetails.City); int orderID = InsertPurchaseOrderHeader(cart, businessEntityID, shoppingDetails.Country); UpdateStatus(orderID, workerID); sender.SendMessage(email, "Manager assigned! Check your order page"); scope.Complete(); } }
private ShopCartItem GetCartItem(List <ShopCartLineDTO> cart) { ShopCartItem shopCart = new ShopCartItem(); foreach (var item in cart) { shopCart.AddItem(new Product { Name = item.ProductDTO.Name, ProductID = item.ProductDTO.ProductID, ListPrice = item.ProductDTO.ListPrice }, item.Quantity); } return(shopCart); }
public ActionResult Success() { try { double transportfee = 0; ViewBag.TotalMoney = 0; ViewBag.TotalGram = 0; LoadDropdown loadDropdown = new LoadDropdown(); ViewBag.Location = loadDropdown.SearchLocationParenId(1, null); if (Session != null) { var entity = NlCheckout.GetSessionCard(Session); ShopCartItem shopCartItem = new ShopCartItem(); // ShopCartItem shopCartItem = new ShopCartItem(); var listCart = entity.Where(x => x.Product.MemberId == 0).ToList(); shopCartItem.ListCartItems = listCart; // shopCartItems.Add(shopCartItem); // var shopCartItemsentity = shopCartItems.FirstOrDefault(); ViewBag.TotalMoney = shopCartItem.ListCartItems.Sum(x => x.Product.Price); var totalWeghit = 0.0; foreach (var listCartItem in shopCartItem.ListCartItems) { totalWeghit += listCartItem.Quantity * listCartItem.Product.Weight; } ViewBag.TotalGram = totalWeghit; Member member = SessionUtility.GetSessionMember(Session); if (member != null) { var loctionmember = member.MemberProfile.Address + ", " + new LocationsBusiness().SearchAddress(member.MemberProfile.LocationId); //var km = new FunctionCountKm().GetDistance(locationshop, loctionmember); //transportfee=FuntionMember.CountMoneyTransport(km, totalWeghit, loctionmember); } ViewBag.Transportfee = transportfee; return(View(shopCartItem)); } } catch { } return(View()); }
private void HandlerExistentShopCart(ShopCartClient cart, ShopCartItem item) { var productItemExistent = cart.ShopCartItemExists(item); cart.AddItem(item); ValidatingShopCart(cart); if (productItemExistent) { _context.ShopCartItems.Update(cart.GetByProductId(item.ProductId)); } else { _context.ShopCartItems.Add(item); } _context.ShopCartClients.Update(cart); }
public async Task DeleteFromCart(Product product) { ShopCart cart = await GetCart(); var cartItems = await _cartRepository.GetItems(cart.Id); if (cartItems.Any(i => i.Product.Id == product.Id && i.ShopCartId == cart.Id)) { ShopCartItem item = cartItems.FirstOrDefault(i => i.Product.Id == product.Id && i.ShopCartId == cart.Id); item.Count--; if (item.Count == 0) { await _cartRepository.RemoveCartItem(item); } else { await _cartRepository.UpdateCartItem(item); } await _cartRepository.SaveChangesAsync(); } }
public async Task <IActionResult> AddShopCartItem(ShopCartItem item) { var shopCart = await GetShopCartClient(); if (shopCart == null) { HandleNewCartItem(item); } else { HandlerExistentShopCart(shopCart, item); } if (!ValidOperation()) { return(CustomResponse()); } await PersistData(); return(CustomResponse()); }
private int InsertPurchaseOrderHeader(ShopCartItem cart, int businessEntityID, string country) { decimal totalPrice = 0; PurchaseOrderDetail orderDetails = new PurchaseOrderDetail(); var orderHeader = new PurchaseOrderHeader() { RevisionNumber = 1, Status = 1, ShipMethodID = 1, OrderDate = DateTime.Now, ModifiedDate = DateTime.Now, BusinessEntityID = businessEntityID }; foreach (var items in cart.Lines) { decimal subtotal = items.Product.ListPrice * items.Quantity; totalPrice += subtotal; orderDetails = new PurchaseOrderDetail { DueDate = DateTime.Now.AddDays(3), OrderQty = (short)items.Quantity, ProductID = items.Product.ProductID, UnitPrice = items.Product.ListPrice, LineTotal = subtotal, ReceivedQty = items.Quantity, RejectedQty = 0, StockedQty = items.Quantity, ModifiedDate = DateTime.Now }; orderHeader.PurchaseOrderDetails.Add(orderDetails); } orderHeader.SubTotal = totalPrice; orderHeader.TaxAmt = GetTaxRate(country) / 100 * totalPrice; orderHeader.Freight = ShipBaseRate() / 100 * totalPrice; orderHeader.TotalDue = totalPrice + orderHeader.Freight + orderHeader.TaxAmt; using (var context = new AWContext()) { context.PurchaseOrderHeader.Add(orderHeader); context.SaveChanges(); } return(orderHeader.PurchaseOrderID); }
public async Task AddToCart(Product product) { ShopCart cart = await GetCart(); var cartItems = await _cartRepository.GetItems(cart.Id); if (cartItems.Any(t => t.Product.Id == product.Id && t.ShopCartId == cart.Id)) { ShopCartItem item = cartItems.FirstOrDefault(t => t.Product.Id == product.Id && t.ShopCartId == cart.Id); item.Count++; await _cartRepository.UpdateCartItem(item); } else { ShopCartItem shopCartItem = new ShopCartItem() { ShopCartId = cart.Id, ProductId = product.Id, Count = 1, }; await _cartRepository.CreateCartItem(shopCartItem); } await _cartRepository.SaveChangesAsync(); }
public ShopCartDto AddItem(ShopCartAddInput input) { ShopCartItem shopCartItem = input.MapTo <ShopCartItem>(); return(ShopCartManager.AddItem(shopCartItem).MapTo <ShopCartDto>()); }
public async Task CreateCartItem(ShopCartItem shopCartItem) { await _context.CartItems.AddAsync(shopCartItem); }
public async Task RemoveCartItem(ShopCartItem shopCartItem) { _context.CartItems.Remove(shopCartItem); }
public async Task UpdateCartItem(ShopCartItem shopCartItem) { _context.CartItems.Update(shopCartItem); }
public async Task <bool> DeleteAsync(ShopCartItem item) { _db.ShopCartItems.Remove(item); return(await _db.SaveChangesAsync() > 0); }
private async Task <ShopCartItem> GetValidShopCartItem(Guid productId, ShopCartClient shopCart, ShopCartItem item = null) { if (item != null && productId != item.ProductId) { AddProcessingError("Item doesn't match with to the informed"); return(null); } if (shopCart == null) { AddProcessingError("Shop cart not found"); return(null); } var shopCartItem = await _context.ShopCartItems .FirstOrDefaultAsync(i => i.ShopCartId == shopCart.Id && i.ProductId == productId); if (shopCartItem == null || !shopCart.ShopCartItemExists(shopCartItem)) { AddProcessingError("Item isn't on shop cart"); return(null); } return(shopCartItem); }
public decimal CalculatePromotionPrice(ShopCartItem item) { throw new NotImplementedException(); }
public async Task <bool> AddAsync(ShopCartItem item) { await _db.ShopCartItems.AddAsync(item); return(await _db.SaveChangesAsync() > 0); }