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 CircleUpdateOutputData Handle(CircleUpdateInputData inputData) { using var transaction = new TransactionScope(); var id = new CircleId(inputData.Id); var circle = circleRepository.Find(id); if (circle == null) { throw new CircleNotFoundException(id); } if (inputData.Name != null) { var name = new CircleName(inputData.Name); circle.ChangeName(name); if (circleService.Exists(circle)) { throw new CanNotRegisterCircleException(circle, "이미 등록된 서클임"); } } circleRepository.Save(circle); transaction.Complete(); return(new CircleUpdateOutputData()); }
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) { 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 <Unit> Handle(CircleUpdateCommand command, CancellationToken cancellationToken) { using var transaction = new TransactionScope(); var circle = _circleRepository.Find(new CircleId(command.Id)); if (command.Name != null) { circle.ChangeName(new CircleName(command.Name)); if (_circleService.Exists(circle)) { throw new CanNotCircleRegisterException($"{ command.Name } は既に存在します。"); } } _circleRepository.Save(circle); transaction.Complete(); return(Task.FromResult(Unit.Value)); }
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))); }