private static RecipeServiceModel Map(Recipe recipe) { if (recipe == null) return null; return new RecipeServiceModel {RecipeId = recipe.RecipeId, Name = recipe.Name}; }
public RecipeServiceModel AddRecipe(string name) { if(string.IsNullOrWhiteSpace(name)) throw new ArgumentOutOfRangeException("name",name,"Name value is required to create a new recipe"); var newRecipe = new Recipe {Name = name}; _dataContext.Recipes.Add(newRecipe); _dataContext.SaveChanges(); var recipeModel = Map(newRecipe); return recipeModel; }