public async Task <Transition> Handle(CreateTransitionCommand request, CancellationToken cancellationToken)
        {
            var locationFrom = await _locationRepository.GetEntity(request.FromLocationId);

            if (locationFrom == null)
            {
                throw new EntityNotFoundException <Location>(request.FromLocationId);
            }

            var locationTo = await _locationRepository.GetEntity(request.ToLocationId);

            if (locationTo == null)
            {
                throw new EntityNotFoundException <Location>(request.ToLocationId);
            }

            var transitionExist =
                await _transitionRepository.ExistTransitionBetween(locationFrom.Id, locationTo.Id);

            if (transitionExist)
            {
                throw new TransitionAlreadyExistsException(locationFrom.Id, locationTo.Id);
            }

            var transition = new Transition
            {
                From = locationFrom,
                To   = locationTo
            };

            await _transitionRepository.AddEntity(transition);

            return(transition);
        }
Exemplo n.º 2
0
        public async Task <Location> Handle(GetLocationQuery request, CancellationToken cancellationToken)
        {
            var location = await _locationRepository.GetEntity(request.LocationId);

            if (location == null)
            {
                throw new EntityNotFoundException <Location>(request.LocationId);
            }

            return(location);
        }
Exemplo n.º 3
0
        public async Task <Location> Handle(UpdateLocationCommand request, CancellationToken cancellationToken)
        {
            var location = await _locationRepository.GetEntity(request.LocationId);

            if (location == null)
            {
                throw new EntityNotFoundException <Location>(request.LocationId);
            }

            location.Name        = request.Name;
            location.Description = request.Description;

            await _locationRepository.UpdateEntity(location);

            return(location);
        }