public async Task <ServiceResponse <Poll> > CreateAsync(CreatePollRequest request)
        {
            var pollToCreate = _mapper.Map <Poll>(request);

            var newId = await _pollRepository.CreateAsync(pollToCreate);

            var newPoll = await GetByIdAsync(newId);

            return(ServiceResponse <Poll> .Success(newPoll));
        }
        public async Task <ServiceResponse <PollDto> > Handle(CreatePollCommand request, CancellationToken cancellationToken)
        {
            var createdId = await _pollRepository.CreateAsync(new PollDto
            {
                Title   = request.Title,
                Status  = request.Status,
                Type    = request.Type,
                Options = request.Options
            });

            var poll = await _pollRepository.GetByIdAsync(createdId);

            return(ServiceResponse <PollDto> .Success(_mapper.Map <PollDto>(poll)));
        }
Exemple #3
0
        public async Task StartAsync(UpdateMessage message)
        {
            var callbackQueryData = message.CallbackQuery.Data.Split(';');
            var occasionId        = callbackQueryData[1];

            var occasion = _occasionRepository.FindById(occasionId);

            if (occasion == null)
            {
                return;
            }

            var activePolls = _pollRepository.Find(x => x.ChatId == occasion.ChatId && !x.IsClosed).ToList();

            if (activePolls.Any())
            {
                await _telegramClient.SendMessageAsync(new SendMessage
                {
                    ChatId = occasion.ChatId,
                    Text   = Messages.ActivePollRunning
                });

                return;
            }

            var sendPollMessage = TelegramMessageFactory.CreateSendPollMessage(occasion.ChatId, occasion.Name);
            var pollMessage     = await _telegramClient.SendPollAsync(sendPollMessage);

            var entity = new PollEntity
            {
                PartitionKey = occasion.ChatId,
                RowKey       = pollMessage.Poll.Id,
                Timestamp    = _dateTimeService.TableEntityTimeStamp,
                ChatId       = occasion.ChatId,
                OccasionId   = occasionId,
                MessageId    = pollMessage.MessageId.ToString(),
                IsClosed     = false
            };

            await _pollRepository.CreateAsync(entity);

            await _telegramClient.AnswerCallbackQuery(new AnswerCallbackQuery
            {
                CallBackQueryId = message.CallbackQuery.Id,
                Text            = Messages.PollStarted
            });
        }
        public async Task <IActionResult> CreateAsync([FromForm] PollDto pollDto)
        {
            if (pollDto == null)
            {
                return(NotFound());
            }

            Poll poll = new Poll();

            poll.PollDescription = pollDto.PollDescription;
            poll.Options         = await _pollOptionsRepository.CreateOptionsWithIdAsync(pollDto.Options);

            var pollCreate = await _pollRepository.CreateAsync(poll);

            dynamic pollResponse = new ExpandoObject();

            pollResponse.poll_id = pollCreate.PollId;

            return(Ok(JsonConvert.SerializeObject(pollResponse)));
        }