示例#1
0
        private IQueryable <Recipe> GetRecipesQuery(RecipesFilterCriteria filterCriteria)
        {
            var queryUpper = string.IsNullOrEmpty(filterCriteria.Query) ? "" : filterCriteria.Query.ToUpper();

            var results = Context.Recipes
                          .Include(rec => rec.RecipeIngredients).ThenInclude(ri => ri.Ingredient)
                          .Include(rec => rec.Category)
                          .Include(rec => rec.Photos)
                          .Where(rec =>
                                 rec.IsValid
                                 &&
                                 filterCriteria.IsPublished.HasValue ? rec.IsPublished.Equals(filterCriteria.IsPublished) : true
                                 &&
                                 (
                                     string.IsNullOrEmpty(queryUpper)
                                     ||
                                     rec.Name.ToUpper().Contains(queryUpper)
                                     ||
                                     rec.Description.ToUpper().Contains(queryUpper)
                                 )
                                 &&
                                 filterCriteria.CategoryId.HasValue ? rec.CategoryId.Equals(filterCriteria.CategoryId) : true
                                 &&
                                 filterCriteria.RecipeType.HasValue ? rec.RecipeType.Equals(filterCriteria.RecipeType) : true
                                 );

            return(results);
        }
示例#2
0
        public IEnumerable <RecipeWithCoverPhotoDto> GetAllRecipesWithCoverPhoto(RecipesFilterCriteria filterCriteria)
        {
            var results = GetRecipesQuery(filterCriteria);

            var dtoResults = results.OrderByDescending(dto => dto.ModificationDate).Select(rec => new RecipeWithCoverPhotoDto()
            {
                Id           = rec.Id,
                Name         = rec.Name,
                Description  = rec.Description,
                RecipeType   = rec.RecipeType,
                IsPublished  = rec.IsPublished,
                CategoryId   = rec.CategoryId,
                CategoryName = rec.Category.Name,
                CreationDate = rec.CreationDate,
                CoverPhoto   = rec.Photos.Where(ph => ph.IsValid && ph.IsCover).Select(ph => new PhotoDto()
                {
                    Id      = ph.Id,
                    Name    = ph.Name,
                    Url     = ph.Url,
                    IsCover = ph.IsCover,
                }).FirstOrDefault(),
            }).AsEnumerable();


            return(dtoResults);
        }
示例#3
0
        public IEnumerable <RecipeWithFullDetailsDto> GetAllRecipesWithFullDetails(RecipesFilterCriteria filterCriteria)
        {
            var results = GetRecipesQuery(filterCriteria);

            var dtoResults = results.OrderByDescending(dto => dto.ModificationDate).Select(rec => new RecipeWithFullDetailsDto()
            {
                Id                = rec.Id,
                Name              = rec.Name,
                Description       = rec.Description,
                RecipeType        = rec.RecipeType,
                IsPublished       = rec.IsPublished,
                CategoryId        = rec.CategoryId,
                CategoryName      = rec.Category.Name,
                CreationDate      = rec.CreationDate,
                RecipeIngredients = rec.RecipeIngredients.Where(ri => ri.IsValid).Select(ri => new RecipeIngredientDto()
                {
                    Id             = ri.Id,
                    IngredientId   = ri.IngredientId,
                    IngredientName = ri.Ingredient.Name,
                    Amount         = ri.Amount,
                    Unit           = ri.Unit,
                    IsChecked      = true,
                }),
                Photos = rec.Photos.Where(ph => ph.IsValid).Select(ph => new PhotoDto()
                {
                    Id      = ph.Id,
                    Name    = ph.Name,
                    Url     = ph.Url,
                    IsCover = ph.IsCover,
                }),
            }).AsEnumerable();

            return(dtoResults);
        }
示例#4
0
        public IEnumerable <RecipeDto> GetAllRecipes(RecipesFilterCriteria filterCriteria)
        {
            var results = GetRecipesQuery(filterCriteria);

            var dtoResults = results.OrderByDescending(dto => dto.ModificationDate).Select(rec => new RecipeDto()
            {
                Id           = rec.Id,
                Name         = rec.Name,
                Description  = rec.Description,
                RecipeType   = rec.RecipeType,
                IsPublished  = rec.IsPublished,
                CategoryId   = rec.CategoryId,
                CategoryName = rec.Category.Name,
                CreationDate = rec.CreationDate,
            }).AsEnumerable();

            return(dtoResults);
        }