Пример #1
0
        public async Task HandleAsync(int id, IGetVotesOutputPort output)
        {
            try
            {
                Poll poll = await this.pollGateway.GetAsync(id);

                if (poll is null)
                {
                    output.NotFound("Poll not found!");
                    this.loggerService.LogInformation("Cannot retrieve a poll with {@id}", id);
                    return;
                }

                var options = poll.Options
                              .Select(option => new OptionOutput
                {
                    Option = option.Text,
                    ParticipantEmailAddresss = option?.Votes?.Select(vote => vote?.ParticipantEmailAddress).ToList()
                })
                              .ToList();

                var getVotesOutput = new GetVotesOutput
                {
                    Title   = poll.Title,
                    Options = options
                };

                output.Success(getVotesOutput);
            }
            catch (DomainException ex)
            {
                this.loggerService.LogInformation("{@excepton} occured when trying to retrieve votes for a poll with {@id}", ex, id);
                output.Error(ex.Message);
            }
        }
        public void Success(GetVotesOutput output)
        {
            var optionsResponse = output.Options
                                  .Select(optionOutput => new OptionResponse
            {
                Option = optionOutput.Option,
                ParticipantEmailAddresss = optionOutput.ParticipantEmailAddresss
            })
                                  .OrderBy(o => o.Votes)
                                  .ToList();

            var response = new GetVotesResponse
            {
                Title   = output.Title,
                Options = optionsResponse
            };

            this.ViewModel = new OkObjectResult(response);
        }