public CircleCreateResult Create(CircleCreateCommand command) { using (var transaction = new TransactionScope()) { var ownerId = new UserId(command.OwnerId); var owner = userRepository.Find(ownerId); if (owner == null) { throw new UserNotFoundException(ownerId, "서클장이 될 사용자가 없음"); } var name = new CircleName(command.Name); var circle = circleFactory.Create(name, owner); if (circleService.Exists(circle)) { throw new CanNotRegisterCircleException(circle, "이미 등록된 서클임"); } circleRepository.Save(circle); transaction.Complete(); return(new CircleCreateResult(circle.Id.Value)); } }
public CircleCreateOutputData Handle(CircleCreateInputData inputData) { using var transaction = new TransactionScope(); var ownerId = new UserId(inputData.OwnerId); var owner = userRepository.Find(ownerId); if (owner == null) { throw new UserNotFoundException(ownerId, "サークルのオーナーとなるユーザが見つかりませんでした。"); } var name = new CircleName(inputData.Name); var circle = circleFactory.Create(name, owner); if (circleService.Exists(circle)) { throw new CanNotRegisterCircleException(circle, "サークルは既に存在しています。"); } circleRepository.Save(circle); transaction.Complete(); return(new CircleCreateOutputData(circle.Id.Value)); }
public void Create(CircleCreateCommand command) { var ownerId = new UserId(command.UserId); var owner = userRepository.Find(ownerId); if (owner == null) { throw new Exception("サークルオーナーとなるユーザーが見つかりませんでした。"); } var name = new CircleName(command.Name); var circle = circleFactory.Create(name, owner); if (circleService.Exists(circle)) { throw new Exception("サークルは既に存在しています。"); } circleRepository.Save(circle); }
public void Create(CircleCreateCommand command) { using (var transaction = new TransactionScope()) { var ownerId = new UserId(command.UserId); var owner = userRepository.Find(ownerId); if (owner == null) { throw new UserNotFoundException(ownerId, "サークルのオーナーとなるユーザが見つかりませんでした。"); } var name = new CircleName(command.Name); var circle = circleFactory.Create(name, owner); if (circleService.Exists(circle)) { throw new CanNotRegisterCircleException(circle, "サークルは既に存在しています。"); } circleRepository.Save(circle); transaction.Complete(); } }
public Task <CircleRegisterOutputData> Handle(CircleRegisterCommand command, CancellationToken cancellationToken) { using var transaction = new TransactionScope(); var circle = _circleFactory.Create(command.Name, command.OwnerId); if (_circleService.Exists(circle)) { throw new CanNotCircleRegisterException($"{command.Name} は既に存在します。"); } var owner = _userRepository.Find(circle.Owner); if (owner is null) { throw new UserNotFoundException($"IDが {command.OwnerId} のユーザーは存在しません。"); } _circleRepository.Save(circle); transaction.Complete(); return(Task.FromResult(new CircleRegisterOutputData(circle.Id.Value))); }
public Circle CreateCircle(ICircleFactory circleFactory, string circleName) { return(circleFactory.Create(id, circleName)); }