public bool CreateHappiness(HappinessCreate model) { var entity = new Happiness() { OwnerId = _userId, HappinessLevel = model.HappinessLevel, EmotionNotes = model.EmotionNotes, Date = model.Date, PersonId = model.PersonId }; using (var ctx = new ApplicationDbContext()) { ctx.Happinesses.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(HappinessCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateHappinessService(); if (service.CreateHappiness(model)) { TempData["SaveResult"] = "Your entry was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Entry could not be created."); ViewBag.PersonId = new SelectList(_db.Persons, "PersonId", "Name", model.PersonId); return(View(model)); }