Ejemplo n.º 1
0
        public async Task <ICollection <DishResponseModel> > Handle(GetDishesQuery request, CancellationToken cancellationToken)
        {
            var dishes = await _dishRepository.GetAsync();

            var response = dishes.Adapt <ICollection <DishResponseModel> >();

            return(response);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetAsync()
        {
            var query = new GetDishesQuery();

            var response = await _mediator.Send(query);

            return(JsonResult(response));
        }
        public async Task <IReadOnlyCollection <DishDto> > Handle(GetDishesQuery request, CancellationToken cancellationToken)
        {
            var dishes = await dishRepository.GetAll();

            var dishesDtos = mapper.Map <IReadOnlyCollection <DishDto> >(dishes);

            return(dishesDtos);
        }
            public async Task <List <Dish> > Handle(GetDishesQuery request,
                                                    CancellationToken cancellationToken)
            {
                string selectCommandText = @"SELECT Dish.DishId, Dish.DishTitle, 
                Dish.DishDescription, Dish.DishSlug, DishCategory.DishCategoryId, DishCategory.DishCategoryTitle
                FROM Dish JOIN DishCategory ON Dish.DishCategoryId = DishCategory.DishCategoryId";

                int userId = 0;

                if (!string.IsNullOrEmpty(request.Username))
                {
                    var user = await _userAuth.GetUser(request.Username);

                    if (user == null)
                    {
                        throw new RestException(HttpStatusCode.NotFound, new { User = "******" });
                    }

                    userId             = user.Id;
                    selectCommandText += @" WHERE Dish.UserId = @userId";
                }

                selectCommandText += @" ORDER BY Dish.DishId
                OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY";



                var dishesFromDB = await _dish.GetDishes(userId, selectCommandText, request.Offset, request.Limit);

                if (dishesFromDB.Count > 0)
                {
                    selectCommandText = @"SELECT Ingredients.IngredientId, Ingredients.IngredientName, Ingredients.IngredientDescription, 
                    Ingredients.IngredientSlug, Recipe.Amount
                    FROM Recipe
                    JOIN Ingredients ON Recipe.IngredientId = Ingredients.IngredientId
                    WHERE Recipe.DishId = @dishId";

                    foreach (var dish in dishesFromDB)
                    {
                        dish.Ingredients = await _ingredient.GetIngredientsByDishId(dish.Id, selectCommandText);
                    }
                }


                return(dishesFromDB);
            }
        public async Task <IReadOnlyCollection <Dish> > Handle(GetDishesQuery request, CancellationToken cancellationToken)
        {
            var dishes = await orderFulfilmentService.GetDishes();

            return(dishes);
        }