public ActionResult Create(ConventionCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateConventionService(); if (service.CreateConvention(model)) { TempData["SaveResult"] = "The convention was created."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "The convention could not be created."); return(View(model)); }
public bool CreateConvention(ConventionCreate model) { var entity = new Convention() { Name = model.Name, City = model.City, State = model.State, StartDate = model.StartDate, EndDate = model.EndDate, Hotel = model.Hotel, Website = model.Website }; using (var ctx = new ApplicationDbContext()) { ctx.Conventions.Add(entity); return(ctx.SaveChanges() == 1); } }