public async Task <Sale> CreateAsync(Sale sale) { int stock = 0; foreach (var saleProduct in sale.SaleProduct) { stock = context.Product.Where(p => p.ProductId == saleProduct.ProductId).Select(p => p.Stock).First(); if (stock == 0 || saleProduct.Quantity > stock) { throw new Exception("There is no stock for this product."); } } context.Add(sale); await context.SaveChangesAsync(); return(sale); }
public async Task CreateAsync(Client client) { context.Add(client); await context.SaveChangesAsync(); }
public async Task CreateAsync(Product product) { context.Add(product); await context.SaveChangesAsync(); }