public void fillWholeStore(int quantity) { using (warehouseContext) { foreach (var item in warehouseContext.wItems.ToList()) { storeItems storeItem = new storeItems { Name = " ", Quantity = 0, Manufacturer = " ", Description = " ", Price = 0 }; storeItem.Name = item.Name; storeItem.Quantity += quantity; storeItem.Manufacturer = item.Manufacturer; storeItem.Price = item.Price; storeItem.Description = item.Description; item.Quantity -= quantity; storeContext.storeItems.Add(storeItem); warehouseContext.SaveChanges(); storeContext.SaveChanges(); } } }
public async Task <IActionResult> Edit(int id, [Bind("storeItemId,Name,Description,Manufacturer,Price,Quantity")] storeItems storeItems) { if (id != storeItems.storeItemId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(storeItems); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!storeItemsExists(storeItems.storeItemId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(storeItems)); }
public async Task <IActionResult> Create([Bind("storeItemId,Name,Description,Manufacturer,Price,Quantity")] storeItems storeItems) { if (ModelState.IsValid) { _context.Add(storeItems); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(storeItems)); }
public void fillWholeStore(int quantity) { if (!storeContext.storeItems.Any()) { using (warehouseContext) { foreach (var item in warehouseContext.wItems.ToList()) { storeItems storeItem = new storeItems { Name = " ", Quantity = 0, Manufacturer = " ", Description = " ", Price = 0 }; if (item.Quantity > quantity) //adding check for warehouse availability { storeItem.Name = item.Name; storeItem.Quantity += quantity; storeItem.Manufacturer = item.Manufacturer; storeItem.Price = item.Price; storeItem.Description = item.Description; item.Quantity -= quantity; storeContext.storeItems.AddAsync(storeItem); } warehouseContext.SaveChangesAsync(); storeContext.SaveChangesAsync(); } } } else { using (storeContext) { foreach (var itm in storeContext.storeItems.ToList()) { var w = warehouseContext.wItems.FirstOrDefault(i => i.Name == itm.Name); if (w.Quantity > quantity) { itm.Quantity += quantity; w.Quantity -= quantity; warehouseContext.wItems.Update(w); storeContext.SaveChanges(); warehouseContext.SaveChanges(); } } } } }
public void orderSpecificItem(int quantity, storeItems storeItem) { // wItems wItem = new wItems(); using (warehouseContext) { foreach (var i in warehouseContext.wItems.ToList()) { if (i.Name.Equals(storeItem.Name)) { storeItem.Quantity += quantity; // storeContext.storeItems.Add(storeItem); i.Quantity -= quantity; } warehouseContext.SaveChanges(); storeContext.SaveChanges(); } } }