Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public async Task <IActionResult> EditPost([FromBody] PostEditRequest request)
        {
            var appUser = (AppUser)HttpContext.Items["User"];
            var result  = await _service.EditPost(appUser, request);

            return(Ok(result));
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
 public void EditPost(PostEditRequest request)
 {
     _dataProvider.UpdatePost(request.PostId, request.Title, request.Content, request.Categories, request.Publish);
 }