public void UpdateRecipe(WhatYouGotLibrary.Models.Recipe recipe) { Entities.Recipe currentRecipe = _context.Recipe.Find(recipe.Id); Entities.Recipe newRecipe = Mapper.Map(recipe); _context.Entry(currentRecipe).CurrentValues.SetValues(newRecipe); }
public static Recipe ConvertToDTO(this Entities.Recipe recipe) { List <Ingredient> ingredients = recipe.Ingredients.ConvertToDTOs(); var steps = recipe.Steps.ConvertToDTOs(); return(new Recipe { ID = recipe.ID, Name = recipe.Name, Ingredients = ingredients, Steps = steps }); }
/// <summary> /// Method to convert a recipe to an entity class so it can be added to the database /// </summary> /// <param name="recipe">The recipe to be converted</param> /// <returns>An instance of the recipe entity</returns> private Entities.Recipe CreateRecipeEntity(RecipeDTO recipe) { var recipeEntity = new Entities.Recipe { Name = recipe.Name }; return(recipeEntity); }
public static Entities.Step ConvertToEntity(this Step step, Entities.Recipe Recipe) { return(new Entities.Step { ID = step.ID, Recipe = Recipe, RecipeId = Recipe.ID, Order = step.Order, Text = step.Text, CookTime = step.CookTime.FromRecipeFormat(), PrepTime = step.PrepTime.FromRecipeFormat() }); }
public ActionResult CreateRecipe(AddRecipeViewModel model) { var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { var recipe = new Entities.Recipe { Name = model.Name, Description = model.Description, Vegetarian = model.Vegetarian, PreparationTime = model.PreparationTime, Added = DateTime.Now, Author = null }; List <Ingredient> ingredients = new List <Ingredient>(); ICollection <IngredientCreateViewModel> ingredientsInfo; if (CookieHelper.TryReadCookie <ICollection <IngredientCreateViewModel> >( currentRecipeCookie, createdRecipeIngredients, out ingredientsInfo)) { foreach (var ingr in ingredientsInfo) { ingredients.Add(new Ingredient { Name = ingr.Alias, ProductId = ingr.ProductId, Product = ProductManager.FindById(ingr.ProductId), Quantity = ingr.Quantity, Recipe = recipe }); } } recipe.Ingredients = ingredients; RecipeManager.AddToCategory(recipe, RecipeManager.FindCategoryById(model.CategoryId)); RecipeManager.Save(); CookieHelper.DeleteCookie(currentRecipeCookie); return(RedirectToAction("CreateResult")); } ViewBag.Categories = RecipeManager.RecipeCategories.ToSelectList <Entities.RecipeCategory, RecipeCategoryInfo>(); ViewBag.OrderedCategories = ProductManager.ProductCategories.ToOrderedSelectList(); return(View("Create")); }
public RecipeVM Get(int id) { var model = new RecipeVM(); Entities.Recipe recipeFromService = _recipesService.GetRecipeById(id); _mapper.Map(recipeFromService, model); // get image from azure if (model.ImageUrl != null) { //var base64 = _recipesService.GetBase64RecipeImage(model.ImageUrl); //model.ImageFile = base64; var url = _recipesService.GetUri(model.ImageUrl); model.ImageFile = url; } model.Ingredients.OrderBy(i => i.PositionNo).ToList(); model.MethodItems.OrderBy(i => i.StepNo).ToList(); return(model); }
public static ICollection <Entities.Step> ConvertToEntities(this Step[] steps, Entities.Recipe recipe) => steps.Select(s => s.ConvertToEntity(recipe)).ToArray();
public WhatYouGotLibrary.Models.Recipe GetRecipeById(int id) { Entities.Recipe recipe = _context.Recipe.Find(id); return(Mapper.Map(recipe)); }
public void DeleteRecipeById(int id) { Entities.Recipe recipe = _context.Recipe.Find(id); _context.Remove(recipe); }
public void AddRecipe(WhatYouGotLibrary.Models.Recipe recipe) { Entities.Recipe newRecipe = Mapper.Map(recipe); _context.Add(newRecipe); }
public ActionResult CreateRecipe(AddRecipeViewModel model) { var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { var recipe = new Entities.Recipe { Name = model.Name, Description = model.Description, Vegetarian = model.Vegetarian, PreparationTime = model.PreparationTime, Added = DateTime.Now, Author = null }; List<Ingredient> ingredients = new List<Ingredient>(); ICollection<IngredientCreateViewModel> ingredientsInfo; if (CookieHelper.TryReadCookie<ICollection<IngredientCreateViewModel>>( currentRecipeCookie, createdRecipeIngredients, out ingredientsInfo)) { foreach (var ingr in ingredientsInfo) { ingredients.Add(new Ingredient{ Name = ingr.Alias, ProductId = ingr.ProductId, Product = ProductManager.FindById(ingr.ProductId), Quantity = ingr.Quantity, Recipe = recipe}); } } recipe.Ingredients = ingredients; RecipeManager.AddToCategory(recipe, RecipeManager.FindCategoryById(model.CategoryId)); RecipeManager.Save(); CookieHelper.DeleteCookie(currentRecipeCookie); return RedirectToAction("CreateResult"); } ViewBag.Categories = RecipeManager.RecipeCategories.ToSelectList<Entities.RecipeCategory, RecipeCategoryInfo>(); ViewBag.OrderedCategories = ProductManager.ProductCategories.ToOrderedSelectList(); return View("Create"); }