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