コード例 #1
0
        public IHttpActionResult UpdatePost(string role, PostForUpdateDTO model)
        {
            if (!ModelState.IsValid || model == null)
            {
                return(BadRequest("Eksik yahut hatalı bilgi girdiniz"));
            }

            var post = _postRepository.Get(p => p.PostId == model.PostId);

            if (post == null)
            {
                return(BadRequest("böyle bir post mevcut değil"));
            }


            if (post.UserId != model.UserId && role != "admin")
            {
                return(BadRequest("Bu Makaleyi Değiştirmeye Yetkiniz Yok"));
            }

            post.Title         = model.Title;
            post.Body          = model.Body;
            post.ImageUrl      = model.ImageUrl;
            post.SubCategoryId = model.SubCategoryId;
            post.CategoryId    = model.CategoryId;



            _postRepository.Update(post);

            return(Ok());
        }
コード例 #2
0
        public IActionResult UpdatePost(string role, PostForUpdateDTO model)
        {
            if (!ModelState.IsValid || model == null)
            {
                return(BadRequest(Messages.ModelNullOrEmpty));
            }


            var post = _postService.GetById(model.PostId);

            if (!post.Success)
            {
                return(BadRequest(post.Message));
            }

            if (post.Data.UserId != model.UserId && role != "admin")
            {
                return(BadRequest(Messages.YouUnauthorizeChangeThisComment));
            }

            post.Data.Title         = model.Title;
            post.Data.Body          = model.Body;
            post.Data.ImageUrl      = model.ImageUrl;
            post.Data.SubCategoryId = model.SubCategoryId;
            post.Data.CategoryId    = model.CategoryId;

            _postService.Update(post.Data);

            return(Ok());
        }