示例#1
0
        public ActionResult Get([FromQuery] RecipeFilter filter)
        {
            ActionResult  retval = BadRequest();
            List <Recipe> recipes;

            try
            {
                recipes = _service.GetRecipes(filter);

                if (recipes != null)
                {
                    if (filter.RecipeId != null && recipes.Count > 0)
                    {
                        retval = new OkObjectResult(recipes[0]);
                    }
                    else
                    {
                        retval = new OkObjectResult(recipes);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex);
            }

            return(retval);
        }
        public List <Recipe> GetRecipes(RecipeFilter filter)
        {
            List <Recipe>       retval = null;
            IQueryable <Recipe> query;

            try
            {
                // Generate the Recipe Query
                query = RecipeQuery(filter);

                // Execute Query
                retval = query.ToList();

                // Post Query Manipulation
                foreach (Recipe recipe in retval)
                {
                    // Sort the Instructions
                    recipe.Instructions = recipe.Instructions.OrderBy(i => i.SortOrder).ToList();
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex);
            }

            return(retval);
        }
示例#3
0
 public Task <List <IRecipe> > GetByCategoryAsync(string categoryId, RecipeFilter filter = null)
 {
     try
     {
         return(Repository.GetByCategoryAsync(categoryId, filter));
     }
     catch (Exception e)
     {
         throw e;
     }
 }
示例#4
0
 public Task <List <IRecipe> > GetAsync(RecipeFilter filter = null)
 {
     try
     {
         return(Repository.GetAsync(filter));
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        private IQueryable <Recipe> RecipeQuery(RecipeFilter filter)
        {
            IQueryable <Recipe> query = null;

            try
            {
                if (filter != null)
                {
                    // Core Query
                    query = _context.Recipes.Select(r => r);

                    // Include Instructions
                    if (filter.IncludeInstructions)
                    {
                        query = query.Include(r => r.Instructions);
                    }

                    // Include Ingredients
                    if (filter.IncludeIngredients)
                    {
                        query = query.Include(r => r.Ingredients);
                    }

                    // Where Clauses
                    if (filter.RecipeId != null)
                    {
                        query = query.Where(r => r.RecipeId == filter.RecipeId);
                    }

                    if (!filter.IncludeDeleted)
                    {
                        query = query.Where(f => f.IsDeleted == false);
                    }

                    // Order By the Recipe Name ASC
                    query = query.OrderBy(r => r.Name);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex);
            }

            return(query);
        }
示例#6
0
        public async Task <IEnumerable <string> > FilterAsync(RecipeFilter filter)
        {
            var keys = new List <string>();

            if (filter.Vegan != null)
            {
                keys.Add(KeyRegistry.Recipes.Vegan.Append(filter.Vegan.Value));
            }
            if (filter.OvernightPreparation != null)
            {
                keys.Add(KeyRegistry.Recipes.OvernightPreparation.Append(filter.OvernightPreparation.Value));
            }
            if (filter.IngredientIds != null && filter.IngredientIds.Length > 0)
            {
                keys.Add(await CacheProxy.CombineAsync(new CombineOptions(LogicalOperator.Or, KeyRegistry.Recipes.IngredientId, filter.IngredientIds)));
            }
            if (filter.Regions != null && filter.Regions.Length > 0)
            {
                keys.Add(await CacheProxy.CombineAsync(new CombineOptions(LogicalOperator.Or, KeyRegistry.Recipes.Region, filter.Regions)));
            }
            if (filter.Cuisines != null && filter.Cuisines.Length > 0)
            {
                keys.Add(await CacheProxy.CombineAsync(new CombineOptions(LogicalOperator.Or, KeyRegistry.Recipes.Cuisine, filter.Cuisines)));
            }
            if (filter.SpiceLevels != null && filter.SpiceLevels.Length > 0)
            {
                keys.Add(await CacheProxy.CombineAsync(new CombineOptions(LogicalOperator.Or, KeyRegistry.Recipes.SpiceLevel, filter.SpiceLevels.ToStrings())));
            }
            if (filter.TotalTimes != null && filter.TotalTimes.Length > 0)
            {
                keys.Add(await CacheProxy.CombineAsync(new CombineOptions(LogicalOperator.Or, KeyRegistry.Recipes.TotalTime, filter.TotalTimes.ToStrings())));
            }
            if (filter.Collections != null && filter.Collections.Length > 0)
            {
                keys.Add(await CacheProxy.CombineAsync(new CombineOptions(LogicalOperator.Or, KeyRegistry.Recipes.Collection, filter.Collections)));
            }
            if (keys.Count == 0)
            {
                return(new string[0]);
            }
            return(await CacheProxy.MembersAsync(await CacheProxy.CombineAsync(new CombineOptions(LogicalOperator.And, keys.ToArray()))));
        }
示例#7
0
        public virtual async Task <List <IRecipe> > GetAsync(string ingradientId, RecipeFilter filter = null)
        {
            try
            {
                if (filter == null)
                {
                    filter = new RecipeFilter(1, 5);
                }
                //Any() returns bool
                var result = await Repository.WhereAsync <Recipe>()
                             .Where(t => t.RecipeIngradients.Where(c => c.IngradientId == ingradientId).Any())
                             .OrderBy(a => a.RecipeTitle)
                             .Skip((filter.PageNumber * filter.PageSize) - filter.PageSize)
                             .Take(filter.PageSize).ToListAsync();

                return(Mapper.Map <List <IRecipe> >(result));
            }
            catch (Exception e)
            {
                throw e.InnerException;
            }
        }
示例#8
0
        public virtual async Task <List <IRecipe> > GetAsync(RecipeFilter filter = null)
        {
            try
            {
                if (filter == null)
                {
                    filter = new RecipeFilter(1, 5);
                }


                return(Mapper.Map <List <IRecipe> >(
                           await Repository.WhereAsync <Recipe>()
                           .OrderBy(a => a.RecipeTitle)
                           .Skip((filter.PageNumber * filter.PageSize) - filter.PageSize)
                           .Take(filter.PageSize).ToListAsync()
                           ));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
示例#9
0
        public async virtual Task <List <IRecipe> > GetByCategoryAsync(string categoryId, RecipeFilter filter = null)
        {
            try
            {
                if (filter == null)
                {
                    filter = new RecipeFilter(1, 5);
                }


                return(Mapper.Map <List <IRecipe> >(
                           await Repository.WhereAsync <Recipe>()
                           .Where(item => item.CategoryId == categoryId)
                           .OrderBy(a => a.RecipeTitle)
                           .Skip((filter.PageNumber * filter.PageSize) - filter.PageSize)
                           .Take(filter.PageSize).ToListAsync()
                           ));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
示例#10
0
        public async Task <IEnumerable <Recipe> > GetByFilter(RecipeFilter filter)
        {
            Task <IEnumerable <Recipe> > recipes = GetAll();


            recipes = GetByRating(filter.Rating, recipes);
            recipes = GetByVotes(filter.Votes, recipes);

            if (filter.Cost > 0)
            {
                recipes = GetByCost(filter.Cost, recipes);
            }
            if (filter.Name != "")
            {
                recipes = GetByName(filter.Name, recipes);
            }
            if (filter.CookingTime != 0)
            {
                recipes = GetByCookingTime(filter.CookingTime, recipes);
            }
            if (filter.IncludingBrands.Count != 0)
            {
                recipes = GetByBrands(filter.IncludingBrands, recipes);
            }
            if (filter.IncludingIngreditents.Count != 0)
            {
                recipes = GetByIngredients(filter.IncludingIngreditents, recipes);
            }
            if (filter.OnlyStores.Count != 0)
            {
                recipes = GetByStores(filter.OnlyStores, recipes);
            }



            return(await recipes);
        }
        public async Task <IActionResult> FilterRecipes([FromBody] FilterDTO filterDTO)
        {
            List <Product> includingProducts = new List <Product>();
            List <Product> includingBrands   = new List <Product>();
            List <Store>   onlyStores        = new List <Store>();

            List <string> includedProductsList = filterDTO.IncludedProducts.Split(',').ToList();
            List <string> includingBrandsList  = filterDTO.IncludingBrands.Split(',').ToList();
            List <string> onlyStoresList       = filterDTO.OnlyStores.Split(',').ToList();

            foreach (var product in includedProductsList)
            {
                includingProducts.AddRange(await _productsRepository.GetByName(product));
            }
            foreach (var brand in includingBrandsList)
            {
                includingBrands.AddRange(await _productsRepository.GetByBrand(brand));
            }
            foreach (var store in onlyStoresList)
            {
                onlyStores.AddRange(await _storesRepository.GetByName(store));
            }

            RecipeFilter filter = new RecipeFilter
            {
                Cost                  = filterDTO.Cost,
                Name                  = filterDTO.Name,
                Rating                = filterDTO.Rating,
                Votes                 = filterDTO.VotesNumber,
                CookingTime           = filterDTO.CookingTime,
                IncludingIngreditents = includingProducts,
                IncludingBrands       = includingBrands,
                OnlyStores            = onlyStores
            };

            return(Ok(await _recipesRepository.GetByFilter(filter)));
        }
示例#12
0
 public async Task <IActionResult> Filter([FromBody] RecipeFilter filter)
 {
     return((await _recipeRepository.FilterAsync(filter)).ToActionResult());
 }
示例#13
0
 public Task <RepositoryResponse <IEnumerable <string> > > FilterAsync(RecipeFilter filter)
 {
     return(ExecuteAsync(() => RecipeCache.FilterAsync(filter), "Cannot filter Recipes with " + JsonConvert.SerializeObject(filter, Formatting.Indented), Sources.Cache));
 }
示例#14
0
 public async Task <ActionResult <ListResponse <RecipeResponse> > > GetRecipesListAsync([FromQuery] RecipeFilter recipe, [FromQuery] ListOptions options, [FromServices] ListQuery <RecipeResponse, RecipeFilter> query) =>
 await query.RunAsync(recipe, options);
 public Task <IEnumerable <Recipe> > GetByFilter(RecipeFilter filter)
 {
     throw new NotImplementedException();
 }