Exemplo n.º 1
0
        public async Task <ActionResult> UpdateOrder(int id, CustomerOrderForUpdateDto updates)
        {
            try
            {
                if (!Enum.IsDefined(typeof(CustomerOrderStatus), updates.Status))
                {
                    return(BadRequest("Status doesn't exist"));
                }

                CustomerOrder order = await dbContext.CustomerOrders.Where(co => co.Id == id)
                                      .Include(co => co.Customer)
                                      .Include(co => co.OrderItems)
                                      .ThenInclude(oi => oi.Product)
                                      .FirstOrDefaultAsync();

                if (order == null)
                {
                    return(NotFound($"Order with Id: {id} not found"));
                }

                order.Status = updates.Status;
                dbContext.CustomerOrders.Update(order);

                await dbContext.SaveChangesAsync();

                return(Ok(new Response <CustomerOrderFullDto>(mapper.Map <CustomerOrderFullDto>(order))));
            }
            catch
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Exemplo n.º 2
0
 public async Task <Response <CustomerOrderFullDto> > EditOrder(string id, CustomerOrderForUpdateDto order)
 {
     try
     {
         return(await httpClient.PutJsonAsync <Response <CustomerOrderFullDto> >("api/customerorders/" + id, order));
     }
     catch
     {
         return(null);
     }
 }
Exemplo n.º 3
0
        protected override async Task OnInitializedAsync()
        {
            IsLoading = true;
            var result = await CustomerOrderService.GetOrder(Id);

            Order       = result.Data;
            OrderUpdate = new CustomerOrderForUpdateDto()
            {
                Status = Order.Status
            };
            IsLoading = false;
        }