public static void AddTopicPoll(int postid, string question, SortedList <int, string> choices) { IPoll dal = Factory <IPoll> .Create("Poll"); PollInfo poll = new PollInfo { TopicId = postid, DisplayText = question }; foreach (var choice in choices) { PollChoiceInfo pollchoice = new PollChoiceInfo { DisplayText = choice.Value, Order = choice.Key }; poll.AddChoice(pollchoice); } dal.Add(poll); }
public async Task <IActionResult> AddPoll([Bind("Question,Answers,Status")] PollAddViewModel model) { if (ModelState.IsValid) { Poll newPoll = new Poll { Question = model.Question, Answers = model.Answers.Select(s => new Answer { Description = s, }).ToList(), Status = model.Status, User = await _userManager.GetUserAsync(User) }; _polls.Add(newPoll); return(RedirectToAction(nameof(MyPollsItem), new { pollId = newPoll.PollId })); } return(View(model)); }