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 }); }
public async Task <Poll> InsertPollAsync(PollCreate pollCreate) { Entity.Poll poll = new(pollCreate); await pollRepository.InsertPollAsync(poll); return(Poll.Of(poll)); }
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))); }
public async Task <IActionResult> Post([FromBody] PollCreate create) { return(Ok(await _pollService.CreatePoll(create))); }