Example #1
0
        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);
            }
        }
Example #2
0
        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));
        }