public async Task <bool> Add(InventoryProductDTO request) { var product = await DbContext.Products.SingleOrDefaultAsync(x => x.Id == request.ProductId); var inventory = await DbContext.Inventories.SingleOrDefaultAsync(x => x.Id == request.InventoryId); if (product is null) { throw new AppException("Product not found"); } if (inventory is null) { throw new AppException("Product not found"); } var inventoryProduct = new InventoryProduct() { Quantity = request.Quantity, Inventory = inventory, Product = product }; await DbContext.InventoryProducts.AddAsync(inventoryProduct); await DbContext.SaveChangesAsync(); return(true); }
public async Task <IActionResult> Add([FromBody] InventoryProductDTO request) { var res = await InventoryProductService.Add(request); return(Ok(res)); }