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)); }
public async Task <IActionResult> GetCity(int id) { var city = await _cityRepository.GetCity(id); var cityResource = CityMapper.MapCityToCityResource(city); return(Ok(cityResource)); }
public async Task <IActionResult> GetCities() { var cities = await _cityRepository.GetCities(); var citiesResources = CityMapper.MapCitiesToCityResources(cities); return(Ok(citiesResources)); }
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); }
public async Task <IActionResult> AddCity(CityResource cityResource) { var city = CityMapper.MapCityResourceToCity(cityResource); _cityRepository.AddCity(city); await _unitOfWork.UpdateDatabase(); return(Ok()); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { PersonMapper.Map(modelBuilder); PersonRelationMapper.Map(modelBuilder); PhoneNumberMapper.Map(modelBuilder); CityMapper.Map(modelBuilder); base.OnModelCreating(modelBuilder); }
public async Task <ActionResult <City> > GetCityByID(int id) { if (id <= 0) { return(BadRequest()); } City city = await dictionaryStorage.CityGetByID(id); return(Ok(CityMapper.ToOutputModel(city))); }
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)); }
public CityViewModel GetCityAsViewModel(Guid id) { var entity = _repository.Get(id); if (entity == null) { throw new Exception(LOCALIZATION_CITY_NOT_FOUND); } return(CityMapper.MapToCityViewModel(entity)); }
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)); }
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); }
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); }
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(); }
public void UpdateCity(City city) { var cityFromDb = _serviceDbContext.Cities.SingleOrDefault(c => c.Id == city.Id); CityMapper.SetCityToUpdate(cityFromDb, city); }
public List <LookupViewModel> GetAllAsLookup(Guid countryId) { return(CityMapper.MapToLookupViewModel(_repository.GetAll(countryId))); }
public async Task <ActionResult <List <City> > > GetAllCities() { List <City> cities = await dictionaryStorage.CitiesGetAll(); return(Ok(CityMapper.ToOutputModels(cities))); }