public ActionResult Create(CigarCreate model) { var service = CreateCigarService(); if (service.CreateCigar(model)) { TempData["SaveResult"] = "Your Cigar was created."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Cigar could not be created"); return(View(model)); }
public bool CreateCigar(CigarCreate model) { var entity = new Cigar { CigarName = model.CigarName, MakerId = model.MakerId, CigarTypeId = model.CigarTypeId }; using (var ctx = new ApplicationDbContext()) { ctx.Cigars.Add(entity); return(ctx.SaveChanges() == 1); } }