GetRuleViolations() public method

public GetRuleViolations ( ) : IEnumerable
return IEnumerable
示例#1
0
        public ActionResult Create(NerdDinner.Entities.Dinners dinner)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    dinner.HostedBy = User.Identity.Name;
                    IList <NerdDinner.Entities.RSVP> rsvps = new List <NerdDinner.Entities.RSVP>();
                    rsvps.Add(new NerdDinner.Entities.RSVP()
                    {
                        AttendeeName = User.Identity.Name
                    });
                    rsvps[0].dinner = dinner;
                    dinner.RSVPs    = rsvps;
                    dinnerRepository.Add(dinner);
                    dinnerRepository.Save(dinner);

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

            return(View(new DinnerFormViewModel(dinner)));
        }
示例#2
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            NerdDinner.Entities.Dinners dinner = dinnerRepository.GetDinner(id);

            if (!dinner.IsHostedBy(User.Identity.Name))
            {
                return(View("InvalidOwner"));
            }

            try
            {
                UpdateModel(dinner);

                dinnerRepository.Save(dinner);

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

                return(View(new DinnerFormViewModel(dinner)));
            }
        }