public async Task<int> SaveOrderAsync(Order order)
 {
     if (order.Id == 0)
     {
         context.Orders.Add(order);
     }
     return await context.SaveChangesAsync();
 }
Beispiel #2
0
 public async Task<IHttpActionResult> CreateOrder(Order order)
 {
     if (ModelState.IsValid)
     {
         IDictionary<int, Product> products = 
             Repository.Products
                 .Where(p => order.Lines.Select(ol => ol.ProductId)
                 .Any(id => id == p.Id)).ToDictionary(p => p.Id);
         order.TotalCost = order.Lines.Sum(ol => ol.Count * products[ol.ProductId].Price);
         await Repository.SaveOrderAsync(order);
         return Ok();
     }
     else
     {
         return BadRequest(ModelState);
     }
 }
Beispiel #3
0
 public async Task<ActionResult> SaveOrder(Order order)
 {
     await repo.SaveOrderAsync(order);
     return RedirectToAction("Orders");
 }