示例#1
0
        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);
        }
示例#2
0
 public async Task CreateAsync(Client client)
 {
     context.Add(client);
     await context.SaveChangesAsync();
 }
示例#3
0
 public async Task CreateAsync(Product product)
 {
     context.Add(product);
     await context.SaveChangesAsync();
 }