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));
        }
Beispiel #2
0
 public void RemoveFromPost(PostPoll postPoll)
 {
     this.dbContext.PostPolls.Remove(postPoll);
 }
Beispiel #3
0
 public void AddPollToPost(PostPoll postPoll)
 {
     this.dbContext.PostPolls.Add(postPoll);
 }