public ActionResult Create(RecipeBindingModel model, string id) { if (!ModelState.IsValid) { return(View(nameof(Create), id)); } try { var ingredients = model.Ingredients.Where(i => i.Quantity > 0) .Select(i => new IngredientDomModel { Id = Guid.Parse(i.Id), Quantity = i.Quantity }); var recipeDom = new RecipeDomModel { Name = model.Name, Description = model.Description, Ingredients = ingredients.ToList() }; var recipe = this.manager.Add(recipeDom); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Edit(RecipeBindingModel model, string id) { if (!ModelState.IsValid) { ModelState.AddModelError("Error", "Error!"); return(RedirectToAction("Edit", "Recipe", id)); } try { var ingredients = model.Ingredients.Where(i => i.Quantity > 0) .Select(i => new IngredientDomModel { Id = Guid.Parse(i.Id), Quantity = i.Quantity, }); var recipeDom = new RecipeDomModel { Id = Guid.Parse(id), Name = model.Name, Description = model.Description, Ingredients = ingredients.ToList() }; this.manager.Edit(recipeDom); return(RedirectToAction(nameof(Index))); } catch (Exception e) { ModelState.AddModelError("Error", e.Message); return(RedirectToAction("Edit", "Recipe", id)); } }
public RecipeBindingModel(RecipeDomModel model, List <IngredientDomModel> availableIngredients) : this() { this.Name = model.Name; this.Description = model.Description; //model.Ingredients.Concat(availableIngredients); this.Ingredients = model.Ingredients.Concat(availableIngredients).Select(i => new RecipeIngredientBindingModel(i)).ToList();; }
private RecipeDomModel ConvertToDomModel(Guid id, RecipeBindingModel model) { var result = new RecipeDomModel { Id = id, }; return(result); }
public RecipeViewModel(RecipeDomModel model) { this.Id = model.Id.ToString(); this.Name = model.Name; this.Description = model.Description; if (model.Ingredients != null) { this.Ingredients = model.Ingredients.Select(i => new RecipeIngredientViewModel(i)).ToList(); } }