public async Task <IActionResult> GetRecipes([FromQuery] RecipeParameters recipeParameters) { var userId = ""; try { var token = Request.Headers[HeaderNames.Authorization].ToString().Remove(0, 7); var email = _authManager.GetUserEmail(token); userId = await _authManager.GetUserId(email); } catch (System.Exception) { BadRequest(new { message = "Wrong payload" }); } recipeParameters.Cuisine = recipeParameters.Cuisine?.First()?.Split(","); recipeParameters.Category = recipeParameters.Category?.First()?.Split(","); var recipes = await _repository.Recipe.GetAllRecipesAsync(userId, recipeParameters, trackChanges : false); Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(recipes.MetaData)); var recipesDto = ConvertRecipesToRecipesWithLikedRecipeIdDto(recipes, userId); return(Ok(recipesDto)); }
public ActionResult <PaginatedReadRecipeDto> GetAllRecipes([FromQuery] RecipeParameters recipeParameters) { var recipes = _recipeService.GetAllRecipes(recipeParameters, GetUserId()); _logger.LogInformation($"Returned {recipes.TotalCount} recipes from database."); return(Ok(recipes)); }
public PagedList <Recipe> GetRecipesByCategory(RecipeParameters recipeParameters) { return(PagedList <Recipe> .ToPagedList(_db.Recipes .Include(rcp => rcp.Category) .Include(rcp => rcp.Ingredients) .Include(rcp => rcp.MethodItems) .Where(r => r.DeletedAt == null) .Where(r => r.CategoryId == recipeParameters.Id), recipeParameters.PageNumber, recipeParameters.PageSize)); }
public PagedList <Recipe> GetAllRecipes(RecipeParameters recipeParameters) { return(PagedList <Recipe> .ToPagedList(_db.Recipes .Include(rcp => rcp.Category) .Include(rcp => rcp.Ingredients) .Include(rcp => rcp.MethodItems) .Where(r => r.DeletedAt == null) .Where(r => string.IsNullOrEmpty(recipeParameters.Text) || r.Name.Contains(recipeParameters.Text) || r.Category.Name.Contains(recipeParameters.Text)), recipeParameters.PageNumber, recipeParameters.PageSize)); }
public async Task <PagedList <Recipe> > GetAllRecipesAsync(string userId, RecipeParameters recipeParameters, bool trackChanges) { var recipes = await FindAll(trackChanges) .Include(r => r.LikedRecipes) .FilterRecipes(recipeParameters.Cuisine, recipeParameters.Category, recipeParameters.ComplexityLevel) .Search(recipeParameters.SearchTerm) .OrderBy(r => r.Name) .ToListAsync(); return(PagedList <Recipe> .ToPagedList(recipes, recipeParameters.PageNumber, recipeParameters.PageSize)); }
public bool FillModules(RecipeParameters recipeParams, Recipe recipe, Entity entity, Goods fuel, out ModuleEffects effects, out RecipeParameters.UsedModule used) { effects = new ModuleEffects(); var beaconedModules = 0; var nonBeaconedModules = 0; Item nonBeacon = null; foreach (var module in list) { float multiplier; if (module.inBeacon) { if (beacon != null) { beaconedModules += module.fixedCount; multiplier = beacon.beaconEfficiency * module.fixedCount; } else { multiplier = 0f; } } else { var count = module.fixedCount > 0 ? module.fixedCount : Math.Max(0, entity.moduleSlots - nonBeaconedModules); multiplier = count; nonBeaconedModules += count; if (nonBeacon == null) { nonBeacon = module.module; } } effects.AddModules(module.module.module, multiplier); } used = new RecipeParameters.UsedModule { module = nonBeacon, count = nonBeaconedModules }; if (beaconedModules > 0 && beacon != null) { used.beacon = beacon; used.beaconCount = ((beaconedModules - 1) / beacon.moduleSlots + 1); } return(list.Count > 0); }
public void GetModulesInfo(RecipeParameters recipeParams, Recipe recipe, Entity entity, Goods fuel, ref ModuleEffects effects, ref RecipeParameters.UsedModule used) { ModuleFillerParameters filler = null; if (modules == null || modules.beacon == null) { filler = GetModuleFiller(); } if (modules == null) { filler?.GetModulesInfo(recipeParams, recipe, entity, fuel, ref effects, ref used); } else { modules.GetModulesInfo(recipeParams, recipe, entity, fuel, ref effects, ref used, filler); } }
public PaginatedRecipeList GetAllRecipes(RecipeParameters recipeParameters) { return(PaginatedRecipeList.ToPagedList( _db.Recipes .Where(r => (recipeParameters.Tags == null || recipeParameters.Tags.Count <= 0) || r.Tags.Any(t => recipeParameters.Tags.Contains(t.Name))) .Where(r => string.IsNullOrWhiteSpace(recipeParameters.SearchText) || r.Title.ToUpper().Contains(recipeParameters.SearchText)) .Include(r => r.Ingredients) .Include(r => r.Votes) .Include(r => r.Tags) .AsSplitQuery() .OrderBy(r => r.Title), recipeParameters.PageNumber, recipeParameters.PageSize)); }
public async Task <IActionResult> GetRecipesForUser([FromQuery] RecipeParameters recipeParameters, string userId) { var user = await _repository.User.GetUserAsync(userId, trackChanges : false); if (user == null) { return(NotFound()); } recipeParameters.Cuisine = recipeParameters.Cuisine?.First()?.Split(","); recipeParameters.Category = recipeParameters.Category?.First()?.Split(","); var recipesFromDb = await _repository.Recipe.GetRecipesForUserAsync(userId, recipeParameters, trackChanges : false); Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(recipesFromDb.MetaData)); var recipesDto = _mapper.Map <IEnumerable <RecipesDto> >(recipesFromDb); return(Ok(recipesDto)); }
public IEnumerable <RecipeVM> GetPublishedRecipes([FromQuery] RecipeParameters recipeParameters) { var recipeFromService = _recipesService.GetAllRecipes(recipeParameters); var metaData = new { recipeFromService.TotalCount, recipeFromService.PageSize, recipeFromService.CurrentPage, recipeFromService.TotalPages, recipeFromService.HasNext, recipeFromService.HasPrevious }; var list = recipeFromService.Select(r => new RecipeVM { RecipeId = r.RecipeId, Name = r.Name, CategoryName = r.Category.Name, DescriptionPrimary = r.DescriptionPrimary, DescriptionSecondary = r.DescriptionSecondary, ImageUrl = r.ImageUrl }).ToList(); // get all images from container var uris = _recipesService.GetAllUrisByContainer(); list.ForEach(r => { if (r.ImageUrl != null) { var uri = uris.FirstOrDefault(u => u.AbsoluteUri.Contains(r.ImageUrl)); if (uri != null) { r.ImageFile = uri.AbsoluteUri; } } }); Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metaData)); return(list); }
public static recipe initializeBlankRecipe() { recipe newRecipe = new recipe(); currentRecipeId = "-1"; newRecipe.name = ""; newRecipe.description = ""; newRecipe.style = new style(); newRecipe.recipeStats = new RecipeStatistics { abv = 0, fg = 0, og = 0, srm = 0, ibu = 0 }; RecipeParameters rp = new RecipeParameters { fermentableCalcType = "basic", ibuBoilTimeCurveFit = -0.04F, ibuCalcType = "basic", intoFermenterVolume = 0 }; newRecipe.recipeParameters = rp; newRecipe.equipmentProfile = RecipeTools.getDefaultEquipmentProfile(); newRecipe.adjuncts = new List <adjunctAddition>(); newRecipe.fermentables = new List <fermentableAddition>(); newRecipe.hops = new List <hopAddition>(); newRecipe.yeasts = new List <yeastAddition>(); //hopAddition a = new hopAddition(); //a.hopID = ""; //a.type = ""; //a.additionGuid = ""; //a.amount = 0; //a.time = 0; //hopbase b = new hopbase(); //b.aau = 1; //b.type = "idk"; //b.substitutes = ""; //b.createdByUserId = ""; //b.idString = ""; //b.name = "Centennial"; //b.notes = ""; //b.origin = ""; //a.hop = b; //newRecipe.hops.Add(a); // fermentable f = new fermentable // { // color = 6, // name = "2 Row", // yield = 14.65F, // maltster = "Breiss" // }; // fermentableAddition fa = new fermentableAddition // { // use = "Mash", // weight = 12.5F, // fermentable = f // }; // yeast y = new yeast // { // attenuation = 1.05F, // lab = "Wyeast", // name = "Wheat" // }; // yeastAddition ya = new yeastAddition // { // yeast = y //}; // adjunct ad = new adjunct // { // name = "Cocoa nibs" // }; // adjunctAddition aa = new adjunctAddition // { // adjunct = ad, // amount = 2, // time = 60, // timeUnit = "min", // type = "boil", // unit = "oz" // }; // newRecipe.fermentables.Add(fa); // newRecipe.yeasts.Add(ya); // newRecipe.adjuncts.Add(aa); return(newRecipe); }
public PagedList <Recipe> GetRecipesByQuery(RecipeParameters recipeParameters) { throw new NotImplementedException(); }
internal PaginatedReadRecipeDto GetAllRecipes(RecipeParameters recipeParameters, string id) { return(_mapper.Map <PaginatedReadRecipeDto>(_recipeRepository.GetAllRecipes(recipeParameters), opt => opt.Items["UserId"] = id)); }