public ActionResult Create(MotherCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateMotherService(); if (service.CreateMother(model)) { TempData["SaveResult"] = "You added a new mother."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "New mother could not be added."); return(View(model)); }
public bool CreateMother(MotherCreate model) { var entity = new Mother() { OwnerId = _userId, FirstName = model.FirstName, LastName = model.LastName, MotherLocation = model.MotherLocation, DateOfBirth = model.DateOfBirth, DueDate = model.DueDate, FirstPregnancy = model.FirstPregnancy, VagBirAftCes = model.VagBirAftCes, BreastFeeding = model.BreastFeeding }; using (var ctx = new ApplicationDbContext()) { ctx.Mothers.Add(entity); return(ctx.SaveChanges() == 1); } }