Exemplo n.º 1
0
        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)));
        }
Exemplo n.º 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)));
        }
Exemplo n.º 3
0
 public ActionResult Create(Dinner dinner)
 {
     if (ModelState.IsValid)
     {
         repo.Add(dinner);
         repo.Save();
         return(RedirectToAction("Index"));
     }
     return(View(dinner));
 }
Exemplo n.º 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)));
        }
Exemplo n.º 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));
    }
Exemplo n.º 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)));
        }
Exemplo n.º 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)));
        }