public async Task <ActionResult> GetOrder(Guid id)
        {
            try
            {
                IGetOrderByIdRequest getOrderByIdRequest = new GetOrderByIdRequest(id);
                IGetOrderResponse    getOrderResponse    = await _orderProvider.GetOrderById(getOrderByIdRequest);

                IGetOrderPositionsResponse getOrderPositionsResponse = await _orderPositionsProvider.GetOrderPositionsByOrderId(new GetOrderPositionsByOrderIdRequest(id));

                return(getOrderResponse.Result switch
                {
                    OrderProvideResultEnum.Success => (ActionResult)Ok(new GetOrderResponseModel
                    {
                        Order = _objectToApiModelConverter.ConvertOrder(getOrderResponse.Order),
                        Restaurant = _objectToApiModelConverter.ConvertRestaurant(_restaurantProvider.GetRestaurant(new GetRestaurantRequest(getOrderResponse.Order.RestaurantId)).Result.Restaurant),
                        OrderPositions = getOrderPositionsResponse.OrderPositions.Select(x =>
                                                                                         new ExtendedOrderPositionApiModel
                        {
                            Id = x.Id,
                            CreationDate = x.CreationDate,
                            MealId = x.MealId,
                            Meal = _objectToApiModelConverter.ConvertMeal(_mealProvider.GetMealById(new GetMealByIdRequest(x.MealId))?.Result?.Meal),
                            UserId = x.UserId,
                            OrderId = x.OrderId,
                            User = _objectToApiModelConverter.ConvertUser(_userProvider.GetUserById(new ProvideUserRequest(x.UserId))?.Result?.User)
                        }).ToList(),
                        OrderBoy = _objectToApiModelConverter.ConvertUser(_userProvider.GetUserById(new ProvideUserRequest(getOrderResponse.Order.OrderBoyId)).Result.User)
                    }),
                    OrderProvideResultEnum.NotFound => NotFound(),
                    OrderProvideResultEnum.Exception => StatusCode(500),
                    OrderProvideResultEnum.Forbidden => Forbid(),
                    _ => throw new ArgumentOutOfRangeException()
                });
            }
Пример #2
0
        public async Task <IOrderUpdateResponse> MarkOrderAsOrdered(IOrderUpdateRequest request)
        {
            try
            {
                IGetOrderByIdRequest getOrderByIdRequest  = new GetOrderByIdRequest(request.Id);
                IGetOrderResponse    getOrderByIdResponse = await _orderProvider.GetOrderById(new GetOrderByIdRequest(request.Id));

                switch (getOrderByIdResponse.Result)
                {
                case OrderProvideResultEnum.Success:
                    break;

                case OrderProvideResultEnum.NotFound:
                    return(new OrderUpdateResponse(UpdateOrderResultEnum.NotFound));

                case OrderProvideResultEnum.Exception:
                    return(new OrderUpdateResponse(UpdateOrderResultEnum.Exception));

                case OrderProvideResultEnum.Forbidden:
                    return(new OrderUpdateResponse(UpdateOrderResultEnum.Forbidden));

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (getOrderByIdResponse.Order.OrderBoyId != request.CurrentLoggedInUserId)
                {
                    return(new OrderUpdateResponse(UpdateOrderResultEnum.Forbidden));
                }

                await _orderRepository.MarkOrderAsOrdered(request.Id);

                return(new OrderUpdateResponse(UpdateOrderResultEnum.Success));
            }
            catch (Exception ex)
            {
                _logger.Log(ex);
                return(new OrderUpdateResponse(UpdateOrderResultEnum.Exception));
            }
        }