public List <LocationInventoryViewModel> AddToCart(List <LocationInventoryViewModel> livmList, LocationInventoryViewModel livm, CustomUser user) { var iloc = livm.Location.LocationId; var uloc = user.DefaultStore; CartInventory cInv = _repo.cartInventories.FirstOrDefault(x => x.CartId == user.CartId && x.ProductId == livm.ProductId); if (cInv == null) { cInv = new CartInventory { CartId = user.CartId, ProductId = livm.ProductId }; _repo.cartInventories.Add(cInv); } LocationInventory lInv = _repo.locationInventories.FirstOrDefault(z => z.LocationId == livm.Location.LocationId && z.ProductId == livm.ProductId); if (cInv != null && lInv.Quantity >= livm.purchaseQuantity) { cInv.CartQuantity += livm.purchaseQuantity; lInv.Quantity -= livm.purchaseQuantity; livm.Quantity -= livm.purchaseQuantity; livm.purchaseQuantity = 0; _repo.CommitSave(); } var l = livmList.FirstOrDefault(x => x.ProductId == livm.ProductId); l = livm; return(livmList); }
public LocationInventoryViewModel CreateLocationInventoryViewModel(LocationInventory locationInventory, Location location, Product product) { LocationInventoryViewModel livm = new LocationInventoryViewModel() { Location = location, ProductId = product.ProductId, Description = product.Description, Price = product.Price, Quantity = locationInventory.Quantity, }; return(livm); }
public ActionResult Details(int id) { int productId = id; var claimsIdentity = (ClaimsIdentity)User.Identity; if (claimsIdentity == null) { return(RedirectToAction("Index", "Home")); } List <LocationInventoryViewModel> livmList = _logicClass.DisplayLocationInventory(_logicClass.GetCurrentUser(claimsIdentity)); LocationInventoryViewModel livm = livmList.FirstOrDefault(x => x.ProductId == productId); return(View("ItemDetailView", livm)); }
public ActionResult AddToCart(LocationInventoryViewModel livm) { if (!ModelState.IsValid) { return(View("ShopView")); } var claimsIdentity = (ClaimsIdentity)User.Identity; if (claimsIdentity == null) { return(RedirectToAction("Index", "Home")); } var user = _logicClass.GetCurrentUser(claimsIdentity); List <LocationInventoryViewModel> livmList = _logicClass.DisplayLocationInventory(user); livmList = _logicClass.AddToCart(livmList, livm, user); return(RedirectToAction("Shop")); }