public Users RemoveUser(RemoveUserCommand account) { using (var db = _paintStoreContext) { var userToRemove = db.Users.First(x => x.Id == account.Id); try { _signInService.SignInCheck(new SignInCommand { Email = account.Email, Password = account.Password }, db); foreach (var post in db.Posts.Where(x => x.UserId == userToRemove.Id)) { _postsService.PostRemover(post.Id); } foreach (var follow in db.UserFollowers. Where(x => x.FollowedUserId == userToRemove.Id || x.FollowingUserId == userToRemove.Id)) { _followersService.FollowRemove(follow.FollowingUserId, follow.FollowedUserId); } db.Users.Remove(userToRemove); db.SaveChanges(); return(userToRemove); } catch (UnauthorizedAccessException) { throw new UnauthorizedAccessException(); } catch (Exception ex) { throw ex; } } }
public IActionResult FollowRemove(int userIdFollowing, int userIdFollowed) { return(Ok(_followersService.FollowRemove(userIdFollowing, userIdFollowed))); }