public ActionResult Update(InstructionsListViewModel instructions) { var instructionsBL = instructionsService.GetAllInstructionsForRecipe(instructions.RecipeID); foreach (var i in instructionsBL) { instructions.ListOfInstructions.Add(new InstructionViewModel() { InstructionID = i.InstructionID, InstructionText = i.InstructionText }); } instructions.NrOfInstructions = instructionsBL.Count(); instructions.RecipeID = instructions.RecipeID; return(View(instructions)); }
public ActionResult View(int id) { var recipeBL = recipeService.GetRecipeByID(id); var recipe = new RecipeViewModel() { RecipeID = recipeBL.RecipeID, CookTime = recipeBL.CookTime, Description = recipeBL.Description, LongDescription = recipeBL.LongDescription, Name = recipeBL.Name, RatingID = recipeBL.RatingID, PictureLocation = recipeBL.PictureLocation, PrepTime = recipeBL.PrepTime }; var ingredientsBL = ingredientService.GetAllIngredientsForRecipe(recipe.RecipeID); var instructionsBL = instructionsService.GetAllInstructionsForRecipe(recipe.RecipeID); var commentsBL = commentService.GetAllCommentsForRecipe(recipe.RecipeID); var ratingBL = ratingService.GetRatingByID(recipe.RatingID); var ingredients = new List <IngredientViewModel>(); var instructions = new List <InstructionViewModel>(); var comments = new List <CommentsViewModel>(); var rating = new RatingViewModel() { RatingID = ratingBL.RatingID, NumberOfRatings = ratingBL.NumberOfRatings, Score = ratingBL.Score, SumRatings = ratingBL.SumRatings }; foreach (var i in ingredientsBL) { ingredients.Add(new IngredientViewModel() { IngredientID = i.IngredientID, Name = i.Name, Quantity = i.Quantity }); } foreach (var i in instructionsBL) { instructions.Add(new InstructionViewModel() { InstructionID = i.InstructionID, InstructionText = i.InstructionText }); } foreach (var i in commentsBL) { comments.Add(new CommentsViewModel() { CommentID = i.CommentID, Comment = i.CommentText, RecipeID = id }); } recipe.Score = rating.Score; recipe.NrOfRatings = rating.NumberOfRatings; recipe.ListIngredients = ingredients; recipe.ListInstructions = instructions; recipe.ListComments = comments; return(View(recipe)); }