public ActionResult Recipe(int id = 1) { string userId = User.Identity.GetUserId(); context = new BlondsCookingContext(); Recipe recipeModel = context.Recipes.FirstOrDefault(recipe => recipe.Id == id); UserRating rate = context.UserRatings.Where( rating => rating.RecipeId == id && rating.UserId.CompareTo(userId) == 0) .FirstOrDefault(); if (recipeModel == null) { return View("Error"); } RecipeRateViewModel recipeRateViewModel = new RecipeRateViewModel() { Id = recipeModel.Id, Name = recipeModel.Name, Description = recipeModel.Description, Image = recipeModel.Image, Ingredients = recipeModel.Ingredients, Temperature = recipeModel.Temperature, Time = recipeModel.Time, Rate = (rate == null) ? null : (int?)rate.Rate }; DishesCompairingHelper helper = new DishesCompairingHelper(); List<Recipe> similarRecipes = new List<Recipe>(helper.GetTopThreeMostSimilarDishes(recipeModel)); model = new RecipeViewModel(recipeRateViewModel, similarRecipes); return View(model); }
public RecipeViewModel(RecipeRateViewModel recipeRateViewModel, List<Recipe> similarRecipes) { RecipeRateViewModel = recipeRateViewModel; SimilarRecipes = new List<Recipe>(similarRecipes); }