Beispiel #1
0
        public async Task <PollCreated> CreatePoll(PollCreate pollCreate)
        {
            //TODO Category Repository
            var generatedCode = await _codeService.GenerateCode();

            int catId = 1;

            var poll = new PollEntity
            {
                Title    = pollCreate.Title,
                Category = new CategoryEntity
                {
                    Id   = catId,
                    Name = pollCreate.Category
                },
                Code = generatedCode
            };

            await _pollRepository.InsertPollAsync(poll);

            return(new PollCreated
            {
                Code = generatedCode.Code
            });
        }
Beispiel #2
0
        public async Task <Poll> InsertPollAsync(PollCreate pollCreate)
        {
            Entity.Poll poll = new(pollCreate);
            await pollRepository.InsertPollAsync(poll);

            return(Poll.Of(poll));
        }
Beispiel #3
0
        public async Task <ActionResult <Poll> > Post([FromBody] PollCreate poll)
        {
            if (poll is null)
            {
                return(BadRequest("Missing payload"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid payload"));
            }

            if (poll.Description is null)
            {
                return(BadRequest("A poll requires a description"));
            }

            if (poll.EndDate == default)
            {
                return(BadRequest("A poll required an ending date"));
            }

            if (poll.Description.Length > 100)
            {
                return(BadRequest("Description cannot be longer than 100 characters"));
            }

            if (poll.Options is null || !poll.Options.AtLeast(2))
            {
                return(BadRequest("A poll requires at least two options"));
            }

            if (poll.VotingSystem == VotingSystem.Ranked)
            {
                if (poll.AllowAdd)
                {
                    return(BadRequest("A ranked system poll cannot have more options added after it's been created"));
                }

                if (poll.ShowVoters)
                {
                    return(BadRequest("A ranked system poll cannot show its voters"));
                }
            }
            return(Ok(await pollService.InsertPollAsync(poll)));
        }
Beispiel #4
0
 public async Task <IActionResult> Post([FromBody] PollCreate create)
 {
     return(Ok(await _pollService.CreatePoll(create)));
 }