public ActionResult Edit(BrewBindingModel model, string id) { if (!ModelState.IsValid) { return(RedirectToAction("Edit", "Brew", id)); } try { BrewDomModel toEdit = new BrewDomModel { Id = Guid.Parse(id), Name = model.Name, Description = model.Description, RecipeId = Guid.Parse(model.RecipeId) }; this.manager.Edit(toEdit); return(RedirectToAction(nameof(Index))); } catch { return(RedirectToAction("Edit", "Edit", id)); } }
// GET: Brews/Create public ActionResult Create() { var model = new BrewBindingModel(); var recipes = this.recipeManager.GetAll(); SelectList listItems = new SelectList(recipes, "Id", "Name", model.RecipeId); model = new BrewBindingModel(new BrewDomModel(), listItems); return(View(model)); }
// GET: Brews/Edit/5 public ActionResult Edit(string id) { var brew = this.manager.Find(Guid.Parse(id)); var model = new BrewBindingModel(); var recipes = this.recipeManager.GetAll(); SelectList listItems = new SelectList(recipes, "Id", "Name", model.RecipeId); model = new BrewBindingModel(brew, listItems); return(View(model)); }
public ActionResult Create(BrewBindingModel model) { if (!ModelState.IsValid) { return(RedirectToAction(nameof(Create))); } try { var brew = new BrewDomModel { Name = model.Name, Description = model.Description, RecipeId = Guid.Parse(model.RecipeId), }; this.manager.Add(brew); return(RedirectToAction(nameof(Index))); } catch { return(RedirectToAction(nameof(Create))); } }