Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,CustomerID,OrderDate,OrderStatus")] OrdersData.Order order)
        {
            if (id != order.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                if (await ExecuteCommandSafe(_mediator.Send(new UpdateOrderV1Command {
                    Order = order
                })))
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }

            var webOrder = await _mediator.Send(new GetOrderDetailsV1Query { OrderID = id });

            var orderStatuses = new List <SelectListItem>
            {
                new SelectListItem(nameof(OrderStatuses.Received), ((int)OrderStatuses.Received).ToString()),
                new SelectListItem(nameof(OrderStatuses.Shipped), ((int)OrderStatuses.Shipped).ToString()),
                new SelectListItem(nameof(OrderStatuses.Cancelled), ((int)OrderStatuses.Cancelled).ToString())
            };

            ViewData["OrderStatus"] = new SelectList(orderStatuses, "Value", "Text", webOrder.OrderStatus);

            return(View(webOrder));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("CustomerID")] OrdersData.Order order)
        {
            if (ModelState.IsValid)
            {
                order.OrderDate   = DateTime.Now.Date;
                order.OrderStatus = OrderStatuses.Received;

                if (await ExecuteCommandSafe(_mediator.Send(new CreateOrderV1Command {
                    Order = order
                })))
                {
                    return(RedirectToAction(nameof(Edit), new { id = order.ID }));
                }
            }

            ViewData["CustomerID"] = new SelectList(await _mediator.Send(new GetAllCustomersV1Query()), "ID", "FullName");

            return(View(order));
        }