public async Task <IActionResult> AttachExistingPollToPost([FromBody] PollPostViewModel model) { var poll = this.unitOfWork.PollsRepository.GetById(model.PollId); var post = this.unitOfWork.PostsRepository.GetById(model.PostId); if (post == null || poll == null) { return(BadRequest()); } var userId = this.userManager.GetUserId(User); if (poll.UserId != userId || post.UserId != userId) { return(Forbid()); } PostPoll postPoll = new PostPoll { Poll = poll, Post = post }; this.unitOfWork.PollsRepository.AddPollToPost(postPoll); await this.unitOfWork.Save(); return(StatusCode(201)); }
public static async Task <PollPostResultViewModel> TestPollPost() { var pollController = new PollController(_pollService); var pollPost = new PollPostViewModel { poll_description = "This is the question", options = new List <string> { "First Option", "Second Option", "Third Option" } }; var result = await pollController.Post(pollPost); return(result); }
public async Task <PollPostResultViewModel> CreatePollAsync([FromBody] PollPostViewModel model) { var poll = new Poll { poll_description = model.poll_description, Options = model.options.Select(x => new Options { option_description = x }).ToList() }; _dataContext.Add(poll); await _dataContext.SaveChangesAsync(); return(new PollPostResultViewModel { poll_id = poll.poll_id }); }
public async Task <PollPostResultViewModel> Post([FromBody] PollPostViewModel model) => await _pollService.CreatePollAsync(model);