Beispiel #1
0
        public IHttpActionResult ChangeStatus(ChangeOrderStatusDTO model)
        {
            var result = orderService.ChangeStatus(model.OrderId, model.StatusId);

            if (!result.Success)
            {
                return(InternalServerError());
            }
            return(Ok());
        }
        public async Task <ActionResult> ChangeOrderStatus([FromBody] ChangeOrderStatusDTO cos)
        {
            GenericResponseDTO genericResponseDTO = new GenericResponseDTO();
            Order o = new Order();

            //Check if order exist
            try
            {
                o = await _context.orders.FirstOrDefaultAsync(x => x.OrderId == cos.OrderId);
            }
            catch
            {
                genericResponseDTO.Message = "No order with that order Id exist";
                return(NotFound(genericResponseDTO));
            }

            //Check if status is valid
            if (cos.Status >= 0 && cos.Status <= 4)
            {
                o.Status = (Statuses)cos.Status;
            }
            else
            {
                genericResponseDTO.Message = "The status is not valid. Try one of the following:" +
                                             "\n0. In progress" +
                                             "\n1. Accepted" +
                                             "\n2. Declined" +
                                             "\n3. Cart";

                return(BadRequest(genericResponseDTO));
            }

            _context.Entry(o).State = EntityState.Modified;

            await _context.SaveChangesAsync();

            genericResponseDTO.Message = "Order status was successfully changed";
            return(Ok(genericResponseDTO));
        }