public async Task <IActionResult> deletePost([FromBody] DeletePostDto deletePostDto) { //if ((User.FindFirst(ClaimTypes.NameIdentifier).Value) != Request.Headers["UserId"]) //{ // return Unauthorized(); //} if (!ModelState.IsValid) { return(Ok()); } deletePostDto.UserId = Convert.ToInt32(User.FindFirst(ClaimTypes.NameIdentifier).Value); ProfileStatisticDto userCondition = await _post.deletePost(deletePostDto); if (userCondition.UserId > 0) { string postImagePath = await _post.getPostImagePathByPostId(deletePostDto.PostId); if (postImagePath.Trim().Length > 0) { string path = _environment.WebRootPath + postImagePath; System.IO.File.Delete(path); } } return(Ok(userCondition)); }
public async Task <ProfileStatisticDto> deletePost(DeletePostDto deletePostDto) { UserCondition userCondition = await _post.deletePost(deletePostDto); ProfileStatisticDto profileStatisticDto = _mapper.Map <ProfileStatisticDto>(userCondition); return(profileStatisticDto); }
public async Task <UserCondition> deletePost(DeletePostDto deletePostDto) { Post post = await _ctx.Post.Where(m => m.UserId == deletePostDto.UserId && m.PostId == deletePostDto.PostId).FirstOrDefaultAsync(); UserCondition userCondition = new UserCondition(); if (post != null) { post.DeletedDate = DateTime.Now; _ctx.Update(post); int response = await _ctx.SaveChangesAsync(); if (response > 0) { userCondition = await _ctx.UserCondition.Where(m => m.UserId == deletePostDto.UserId).FirstOrDefaultAsync(); if (post.Condition == 0) { userCondition.UnknownCount -= 1; } else if (post.Condition == 1) { userCondition.SuccessCount -= 1; } else { userCondition.FailureCount -= 1; } _ctx.UserCondition.Update(userCondition); int conditionResponse = await _ctx.SaveChangesAsync(); if (conditionResponse > 0) { return(userCondition); } } } return(userCondition); }