public async Task PerformStockRequest(StockRequest s) { var ownerItem = await _context.OwnerInventory. SingleOrDefaultAsync(r => r.ProductID == s.ProductID); var storeItem = await _context.StoreInventory. Where(r => r.StoreID == s.StoreID). SingleOrDefaultAsync(r => r.ProductID == s.ProductID); //Add product to store if not currently in Inventory. if (storeItem == null) { StoreInventory item = new StoreInventory { StoreID = s.StoreID, ProductID = s.ProductID, StockLevel = s.Quantity }; _context.StoreInventory.Add(item); await _context.SaveChangesAsync(); } else { storeItem.StockLevel += s.Quantity; } //Decrease owner product stock level. ownerItem.StockLevel -= s.Quantity; // Remove stock request _context.StockRequests.Remove(s); await _context.SaveChangesAsync(); }
public async Task <bool> IsStockAvailable(StockRequest s) { var query = await GetOwnerInventory(s.ProductID); OwnerInventory item = query.First(); var test = item.StockLevel; return(item.StockLevel >= s.Quantity); }
public async Task AddItemToStoreInventory(StockRequest s) { //Add item to storeInventory StoreInventory item = new StoreInventory { StoreID = this.StoreID, ProductID = s.ProductID, StockLevel = s.Quantity }; this._context.StoreInventory.Add(item); this._context.SaveChanges(); return; }
public async void MakeStockRequest(StockRequest s) { return; }