public async Task <Post> EditPost(AppUser appUser, PostEditRequest request) { if (!request.Id.HasValue) { throw new AppException("Id is not null"); } var post = await _unitOfWork.Repository.GetSingle(x => x.Id == request.Id.Value); if (post == null) { throw new AppException("Post not found!"); } post.Title = request.Title; post.Content = request.Content; post.UserId = appUser.Id; await UpdatePostTags(post, request); _unitOfWork.Repository.Update(post); await _unitOfWork.SaveChanges(); return(post); }
public async Task <IActionResult> EditPost([FromBody] PostEditRequest request) { var appUser = (AppUser)HttpContext.Items["User"]; var result = await _service.EditPost(appUser, request); return(Ok(result)); }
private async Task UpdatePostTags(Post post, PostEditRequest request) { var tagList = new List <Tag>(); if (request.Tags != null) { tagList = await _tagService.GetAllByName(request.Tags); } await _postTagService.UpdatePostTags(post, tagList); }
public async Task <Post> AddPost(AppUser appUser, PostEditRequest request) { var post = new Post { Title = request.Title, Content = request.Content, UserId = appUser.Id }; await UpdatePostTags(post, request); await _unitOfWork.Repository.Add(post); await _unitOfWork.SaveChanges(); return(post); }
public void EditPost(PostEditRequest request) { _dataProvider.UpdatePost(request.PostId, request.Title, request.Content, request.Categories, request.Publish); }