public ActionResult Create(RootCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = new RootService(); service.CreateRoot(model); return(RedirectToAction("Index")); }
public bool CreateRoot(RootCreate model) { var entity = new Root() { RootName = model.RootName, NotesOnRoot = model.NotesOnRoot, }; using (var ctx = new ApplicationDbContext()) { if (_db.Roots.Where(e => e.RootName == model.RootName).Any()) { return(false); } else { ctx.Roots.Add(entity); return(ctx.SaveChanges() == 1); } } }