public async Task <CircleViewModel> Handle(CreateCircleCommand request, CancellationToken cancellationToken) { var circle = await _circleRepository.GetCircleByNameAsync(request.Name); if (circle != null) { throw new ClientException("圈子名已存在"); } var myId = Guid.Parse(_httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value); var circleCount = await _circleRepository.GetUserCircleCount(myId); if (circleCount >= 5) { throw new ClientException("圈子数量已达上限"); } circle = new Domain.AggregatesModel.CircleAggregate.Circle(request.Name, request.Description, request.VerifyJoin, request.BackgroundImage, myId); _circleRepository.Add(circle); if (await _circleRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken)) { return(await _circleQueries.GetCircleAsync(circle.Id)); } throw new ApplicationException("操作失败"); }
// 发送用户已入圈事件 public static async Task SendJoinedCircleEventAsync(Domain.AggregatesModel.CircleAggregate.Circle circle, Guid joinedUserId, IMessageSession messageSession, ILogger logger) { var @event = new JoinedCircleEvent { JoinedUserId = joinedUserId, CircleOwnerId = circle.OwnerId, CircleId = circle.Id, CircleName = circle.Name }; await messageSession.Publish(@event); logger.LogInformation("----- Published JoinedCircleEvent: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); }
private async Task SendCircleOwnerChangedEventAsync(Domain.AggregatesModel.CircleAggregate.Circle circle, Guid operatorId) { var @event = new CircleOwnerChangedEvent { OldOwnerId = operatorId, NewOwnerId = circle.OwnerId, CircleId = circle.Id, CircleName = circle.Name }; var messageSession = (IMessageSession)_serviceProvider.GetService(typeof(IMessageSession)); await messageSession.Publish(@event); _logger.LogInformation("----- Published CircleOwnerChangedEvent: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); }
// 发送用户申请入圈事件 private async Task SendAppliedJoinCircleEventAsync(Guid myId, Domain.AggregatesModel.CircleAggregate.Circle circle, string applyDescription) { var @event = new AppliedJoinCircleEvent { ApplyUserId = myId, CircleOwnerId = circle.OwnerId, CircleId = circle.Id, CircleName = circle.Name, ApplyDescription = applyDescription }; await _messageSession.Publish(@event); _logger.LogInformation("----- Published AppliedJoinCircleEvent: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); }