public ActionResult Create(Dinner dinner)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    dinner.HostedBy = User.Identity.Name;

                    var rsvp = new RSVP();
                    rsvp.AttendeeName = User.Identity.Name;
                    dinner.RSVPs.Add(rsvp);

                    dinnerRepository.Add(dinner);
                    dinnerRepository.Save();

                    return RedirectToAction("Details", new {id = dinner.DinnerID});
                }
                catch
                {
                    ModelState.AddModelErrors(dinner.GetRuleViolations());
                }
            }

            return View(new DinnerFormViewModel(dinner));
        }
Пример #2
0
        public ActionResult Create(Dinner dinner)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    dinner.Rsvps = new List<RSVP>();
                    var rsvp = new RSVP {AttendeeName = User.Identity.Name};
                    dinner.Rsvps.Add(rsvp);

                    dinnerRepository.AddDinner(dinner);
                    dinnerRepository.Save();

                    return RedirectToAction("Details", new {id = dinner.DinnerId});
                }
                catch
                {
                    ModelState.AddRuleViolations(dinner.GetRuleViolations());
                }
            }

            return View(new DinnerFormViewModel(dinner));
        }
Пример #3
0
        public ActionResult Create(Dinner dinner)
        {
            if (ModelState.IsValid) {
                try {
                    using (var tx = _session.BeginTransaction())
                    {
                        dinner.HostedBy = User.Identity.Name;

                        RSVP rsvp = new RSVP();
                        rsvp.AttendeeName = User.Identity.Name;
                        dinner.AddRsvp(rsvp);
                        _dinnerRepository.Save(dinner);
                        tx.Commit();
                        return RedirectToAction("Details", new { id = dinner.DinnerID });
                    }
                }
                catch {
                    ModelState.AddModelErrors(dinner.GetRuleViolations());
                }
            }

            return View(new DinnerFormViewModel(dinner));
        }
Пример #4
0
        public ActionResult Create(Dinner dinner)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    dinner.HostedBy = User.Identity.Name;

                    dinnerRepository.Add(dinner);
                    dinnerRepository.Save();

                    return RedirectToAction("Details", new {id = dinner.DinnerID});
                }
                catch
                {
                    foreach (var issue in dinner.GetRuleViolations())
                    {
                        ModelState.AddModelError(issue.PropertyName, issue.ErrorMessage);
                    }
                }
            }
            return View(new DinnerFormViewModel(dinner));
        }