public void AddItemsToCart(CustomerStorelocationProductsViewModel customerStorelocationProductsViewModel) { List <Product> allProducts = GetAllProducts(); //List<Product> cartProducts = new List<Product>(); Inventory productInventory = new Inventory(); for (int i = 0; i < customerStorelocationProductsViewModel.quantityToAddToCart; i++) { foreach (var item in allProducts) { if (item.productName == customerStorelocationProductsViewModel.VMproductName) { currentCartProducts.Add(item); foreach (var x in currentStoreInventory) { if (x.productId == item.ProductId) { productInventory = x; x.decrementInventory(); rs.Save(); } } } } } }
public void SetNumOfCasesTest() { CustomerStorelocationProductsViewModel c = new CustomerStorelocationProductsViewModel(); c.SetNumOfCases(3); Assert.True(c.numOfCases == 3); }
// GET: StoreLocationController/Details/5 public ActionResult PlaceOrder(CustomerStorelocationProductsViewModel c) { CartViewModel cartViewModel = blc.GetCartViewModel(); blc.PlaceOrder(c); return(View("PlaceOrder", cartViewModel)); }
public CustomerStorelocationProductsViewModel SetNumOfProductsAndIds(CustomerStorelocationProductsViewModel c) { foreach (var item in allProducts) { if (item.productName == "Guitar") { foreach (var x in currentStoreInventory) { if (x.productId == item.ProductId) { c.SetNumOfGuitars(x.quantity); } } } if (item.productName == "Amplifier") { foreach (var x in currentStoreInventory) { if (x.productId == item.ProductId) { c.SetNumOfAmplifiers(x.quantity); } } } if (item.productName == "Strings") { foreach (var x in currentStoreInventory) { if (x.productId == item.ProductId) { c.SetNumOfStrings(x.quantity); } } } if (item.productName == "Case") { foreach (var x in currentStoreInventory) { if (x.productId == item.ProductId) { c.SetNumOfCases(x.quantity); } } } } try { c.SetCustomerId(loggedInCustBLC.CustomerId); } catch (Exception e) { } c.SetStoreId(currentStore.StoreId); return(c); }
public void PlaceOrder(CustomerStorelocationProductsViewModel c) { Order newOrder = new Order(loggedInCustBLC.CustomerId, currentStore.StoreId); rs.AddOrderToHistory(newOrder); rs.Save(); foreach (var item in currentCartProducts) { PurchasedProducts purchasedProducts = new PurchasedProducts(newOrder.OrderId, item.ProductId); rs.AddPurchasedProduct(purchasedProducts); rs.Save(); } currentCartProducts = new List <Product>(); }
public ActionResult AddToCart(CustomerStorelocationProductsViewModel customerStorelocationProductsViewModel) { if (customerStorelocationProductsViewModel.VMproductName == "Guitar") { if (customerStorelocationProductsViewModel.quantityToAddToCart > customerStorelocationProductsViewModel.numOfGuitars || customerStorelocationProductsViewModel.quantityToAddToCart != 1) { string location = blc.GetCurrentStoreLocation().location; // ModelState.AddModelError("Failure", "You can only buy 1 of that items at a timer"); return(RedirectToAction("Choice", new { LocationAbreviation = location })); } } if (customerStorelocationProductsViewModel.VMproductName == "Amplifier") { if (customerStorelocationProductsViewModel.quantityToAddToCart > customerStorelocationProductsViewModel.numOfAmplifiers || customerStorelocationProductsViewModel.quantityToAddToCart != 1) { string location = blc.GetCurrentStoreLocation().location; // ModelState.AddModelError("Failure", "You can only buy 1 of that items at a timer"); return(RedirectToAction("Choice", new { LocationAbreviation = location })); } } if (customerStorelocationProductsViewModel.VMproductName == "Case") { if (customerStorelocationProductsViewModel.quantityToAddToCart > customerStorelocationProductsViewModel.numOfCases || customerStorelocationProductsViewModel.quantityToAddToCart != 1) { string location = blc.GetCurrentStoreLocation().location; // ModelState.AddModelError("Failure", "You can only buy 1 of that items at a timer"); return(RedirectToAction("Choice", new { LocationAbreviation = location })); } } if (customerStorelocationProductsViewModel.VMproductName == "Strings") { if (customerStorelocationProductsViewModel.quantityToAddToCart > customerStorelocationProductsViewModel.numOfStrings) { string location = blc.GetCurrentStoreLocation().location; // ModelState.AddModelError("Failure", "You can only buy 1 of that items at a timer"); return(RedirectToAction("Choice", new { LocationAbreviation = location })); } } blc.SetStoreLocation(customerStorelocationProductsViewModel.defaultStore); blc.AddItemsToCart(customerStorelocationProductsViewModel); StoreLocation local = blc.GetCurrentStoreLocation(); string locationString = local.location; return(Choice(locationString)); }
// GET: StoreLocationController public ActionResult Choice(string LocationAbreviation) { Customer cust = blc.GetLoggedInCustBLC(); StoreLocation stLocation = blc.getStoreLocationByAbreviation(LocationAbreviation); List <Inventory> inv = blc.GetInventoryByStoreId(stLocation.StoreId); List <Product> pro = blc.GetAllProducts(); int qty = 0; string VMproductName = ""; var customerStorelocationProductsViewModel = new CustomerStorelocationProductsViewModel(cust, stLocation, inv, pro, qty, VMproductName); customerStorelocationProductsViewModel = blc.SetNumOfProductsAndIds(customerStorelocationProductsViewModel); return(View("StoreLocation2", customerStorelocationProductsViewModel)); // return View(); }