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("操作失败"); }