public async Task <int> BlockUser(BlockUserRequest request) { var kicker = await _context.Users.SingleOrDefaultAsync(user => user.UserName == request.KickerName); if (kicker == null) { return(0); } var blocked = await _context.Users.SingleOrDefaultAsync(user => user.UserName == request.BlockedName); if (blocked == null) { return(0); } _context.Blocks.Add(new BlockedEntity { Id = Guid.NewGuid(), KickerID = kicker.ID, BlockedID = blocked.ID, Date = DateTime.Now }); return(await _context.SaveChangesAsync()); }
public async Task <IActionResult> Block([FromBody] BlockUserRequest request) { if (!ModelState.IsValid) { return(BadRequest()); } if ((!await _userService.isUserNameExist(request.KickerName) || (!await _userService.isUserNameExist(request.BlockedName)))) { return(NotFound("There is no such a username")); } var isBlocked = await _userService.isBlocked(request); if (isBlocked) { return(BadRequest("You have already blocked this user")); } if (await _userService.BlockUser(request) == 0) { return(NotFound("Your username or the username you want to block could not be found.")); } return(Ok()); }
public async Task <IActionResult> UnBlockUser([FromBody] BlockUserRequest request) { request.UserId = (int)HttpContext.Items["id"]; await this._userService.UnBlockUserAsync(request); return(Ok()); }
public async Task <IActionResult> BlockUser(BlockUserRequest request) { var response = await mediator.Send(request); logger.LogResponse($"Admin #{HttpContext.GetCurrentUserId()} blocked #{request.UserId} user", response.Error); return(response.IsSucceeded ? (IActionResult)Ok(response) : BadRequest(response)); }
public IActionResult Block([FromBody] BlockUserRequest request) { bool isSuccess = _userManager.BlockUser(CurrentUserId.Value, request.Username); if (!isSuccess) { return(BadRequest()); } return(Ok()); }
public async Task <bool> isBlocked(BlockUserRequest request) { var kicker = await _context.Users.SingleOrDefaultAsync(user => user.UserName == request.KickerName); var blocked = await _context.Users.SingleOrDefaultAsync(user => user.UserName == request.BlockedName); var result = await _context.Blocks.SingleOrDefaultAsync(block => block.KickerID == kicker.ID && block.BlockedID == blocked.ID); if (result == null) { return(false); } return(true); }
public async Task UnBlockUserAsync(BlockUserRequest request) { var currentUser = await this._auth.FindByIdUserAsync(request.UserId); if (currentUser == null) { throw new UserNotExistException("Given user not exist!!", 400); } var blockedUser = await this._unit.BlockedUserRepository .IsBlockedUserAsync(currentUser.Id, request.UserIdToBlock); if (blockedUser == null) { throw new BlockedUserNotExistException("User to unblock not exist!!", 400); } await this._unit.BlockedUserRepository.DeleteAsync(blockedUser.Id); await this._unit.Commit(); }
public async Task BlockUserAsync(BlockUserRequest request) { var currentUser = await this._auth.FindByIdUserAsync(request.UserId); if (currentUser == null) { throw new UserNotExistException("Given user not exist!!", 400); } var userToBlock = await this._unit.UserRepository.GetAsync(request.UserIdToBlock); if (userToBlock == null) { throw new UserNotExistException("User to block not exist!!", 400); } var blockedUser = await this._unit.BlockedUserRepository .IsBlockedUserAsync(currentUser.Id, request.UserIdToBlock); if (blockedUser != null) { throw new BlockedUserAlreadyExistException("Given user to block is already blocked!!", 400); } var newBlockedUser = new BlockedUser() { UserId = currentUser.Id, UserToBlockId = request.UserIdToBlock }; await this._unit.BlockedUserRepository .CreateAsync(newBlockedUser); await this._unit.Commit(); }
public async Task <IActionResult> BlockUser(BlockUserRequest request, CancellationToken cancellationToken) { await _identityService.BlockUser(request.UserId, request.UntilDate, cancellationToken); return(Ok()); }