public async Task<string> SavePollAsync(PollDefinition poll)
        {
            if (string.IsNullOrEmpty(poll.Id))
            {
                poll.Id = Guid.NewGuid().ToString();

                var topic = (await this._snsClient.CreateTopicAsync("pollster-poll-" + poll.Id)).TopicArn;
                poll.TopicArn = topic;
                await this._dbContext.SaveAsync<PollDefinition>(poll);

                await this._snsClient.SubscribeAsync(topic, "email", poll.AuthorEmail);

            }
            await this._dbContext.SaveAsync(poll);

            await this._swfClient.StartWorkflowExecutionAsync(new StartWorkflowExecutionRequest
            {
                Domain = Constants.SWF_DOMAIN,
                WorkflowId = poll.Id,
                WorkflowType = new WorkflowType()
                {
                    Name = Constants.SWF_WORKFLOW_TYPE_NAME,
                    Version = _swfWorkflowTypeVersion,
                },
                TaskList = new TaskList
                {
                    Name = Constants.SWF_DECIDER_TASKLIST
                },
                Input = poll.Id
            });

            return poll.Id;
        }
 public async Task Save(PollDefinition poll)
 {
     if(string.IsNullOrEmpty(poll.Id))
     {
         var response = await base.Post<string>("api/Polls", poll);
         Logger.LogMessage("Response from saving poll: {0}", response);
     }
     else
     {
         var response = await base.Put<string>("api/Polls/" + poll.Id, poll);
         Logger.LogMessage("Response from saving poll: {0}", response);
     }
 }
        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);
        }