// GET: Brews/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Brew brew = context.Brews.Include(b => b.Variables).SingleOrDefault(b => b.ID == id); if (brew == null) { return(HttpNotFound()); } CreateBrewViewModel viewModel = new CreateBrewViewModel { Brew = brew, BeerID = brew.BeerID, OriginalWaterType = brew.Variables.WaterType, OriginalFermentableType = brew.Variables.FermentableType }; return(View(viewModel)); }
public ActionResult Create([Bind(Include = "BeerID,Brew,NewWaterType,NewFermentableType,Variables")] CreateBrewViewModel newBrew) { if (ModelState.IsValid) { newBrew.Brew.Variables.WaterType = newBrew.Brew.Variables.WaterType == "Create New" ? newBrew.NewWaterType : newBrew.Brew.Variables.WaterType; newBrew.Brew.Variables.FermentableType = newBrew.Brew.Variables.FermentableType == "Create New" ? newBrew.NewFermentableType : newBrew.Brew.Variables.FermentableType; newBrew.Brew.CreatedDate = DateTime.Now; User jim = context.Users.Find(1); newBrew.Brew.CreatedBy = jim; Beer beer = context.Beers.Find(newBrew.BeerID); beer.Brews.Add(newBrew.Brew); context.SaveChanges(); return(RedirectToAction("Details", "Beers", new { id = beer.ID })); } return(View(newBrew)); }