Esempio n. 1
0
        public ActionResult CreatePoll([ModelBinder(typeof(CreatePollBinder))] PollViewModel model)
        {
            Poll poll = model.Poll;

            // add some values not populated from the form
            poll.PubDate = DateTime.Now;

            int id = repository.AddPoll(poll);

            List <Option> options = new List <Option>(model.Options.ToList().Count);

            // relate the options to the poll
            foreach (Option opt in model.Options)
            {
                Option o = opt;
                o.PollID = id;
                options.Add(o);
            }
            repository.AddOptions(options);

            return(RedirectToAction("Index"));
        }