public IActionResult Index() { var model = new PollCreatorViewModel { StartDate = DateTime.Today, EndDate = DateTime.Today.AddDays(1) }; model.StartTime = DateTime.Now.AddMinutes(10); model.EndTime = DateTime.Now.AddMinutes(10); return View(model); }
public async Task<IActionResult> Index(PollCreatorViewModel model) { PollConfirmationViewModel confirmModel = new PollConfirmationViewModel(); try { var pollDefinition = new PollDefinition { Title = model.Title, Question = model.Question, AuthorEmail = model.AuthorEmail, Options = new Dictionary<string, PollDefinition.Option>() }; pollDefinition.StartTime = model.StartDate.Date.Add(model.StartTime.TimeOfDay); pollDefinition.EndTime = model.EndDate.Date.Add(model.EndTime.TimeOfDay); string line; using (var reader = new StringReader(model.Options)) { int index = 0; while ((line = reader.ReadLine()) != null) { pollDefinition.Options.Add(index.ToString(), new PollDefinition.Option { Text = line }); index++; } } await this._pollWriter.Save(pollDefinition); confirmModel.Title = pollDefinition.Title; confirmModel.StartTime = pollDefinition.StartTime; confirmModel.EndTime = pollDefinition.EndTime; confirmModel.Success = true; } catch(Exception e) { confirmModel.Success = false; confirmModel.ErrorMessage = string.Format("Unknown error saving poll: {0}", e.Message); } return View("Confirmation", confirmModel); }