public bool AddItemToCart(int userId, int productId, int locationId, int n) { if (!repo.SetLocationInventory(productId, locationId, -n, true)) { return(false); } return(repo.AddItemToCart(userId, productId, locationId, n, true)); }
public void SetLocationInventoryNegativeShouldNotWorkDelta() { Product prod = new Product { ProductName = "testprod", ProductPrice = 1 }; Location loc = new Location { LocationName = "testloc", LocationAddress = "asdf" }; using (var ctx = new StoreContext(options)) { StoreRepoDB repo = new StoreRepoDB(ctx); ctx.Products.Add(prod); ctx.Locations.Add(loc); ctx.SaveChanges(); Inventory inv = new Inventory { ProductId = prod.ProductId, LocationId = loc.LocationId, Quantity = 0 }; ctx.Inventories.Add(inv); repo.SetLocationInventory(prod.ProductId, loc.LocationId, -10, true); ctx.SaveChanges(); } using (var assertCtx = new StoreContext(options)) { StoreRepoDB repo = new StoreRepoDB(assertCtx); var inv = assertCtx.Inventories.FirstOrDefault(inv => inv.ProductId == prod.ProductId && inv.LocationId == loc.LocationId); Assert.NotNull(inv); Assert.Equal(0, inv.Quantity); } }