public async Task<int> SaveOrderAsync(Order order)
 {
     if (order.Id == 0)
     {
         context.Orders.Add(order);
     }
     return await context.SaveChangesAsync();
 }
 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);
     }
 }
 public async Task<ActionResult> SaveOrder(Order order)
 {
     await repo.SaveOrderAsync(order);
     return RedirectToAction("Orders");
 }