Exemplo n.º 1
0
        public IActionResult Get_Order(int id)
        {
            if (id <= 0)
            {
                return(BadRequest("Id must be greater than zero."));
            }

            var order = customerLogic.GetOrder(id); //TODO Change to Team context;

            if (order == null)
            {
                return(NotFound());
            }

            try
            {
                return(Ok(Order_DTO.MapFromModel(order)));
            }
            catch (Exception ex)
            {
#if DEBUG
                throw;
#endif
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex));
            }
        }
Exemplo n.º 2
0
        public IActionResult ChangeOrderStatus(int id, [FromBody] OrderStatusChangeRequest data)
        {
            if (id <= 0)
            {
                return(BadRequest("Id must be greater than zero."));
            }

            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState));
            }

            Order order;

            try
            {
                switch (data.Status)
                {
                case OrderStatus.InProgress:
                    order = _shopLogic.SetOrderState_InProgress(id);
                    break;

                case OrderStatus.ReadyToReceive:
                    order = _shopLogic.SetOrderState_ReadyToReceive(id);
                    break;

                case OrderStatus.Finished:
                    order = _shopLogic.SetOrderState_Finished(id);
                    break;

                default:
                    throw new NotImplementedException($"Status {data.Status} is not supporrted");
                }

                return(Ok(Order_DTO.MapFromModel(order)));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
#if DEBUG
                throw;
#endif
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex));
            }
        }
Exemplo n.º 3
0
        public async System.Threading.Tasks.Task <IActionResult> GetAllAsync()
        {
            try
            {
                var orders = await customerLogic.GetOrdersAsync();

                AddTeamDataToOrders(orders);

                return(Ok(orders.Select(o => Order_DTO.MapFromModel(o))));
            }
            catch (Exception ex)
            {
#if DEBUG
                throw;
#endif
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex));
            }
        }
Exemplo n.º 4
0
        public IActionResult Get([FromQuery] int teamId)
        {
            if (teamId <= 0)
            {
                return(BadRequest("Id must be greater than zero."));
            }

            var orders = customerLogic.GetTeamOrders(new Model.Team {
                Id = teamId
            }).Result;                                                                       //TODO Change to Team context;

            if (orders.Any() == false)
            {
                return(NotFound());
            }

            AddTeamDataToOrders(orders);

            return(Ok(orders.Select(order => Order_DTO.MapFromModel(order))));
        }