public async Task <bool> Handle(QuitCircleCommand request, CancellationToken cancellationToken) { var myId = Guid.Parse(_httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value); var userCircle = await _userCircleRelationRepository.GetRelationAsync(request.CircleId, myId); if (userCircle == null) { return(true); } var circle = await _circleRepository.GetByIdAsync(request.CircleId); if (circle.OwnerId == myId) { throw new ClientException("操作失败", new List <string> { $"User {myId} is the owner of the circle {request.CircleId}, can't quit circle." }); } userCircle.Quit(); _userCircleRelationRepository.Remove(userCircle); return(await _userCircleRelationRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken)); }
public async Task Handle(CircleDeletedDomainEvent notification, CancellationToken cancellationToken) { _logger.LogInformation("----- Handling CircleDeletedDomainEvent: at {AppName} - ({@DomainEvent})", Program.AppName, notification); var relations = await _userCircleRelationRepository.GetRelationsByCircleIdAsync(notification.CircleId); relations.ForEach(r => _userCircleRelationRepository.Remove(r)); }