示例#1
0
            public async Task <string> Handle(CreateCityCommand request, CancellationToken cancellationToken)
            {
                var cityExist = await _distributorRepository.CityExistAsync(request.Name);

                if (cityExist)
                {
                    throw new CityAlreadyExistException(request.Name);
                }

                var city = new City(Guid.NewGuid().ToString(), request.Name);

                _distributorRepository.AddCity(city);

                await _distributorRepository.UnitOfWork.SaveEntitiesAsync();

                return(city.Id.ToString());
            }
示例#2
0
            public async Task <string> Handle(UpdateCityCommand request, CancellationToken cancellationToken)
            {
                var city = await _distributorRepository.FindCityByIdAsync(request.CityId);

                if (city == null)
                {
                    throw new CityNotFoundException(request.CityId);
                }

                var cityExist = await _distributorRepository.CityExistAsync(request.Name);

                if (cityExist)
                {
                    throw new CityAlreadyExistException(request.Name);
                }

                city.UpdateCity(request.Name);

                _distributorRepository.UpdateCity(city);

                await _distributorRepository.UnitOfWork.SaveEntitiesAsync();

                return(city.Id.ToString());
            }