// POST api/recipies public void Post(RecipeModel recipe, string sessionKey) { var user = persister.GetUser(sessionKey); if (user.SessionKey != null) { Recipe newRecipe = RecipeModel.FromRecipeModeltoRecipe(recipe, user.UserId); this.recipeRepository.Add(newRecipe); } }
// PUT api/recipies/5 public void Put(int id, string sessionKey, RecipeModel recipe) { var user = persister.GetUser(sessionKey); recipe.RecipeId = id; if (user.SessionKey != null) { Recipe currentRecipe = RecipeModel.FromRecipeModeltoRecipe(recipe, user.UserId); this.recipeRepository.Update(id, currentRecipe); } }
public static Recipe FromRecipeModeltoRecipe(RecipeModel x, int UserId) { foreach (var comment in x.Comments) { comment.UserId = UserId; } foreach (var like in x.Likes) { like.User_Id = UserId; like.Recipe_Id = x.RecipeId; } return new Recipe { UserId = UserId, Title = x.Title, ImageUrl = x.ImageUrl, Ingredients = x.Ingredients, PrepContent = x.PrepContent, Likes = x.Likes, Comments = x.Comments, Steps = x.Steps.OrderBy(s => s.Number).ToList() }; }