示例#1
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)));
        }