public async Task <BaseResponse <BlockList> > BlockUserAsync(RequestBlockModel request) { var response = new BaseResponse <BlockList>(); var blockedUser = await _userService.GetUserByUsername(request.BlockedUserName); if (blockedUser.HasError) { response.Errors.Add("Block işlemi sırasında hata oluştu!"); return(response); } var entitiy = new BlockList { UserId = new ObjectId(request.UserId), BlockedUserId = blockedUser.Data.Id, UserName = request.UserName, BlockedUserName = request.BlockedUserName }; var isBlocked = await _blockRepository.IsBlocked(entitiy); if (isBlocked == null) { var result = await _blockRepository.InsertAsync(entitiy); if (result.Id != default) { response.Data = result; return(response); } } response.Errors.Add("Kullanıcı daha önce blocklanmış!"); return(response); }
public async Task <BaseResponse <Messages> > SendMessage(RequestMessageModel request) { var response = new BaseResponse <Messages>(); var toUser = await _userRepository.GetByUserNameAsync(request.ToUserName); if (toUser != null) { var entity = new Messages { FromId = new ObjectId(request.FromId), SendToId = toUser.Id, FromUserName = request.FromUserName, ToUserName = request.ToUserName, Message = request.Message }; var isBlocked = await _blockRepository.IsBlocked(new BlockList { UserId = entity.FromId, BlockedUserId = toUser.Id }); if (isBlocked == null) { var result = await _messageRepository.InsertAsync(entity); if (result.Id != default) { response.Data = result; return(response); } } else { response.Errors.Add("Blocklandığınız için mesaj gönderemezsiniz!"); return(response); } } response.Errors.Add("Kullanıcı bulunamadı!"); return(response); }