//For GET Edit Action private AdminRecipeViewModel ParseRecipeModelToRecipeVM(Recipe recipeForEdit) { AdminRecipeViewModel editRecipeVM = new AdminRecipeViewModel(); RTFToHTMLConverter converter = new RTFToHTMLConverter(); editRecipeVM.RecipeID = recipeForEdit.RecipeID; editRecipeVM.Title = recipeForEdit.Title; editRecipeVM.ImageURL = recipeForEdit.ImageURL; editRecipeVM.ParentCategories = db.Categories.AllParentCategories(); editRecipeVM.SelectedParentCategory = recipeForEdit.Categories.Where(cat => cat.ParentCategoryID == null).Select(cat => cat.CategoryID).FirstOrDefault(); editRecipeVM.ChildrenCategories = db.Categories.AllChildrenCategories(); editRecipeVM.SelectedChildrenCategory = recipeForEdit.Categories.Where(cat => cat.ParentCategoryID != null).Select(cat => cat.CategoryID).FirstOrDefault(); editRecipeVM.PrepTimeHours = this.hours.ToList(); editRecipeVM.SelectedPrepTimeHours = (int)recipeForEdit.PreparationTime / 60; editRecipeVM.PrepTimeMinutes = this.minutes; editRecipeVM.SelectedPrepTimeMinutes = (int)recipeForEdit.PreparationTime % 60; editRecipeVM.CookTimeHours = this.hours; editRecipeVM.SelectedCookTimeHours = (int)recipeForEdit.CookingTime / 60; editRecipeVM.CookTimeMinutes = this.minutes; editRecipeVM.SelectedCookTimeMinutes = (int)recipeForEdit.CookingTime % 60; editRecipeVM.Serves = this.servesArray; editRecipeVM.SelectedServes = (int)recipeForEdit.Serves; editRecipeVM.Rating = this.rating; editRecipeVM.SelectedRating = (int)recipeForEdit.Rating; editRecipeVM.Sources = this.db.Sources.All(); editRecipeVM.SelectedSource = recipeForEdit.Source.SourceID; editRecipeVM.Recommendation = this.recommendationArray; //editRecipeVM.SelectedRecommendation = recipeForEdit.Recommended; if (recipeForEdit.Recommended == true) { editRecipeVM.SelectedRecommendation = "Да"; } else { editRecipeVM.SelectedRecommendation = "Не"; } editRecipeVM.PublishedDate = (DateTime)recipeForEdit.Date; editRecipeVM.Description = RtfHelper.PlainText(recipeForEdit.Description); //editRecipeVM.RecipeItems = recipeForEdit.RecipeItems.ToList(); foreach (var recipeItem in recipeForEdit.RecipeItems) { RecipeItem newRecipeItem = new RecipeItem(); newRecipeItem.RecipeItemName = recipeItem.RecipeItemName; foreach (var recipeItem_ingredient in recipeItem.RecipeItems_Ingredients) { RecipeItems_Ingredients newRecipeItem_ingredient = new RecipeItems_Ingredients(); Unit newUnit = this.db.Units.GetById(recipeItem_ingredient.Unit.UnitID); Ingredient newIngredient = this.db.Ingredients.GetById(recipeItem_ingredient.Ingredient.IngredientID); newRecipeItem_ingredient.Quantity = recipeItem_ingredient.Quantity; newRecipeItem_ingredient.Unit = newUnit; newRecipeItem_ingredient.Ingredient = newIngredient; newRecipeItem.RecipeItems_Ingredients.Add(newRecipeItem_ingredient); } foreach (var step in recipeItem.Steps) { newRecipeItem.Steps.Add(step); } editRecipeVM.RecipeItems.Add(newRecipeItem); } return(editRecipeVM); }