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()); }
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()); }