public async Task <IActionResult> UploadCity([FromBody] CityUploadDto cityUploadDto) { if (cityUploadDto == null || !InfraData.CountriesNames.Contains(cityUploadDto.Country)) { return(BadRequest("The country name is incorrect!")); } var result = await _service.UploadCityAsync(cityUploadDto); if (result.UploadSuccessful) { return(CreatedAtAction(nameof(GetCityByNameAndCode), result.CityFromMap)); } return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); }
public async Task <ReturnedUpload> UploadCityAsync(CityUploadDto cityUploadDto) { var cityFromMap = _mapper.Map <City>(cityUploadDto); cityFromMap.Alpha2Code = InfraData.CountriesCodes[cityUploadDto.Country].Alpha2Code; cityFromMap.Alpha3Code = InfraData.CountriesCodes[cityUploadDto.Country].Alpha3Code; cityFromMap.CurrenciesCode = InfraData.CountriesCodes[cityUploadDto.Country].CurrenciesCode; _cityRepo.Add(cityFromMap); bool successful = await _cityRepo.SaveChangesAsync(); ReturnedUpload result = new ReturnedUpload { CityFromMap = cityFromMap, UploadSuccessful = successful }; return(result); }