public async Task <PostDetailsModel> GetById(int id) { ForumPost post = await _unitOfWork.ForumPosts.GetById(id); PostDetailsModel postDetails = new PostDetailsModel(post); return(postDetails); }
public async Task <PostDetailsModel> UpdatePost(EditPostModel editModel) { ForumPost post = await _unitOfWork.ForumPosts.GetById(editModel.PostId); if (post == null) { throw new EntityNotFoundException <ForumPost>(editModel.PostId); } post.Content = editModel.Content; _unitOfWork.ForumPosts.Update(post); await _unitOfWork.SaveChanges(); PostDetailsModel postDetails = new PostDetailsModel(post); return(postDetails); }
public async Task <PostDetailsModel> CreatePost(CreatePostModel createModel) { ForumPost post = new ForumPost { ThreadId = createModel.ThreadId, Content = createModel.Content }; if (!string.IsNullOrWhiteSpace(createModel.Username)) { User user = await _userService.GetByUsername(createModel.Username); post.User = user; post.UserId = user.Id; } _unitOfWork.ForumPosts.Add(post); await _unitOfWork.SaveChanges(); PostDetailsModel postDetails = new PostDetailsModel(post); return(postDetails); }