public bool CreateBaby(BabyCreate model) { var entity = new Baby() { ParentID = _userID, Name = model.Name, Gender = model.Gender, BirthDate = model.BirthDate, Notes = model.Notes }; using (var ctx = new ApplicationDbContext()) { ctx.Babies.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(BabyCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateBabyService(); if (service.CreateBaby(model)) { TempData["SaveResult"] = "Your baby has been added!"; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Your baby could not be added. Please, try again."); return(View(model)); }