public ActionResult Create(Dinners dinner)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    dinner.DinnerID = dinnerRepository.GetDinnerNewId() + 1;
                    dinner.HostedBy = User.Identity.Name;

                    RSVP rsvp = new RSVP();
                    rsvp.RsvpID       = dinnerRepository.GetRsvpNewId() + 1;
                    rsvp.AttendeeName = User.Identity.Name;
                    dinner.RSVP.Add(rsvp);

                    dinnerRepository.Add(dinner);
                    dinnerRepository.Save();
                    return(RedirectToAction("Details", new { id = dinner.DinnerID }));
                }
                catch (Exception e)
                {
                    //ModelState.AddRuleViolations(dinner.GetRuleViolations());
                }
            }
            return(View(new DinnerFormViewModel(dinner)));
        }
Beispiel #2
0
        public ActionResult Create(Dinner dinner)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    dinner.HostedBy = User.Identity.Name;

                    RSVP 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
                {
                    foreach (var issue in dinner.GetRuleViolations())
                    {
                        ModelState.AddModelError(issue.PropertyName, issue.ErrorMessage);
                    }

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

            return(View(new DinnerFormViewModel(dinner)));
        }
Beispiel #3
0
 public ActionResult Create(Dinner dinner)
 {
     if (ModelState.IsValid)
     {
         repo.Add(dinner);
         repo.Save();
         return(RedirectToAction("Index"));
     }
     return(View(dinner));
 }
Beispiel #4
0
        public ActionResult Create(Dinner dinner)
        {
            if (ModelState.IsValid)
            {
                dinner.HostedBy = "SomeUser";

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

                return(RedirectToAction("Details", new { id = dinner.DinnerID }));
            }
            return(View(new DinnerFormViewModel(dinner)));
        }
Beispiel #5
0
    public ActionResult Create(Dinner dinner)
    {
        if (ModelState.IsValid)
        {
            try {
                dinner.HostedBy = "SomeUser";

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

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

        return(View(dinner));
    }
Beispiel #6
0
        public ActionResult Create(Dinner dinner)
        {
            if (ModelState.IsValid)
            {
                dinner.HostedBy = User.Identity.Name;
                dinner.DinnerID = dinnerRepository.GetUnusedDinnerID();
                dinnerRepository.Add(dinner);
                dinnerRepository.Save();

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

            Dinner newDinner = new Dinner()
            {
                EventDate = DateTime.Now.AddDays(7)
            };

            return(View(new DinnerFormViewModel(newDinner)));
        }
Beispiel #7
0
        public ActionResult Create(Dinner dinner)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    dinner.HostedBy = "SomeUser";

                    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)));
        }