public ActionResult Create(DefendantCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateDefendantService(); if (service.CreateDefendant(model)) { TempData["SaveResult"] = "Defendant was added"; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Defendant was not added"); return(View(model)); }
public bool CreateDefendant(DefendantCreate model) { var entity = new Defendant() { DefendantID = model.DefendantID, FirstName = model.FirstName, LastName = model.LastName, StreetAddress = model.StreetAddress, City = model.City, County = model.County, State = model.State, Zipcode = model.Zipcode, Prosecuted = model.Prosecuted, Arrested = model.Arrested, //CourtHearingID = model.CourtHearingID, //ConvictionID = model.ConvictionID }; using (var dft = new ApplicationDbContext()) { dft.Defendants.Add(entity); return(dft.SaveChanges() == 1); } }