private IngredientDomModel ConvertToDomModel(Guid id, IngredientBindingModel model) { var result = new IngredientDomModel { Id = id, Name = model.Name, Quantity = model.Quantity }; return(result); }
private ICollection <IngredientDomModel> IngredientToDom(ICollection <IngredientForRecipe> ingredients) { var ingredientModels = new List <IngredientDomModel>(); foreach (var i in ingredients) { var ingredient = new IngredientDomModel { Id = i.IngredientId, Name = i.Ingredient.Name, Quantity = i.RequiredAmmount }; ingredientModels.Add(ingredient); } return(ingredientModels); }
public ActionResult Edit(Guid id, IngredientBindingModel model) { if (!ModelState.IsValid) { return(RedirectToAction("Edit", "Ingredient", id)); } try { IngredientDomModel ingredient = this.ConvertToDomModel(id, model); this.manager.Edit(ingredient); return(RedirectToAction(nameof(Index))); } catch (Exception e) { ModelState.AddModelError("Error", e.Message); return(View()); } }
public ActionResult Create(IngredientBindingModel model) //IFormCollection collection { if (!ModelState.IsValid) { return(View()); } try { var ingredientDomModel = new IngredientDomModel { Name = model.Name, Quantity = model.Quantity }; var result = this.manager.Add(ingredientDomModel); return(RedirectToAction(nameof(Index))); } catch (Exception e) { ModelState.AddModelError("Error", e.Message); return(View()); } }
public IngredientViewModel(IngredientDomModel ingredient) { this.Name = ingredient.Name; this.Id = ingredient.Id.ToString(); this.Quantity = ingredient.Quantity; }
public RecipeIngredientBindingModel(IngredientDomModel ingredient) { this.Name = ingredient.Name; this.Id = ingredient.Id.ToString(); this.Quantity = ingredient.Quantity; }
public RecipeIngredientViewModel(IngredientDomModel model) { this.Id = model.Id.ToString(); this.Name = model.Name; this.Quantity = model.Quantity; }