public async Task <bool> Handle(FollowEachOtherCommand request, CancellationToken cancellationToken) { var anotherUserId = await _userRepository.GetUserIdByCodeAsync(request.InvitingUserCode); if (anotherUserId != null) { var userId = Guid.Parse(request.UserId); var relation1 = new UserRelation(userId, anotherUserId.Value); var relation2 = new UserRelation(anotherUserId.Value, userId); relation1.Follow(); relation2.Follow(); _userRelationRepository.Add(relation1); _userRelationRepository.Add(relation2); return(await _userRelationRepository.UnitOfWork.SaveEntitiesAsync()); } return(false); }
public async Task <bool> Handle(FollowCommand request, CancellationToken cancellationToken) { var ur = await _userRelationRepository.GetUserRelationAsync(request.FollowerId, request.FollowedUserId); if (ur == null) { ur = new UserRelation(request.FollowerId, request.FollowedUserId); _userRelationRepository.Add(ur); return(await _userRelationRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken)); } return(true); }
public async Task <bool> Handle(ToggleUserFollowCommand request, CancellationToken cancellationToken) { var isFollow = false; var ur = await _userRelationRepository.GetAsync(request.FollowerId, request.UserIdToFollow); if (ur == null) { ur = new UserRelation(request.FollowerId, request.UserIdToFollow); ur.Follow(); _userRelationRepository.Add(ur); isFollow = true; } else { if (ur.Followed) { ur.UnFollow(); } else { isFollow = true; ur.Follow(); } } var result = await _userRelationRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken); if (result) { if (isFollow) { await SendUserFollowedEventAsync(request.FollowerId, request.UserIdToFollow); } else { await SendUserUnFollowedEventAsync(request.FollowerId, request.UserIdToFollow); } // 返回被关注者是否关注了我 ur = await _userRelationRepository.GetAsync(request.UserIdToFollow, request.FollowerId); return(ur?.Followed ?? false); } throw new ApplicationException("操作失败"); }
public async Task <bool> Handle(MuteUserCommand request, CancellationToken cancellationToken) { var claim = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier); var myId = claim == null ? Guid.Empty : Guid.Parse(claim.Value); var userRelation = await _userRelationRepository.GetAsync(myId, request.UserId); if (request.Muted) { if (userRelation == null) { userRelation = new UserRelation(myId, request.UserId); _userRelationRepository.Add(userRelation); } userRelation.Mute(); } else if (userRelation != null) { userRelation.UnMute(); } return(await _userRelationRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken)); }
public void Add(UserRelation ur) { _userRelationRepository.Add(ur); }
public void Create(UserRelation ur) { _userRelationRepository.Add(ur); _userRelationRepository.Commit(); }