コード例 #1
0
        /// <summary>
        /// Method that deletes a post
        /// </summary>
        public async Task <bool> DeletePost(PostDeleteRequest post)
        {
            try
            {
                int idPost            = Convert.ToInt32(post.id);
                var postToRemove      = _context.Post.FirstOrDefault(x => x.id == idPost);
                var Post_UserToRemove = _context.Post_User.FirstOrDefault(x => x.id_post == idPost);
                var CommentToRemove   = _context.Comment.FirstOrDefault(x => x.id_post == idPost);

                if (postToRemove != null)
                {
                    _context.Post.Remove(postToRemove);
                    _context.Post_User.Remove(Post_UserToRemove);
                }
                if (CommentToRemove != null)
                {
                    _context.Comment.Remove(CommentToRemove);
                }

                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
                _context.Dispose();
            }
        }
コード例 #2
0
ファイル: EditorService.cs プロジェクト: Jezuz85/ZemogaTest
        /// <summary>
        /// Method that deletes a post
        /// </summary>
        public async Task <bool> DeletePost(PostDeleteRequest post)
        {
            try
            {
                var result = await _repository.DeletePost(post);

                return(result);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #3
0
ファイル: EditorFacade.cs プロジェクト: Jezuz85/ZemogaTest
        /// <summary>
        /// Method that deletes a post
        /// </summary>
        public async Task <bool> DeletePost(PostDeleteRequest post)
        {
            try
            {
                var newPost = _mapper.Map <Domain.Dto.PostDeleteRequest>(post);

                var response = await _service.DeletePost(newPost);

                return(response);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #4
0
        public async Task <bool> DeletePost(PostDeleteRequest post)
        {
            try
            {
                var postData = new StringContent(JsonConvert.SerializeObject(post), Encoding.UTF8, "application/json");

                var result = await _httpClient.PostAsync("Editor", postData);

                if (result.IsSuccessStatusCode)
                {
                    var response = JsonConvert.DeserializeObject <bool>(result.Content.ReadAsStringAsync().Result);
                    return(response);
                }
                return(false);
            }
            catch (System.Exception)
            {
                return(false);
            }
        }
コード例 #5
0
 public IActionResult Delete([FromBody] PostDeleteRequest request)
 {
     try
     {
         var userId = _authenticationService.GetAuthenticatedUserId(User);
         _postService.Delete(request.PostId, userId);
         return(new ObjectResult(new
         {
             StatusCode = ResponseConstants.Success,
         }));
     }
     catch (PostNotFoundException)
     {
         return(new ObjectResult(new Result {
             StatusCode = ResponseConstants.Unknown
         }));
     }
     catch (Exception)
     {
         return(new ObjectResult(new Result {
             StatusCode = ResponseConstants.Unknown
         }));
     }
 }