public ActionResult Create(ChildCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateChildService(); if (service.CreateChild(model)) { TempData["SaveResult"] = "Child's info was saved."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Child's info could not be saved."); return(View(model)); }
public bool CreateChild(ChildCreate model) { var entity = new Child() { UserId = _userId, ChildName = model.ChildName, BedsNeed = model.BedsNeed, ChildGender = model.ChildGender, ChildAge = model.ChildAge, SchoolDistNeed = model.SchoolDistNeed, CaseworkerName = model.CaseworkerName, CaseworkerContact = model.CaseworkerContact, Comments = model.Comments, PhotoUrl = model.PhotoUrl, ModifiedUtc = model.ModifiedUtc, }; using (var ctx = new ApplicationDbContext()) { ctx.Children.Add(entity); return(ctx.SaveChanges() == 1); } }