public bool CreateSection(SectionCreate model) { var entity = new Section() { CreatorID = _userId, Title = model.Title, }; using (var ctx = new ApplicationDbContext()) { ctx.Sections.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(SectionCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateSectionService(); if (service.CreateSection(model)) { TempData["ResultSaved"] = "Your section was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Section could not be created."); return(View(model)); }