コード例 #1
0
        public List <CityViewModel> GetCities(string columnName, string searchString, Guid countryId)
        {
            List <City> entities;

            switch (columnName.ToLower())
            {
            case "name":
                entities = _repository.GetByCityName(searchString, countryId);
                break;

            case "postcode":
                entities = _repository.GetByCityPostcode(searchString, countryId);
                break;

            default:
                entities = _repository.GetAll(countryId);
                break;
            }

            if (entities == null)
            {
                throw new Exception(LOCALIZATION_CITY_NOT_FOUND);
            }

            return(CityMapper.MapToCityViewModel(entities));
        }
コード例 #2
0
        public async Task <IActionResult> GetCity(int id)
        {
            var city = await _cityRepository.GetCity(id);

            var cityResource = CityMapper.MapCityToCityResource(city);

            return(Ok(cityResource));
        }
コード例 #3
0
        public async Task <IActionResult> GetCities()
        {
            var cities = await _cityRepository.GetCities();

            var citiesResources = CityMapper.MapCitiesToCityResources(cities);

            return(Ok(citiesResources));
        }
コード例 #4
0
        public void MapCityResourceFromCity_IfCityExists_ShouldMap()
        {
            var testCityResource = CityMapper.MapCityToCityResource(city);

            testCityResource.Id.Should().Be(3);
            testCityResource.Description.Should().Be("City Description A");
            testCityResource.Area.Should().Be(130.9);
        }
コード例 #5
0
        public async Task <IActionResult> AddCity(CityResource cityResource)
        {
            var city = CityMapper.MapCityResourceToCity(cityResource);

            _cityRepository.AddCity(city);
            await _unitOfWork.UpdateDatabase();

            return(Ok());
        }
コード例 #6
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            PersonMapper.Map(modelBuilder);
            PersonRelationMapper.Map(modelBuilder);
            PhoneNumberMapper.Map(modelBuilder);
            CityMapper.Map(modelBuilder);

            base.OnModelCreating(modelBuilder);
        }
コード例 #7
0
ファイル: DictionaryController.cs プロジェクト: evsig/DevEdu
        public async Task <ActionResult <City> > GetCityByID(int id)
        {
            if (id <= 0)
            {
                return(BadRequest());
            }
            City city = await dictionaryStorage.CityGetByID(id);

            return(Ok(CityMapper.ToOutputModel(city)));
        }
コード例 #8
0
        public List <CityViewModel> GetCities(Guid countryId)
        {
            var entities = _repository.GetAll(countryId);

            if (entities == null)
            {
                throw new Exception(LOCALIZATION_CITY_NOT_FOUND);
            }

            return(CityMapper.MapToCityViewModel(entities));
        }
コード例 #9
0
        public CityViewModel GetCityAsViewModel(Guid id)
        {
            var entity = _repository.Get(id);

            if (entity == null)
            {
                throw new Exception(LOCALIZATION_CITY_NOT_FOUND);
            }

            return(CityMapper.MapToCityViewModel(entity));
        }
コード例 #10
0
ファイル: DictionaryController.cs プロジェクト: evsig/DevEdu
        public async Task <ActionResult <int?> > UpdateCity([FromBody] CityInputModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }
            City dataModel = CityMapper.ToDataModel(model);
            int? id        = await dictionaryStorage.CityAddOrUpdate(dataModel);

            return(Ok(id));
        }
コード例 #11
0
        public void CorrectMapping_ToCity()
        {
            //Arrange
            var cityDTO = new CityDTO
            {
                Id   = 4,
                Name = "Pleven"
            };

            //Act & Assert
            var sut    = new CityMapper();
            var result = sut.MapToCity(cityDTO);

            Assert.IsInstanceOfType(result, typeof(City));
            Assert.AreEqual(cityDTO.Name, result.Name);
        }
コード例 #12
0
        public void CorrectMapping_ToCityDTO()
        {
            //Arrange
            var city = new City
            {
                Id   = 3,
                Name = "Ruse",
            };

            //Act & Assert
            var sut    = new CityMapper();
            var result = sut.MapToCityDTO(city);

            Assert.IsInstanceOfType(result, typeof(CityDTO));
            Assert.AreEqual(city.Id, result.Id);
            Assert.AreEqual(city.Name, result.Name);
        }
コード例 #13
0
        public void TestTravelTimeResponse_WithValidJsonReturned_CanBeDeserializedSuccessfully()
        {
            // Arrange
            const string response = "{\"travel_time_minutes\": 42}";
            var          mockHttp = new MockHttpMessageHandler();

            mockHttp.When("https://developer.citymapper.com/api/1/traveltime/*").Respond("application/json", response);

            var underTest = new CityMapper("fake-api-key", mockHttp.ToHttpClient());

            // Act
            var travelTime = underTest.TravelTimeInMinutesAsync(new Coordinate(), new Coordinate());

            // Assert
            // TODO: Possibly not best practice
            Assert.AreEqual(travelTime.Result, 42);
            mockHttp.VerifyNoOutstandingExpectation();
        }
コード例 #14
0
        public void UpdateCity(City city)
        {
            var cityFromDb = _serviceDbContext.Cities.SingleOrDefault(c => c.Id == city.Id);

            CityMapper.SetCityToUpdate(cityFromDb, city);
        }
コード例 #15
0
 public List <LookupViewModel> GetAllAsLookup(Guid countryId)
 {
     return(CityMapper.MapToLookupViewModel(_repository.GetAll(countryId)));
 }
コード例 #16
0
ファイル: DictionaryController.cs プロジェクト: evsig/DevEdu
        public async Task <ActionResult <List <City> > > GetAllCities()
        {
            List <City> cities = await dictionaryStorage.CitiesGetAll();

            return(Ok(CityMapper.ToOutputModels(cities)));
        }