// CREATE public bool CreateBrewery(BreweryCreate model) { var entity = new Brewery { Name = model.Name, Address = model.Address, Carryout = model.Carryout }; _context.Breweries.Add(entity); return(_context.SaveChanges() == 1); }
//method to create a brewery public bool CreateBrewery(BreweryCreate model) { var entity = new Brewery() { Name = model.Name, Inception = model.Inception, Location = model.Location, About = model.About, }; using (var ctx = new BreweryDbContext()) { ctx.Breweries.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(BreweryCreate model) { if (!ModelState.IsValid) { return(View(model)); } if (_service.CreateBrewery(model)) { TempData["SaveResult"] = "Brewery was added."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Brewery could not be created."); return(View(model)); }