public bool CreateSalesRep(SalesRepCreate model) { var entity = new SalesRep() { RepName = model.RepName, Territory = model.Territory, }; using (var ctx = new ApplicationDbContext()) { ctx.SalesReps.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(SalesRepCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateSalesRepService(); if (service.CreateSalesRep(model)) { TempData["SaveResult"] = "SalesRep was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "SalesRep could not be created."); return(View(model)); }