Exemple #1
0
 public async Task <bool> CreateAsync(Product product)
 {
     context.Products.Add(product);
     try
     {
         return(await context.SaveChangesAsync() == 1);
     }
     catch (DbUpdateException)
     {
         return(false);
     }
 }
Exemple #2
0
        public async Task <int> CreateAsync(Order order)
        {
            Debug.WriteLine(context.Entry(order).State);
            //is there an existing provisional order with this account id
            if (context.Orders.Any(o => o.AccountId == order.AccountId &&
                                   o.OrderStatus == OrderStatus.Provisional))
            {
                throw new InvalidOperationException("A provisional order for this AccountId already exists");
            }
            context.Add(order); //if the Account property is set, a row will be added to the Account table
            Debug.WriteLine(context.Entry(order).State);
            await context.SaveChangesAsync();

            Debug.WriteLine(context.Entry(order).State);
            return(order.OrderId);
        }