Beispiel #1
0
        public async Task <IActionResult> ById(string recipeId)
        {
            var recipe = this.recipesService.ReturnRecipe(recipeId);
            var user   = await this.userManager.FindByIdAsync(recipe.UserId);

            var currentlyLoggedUser = await this.userManager.GetUserAsync(this.User);

            var viewModel = new FullRecipeViewModel
            {
                RecipeId            = recipe.Id,
                UserId              = recipe.UserId,
                Username            = user.UserName,
                CurrentlyLoggeduser = currentlyLoggedUser.UserName,
                Title        = recipe.Title,
                Level        = recipe.Level,
                CreatedOn    = recipe.CreatedOn,
                CategoryName = this.categoriesService.ReturnCategoryName(recipe.CategoryId),
                Products     = new HtmlSanitizer().Sanitize(recipe.Products),
                Description  = new HtmlSanitizer().Sanitize(recipe.Description),
                ImageUrls    = this.recipesService.ReturnImageUrls(recipe.Id),
                VotesCount   = this.votesService.GetVotes(recipe.Id),
                Comments     = this.commentsService.ReturnCommentsToRecipe(recipe.Id),
            };

            return(this.View(viewModel));
        }
Beispiel #2
0
        private FullRecipeViewModel ParseRecipe(Recipe recipe)
        {
            FullRecipeViewModel fullRecipeViewModel = new FullRecipeViewModel();

            fullRecipeViewModel.RecipeDetails       = _recipeProvider.GetRecipeDetailsByRecipeId(recipe.RecipeId);
            fullRecipeViewModel.Ingridients         = _recipeProvider.GetRecipeIngridientsByRecipeId(recipe.RecipeId);
            fullRecipeViewModel.Recipe              = new RecipeView();
            fullRecipeViewModel.Recipe.RecipeId     = recipe.RecipeId;
            fullRecipeViewModel.Recipe.Name         = recipe.Name;
            fullRecipeViewModel.Recipe.ImageUrl     = recipe.ImageUrl;
            fullRecipeViewModel.Recipe.CategoryId   = recipe.CategoryId;
            fullRecipeViewModel.Recipe.CategoryName = _categoryProvider.GetCategoryById(recipe.CategoryId).Name;
            return(fullRecipeViewModel);
        }
Beispiel #3
0
        public ActionResult ShowFullRecipe(int recipeId)
        {
            Recipe recipe             = _recipeProvider.GetRecipeById(recipeId);
            FullRecipeViewModel model = ParseRecipe(recipe);

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_ShowFullRecipe", model));
            }
            else
            {
                return(View(model));
            }
        }
        public ActionResult FullRecepieView(string recepieId)
        {
            ViewBag.User = HttpContext.Application["User"];
            Recipe r = storage.ReturnRecipeById(recepieId);
            FullRecipeViewModel vm = new FullRecipeViewModel();

            vm.Recipe = r;
            if (HttpContext.Application["User"] != null)
            {
                User u = storage.FindUserByUsername(HttpContext.Application["User"].ToString());
                vm.User = u;
            }
            ViewBag.Comments = storage.FindCommentByRecipeId(ObjectId.Parse(recepieId));
            return(View(vm));
        }
Beispiel #5
0
        public async Task <FullRecipeViewModel> GetRecipeAsync(int recipeId)
        {
            FullRecipeViewModel result = null;

            try
            {
                result = await this.Repository
                         .GetAll()
                         .Include(x => x.Images)
                         .Include(x => x.Tags)
                         .ThenInclude(x => x.RecipeTag)
                         .Include(x => x.Steps)
                         .Include(x => x.Ingrediants)
                         .ThenInclude(x => x.Ingrediant)
                         .Include(x => x.Source)
                         .ThenInclude(x => x.Source)
                         .ProjectTo <FullRecipeViewModel>(this.Mapper.ConfigurationProvider)
                         .SingleOrDefaultAsync(x => x.Id.Equals(recipeId));

                if (result == null)
                {
                    throw new DataObjectNotFoundException("No Recipe with the given id found");
                }

                result.Steps  = result.Steps.OrderBy(x => x.Order);
                result.Images = result.Images.OrderBy(x => x.Id);
                result.Tags   = result.Tags.OrderBy(x => x.Name);


                this.Logger.LogDebug(new EventId(), $"Returned recipe '{result.Name} ({result.Id})'");
            }
            catch (Exception e)
            {
                this.Logger.LogError(new EventId(), e, $"Error on receiving recipe '{recipeId}'");
                throw new Exception($"Error on receiving recipe '{recipeId}'");
            }
            return(result);
        }