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