public async Task <IActionResult> CheckOut( OrderViewModel orderModel, [FromServices] IOrdersService ordersService, [FromServices] UserManager <User> userManager) { var cartModel = GetCartViewModel(); if (!ModelState.IsValid) { return(View(nameof(Index), new CartOrderViewModel { Cart = cartModel, Order = orderModel })); } var userName = User.Identity?.Name; var user = await userManager.FindByNameAsync(userName); if (user is null) { throw new InvalidOperationException($"User {userName} is not found."); } var order = CreateOrder(user, cartModel, orderModel); await ordersService.Add(order); _cartService.Clear(); return(RedirectToAction(nameof(OrderConfirmed), new { order.Id })); }
public ActionResult Add([FromBody] Order value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var order = service.Add(value); if (order != null) { return(CreatedAtAction("Get", new { id = order.Id }, order)); } return(BadRequest("Failed Validation")); }
public ActionResult create(string id, DateTime date, string orderstatus, int total, int addressID, string customerID) { try { Orders orders = new Orders { Date = date, AddressId = addressID, CustomerId = customerID, OrderStatus = orderstatus, Total = total }; _ordersService.Add(orders); _ordersService.SaveChanges(); return(Ok(orders.Id)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IActionResult Post([FromBody] Order order) { ordersService.Add(order); return(CreatedAtRoute(new { id = order.Id }, order)); }