コード例 #1
0
        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));
            }
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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();
            }
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        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)));
        }