public async Task Update(CityDto cityDto) { var city = CityMappers.FromCityDtoToCity(cityDto); city.Updated = DateTime.UtcNow; await _cityRepository.Update(city); }
public async Task <IEnumerable <CityViewModel> > Get([FromQuery] CityFilterModel cityFilterModel) { var data = await _cityService.GetAll(cityFilterModel); Response?.Headers?.Add("total-count", new StringValues(data.TotalCount.ToString())); return(data.Items.Select(i => CityMappers.FromCityDtoToCityViewModel(i))); }
public async Task <CityDto> Create(CityDto cityDto) { var city = CityMappers.FromCityDtoToCity(cityDto); city.Updated = DateTime.UtcNow; await _cityRepository.Create(city); return(CityMappers.FromCityToCityDto(city)); }
public async Task <CityDto> Modify(TemperatureDto temperatureDto) { var city = await _cityRepository.GetById(temperatureDto.CityId); city.Temperature = temperatureDto.Temperature; await _cityRepository.Update(city); return(CityMappers.FromCityToCityDto(city)); }
public async Task <IPagedList <CityDto> > GetAll(CityFilterModel cityFilterModel) { var items = await _cityRepository.GetAll(cityFilterModel); return(new PagedList <CityDto>( items.Items.Select(i => CityMappers.FromCityToCityDto(i)).ToList(), items.PageNumber, items.PageSize, items.TotalCount)); }
public async Task <ActionResult <CityViewModel> > Get(int id) { var cityDto = await _cityService.GetById(id); if (cityDto == null) { return(NotFound()); } return(CityMappers.FromCityDtoToCityViewModel(cityDto)); }
public async Task <ActionResult <CityDto> > Post(CityViewModel cityViewModel) { if (!ModelState.IsValid) { return(BadRequest("City name can not be empty")); } var cityDto = CityMappers.FromCityViewModelToCityDto(cityViewModel); cityDto = await _cityService.Create(cityDto); cityViewModel = CityMappers.FromCityDtoToCityViewModel(cityDto); return(CreatedAtAction("Get", new { id = cityDto.Id }, cityViewModel)); }
public async Task <CityDto> Delete(int id) { var city = await _cityRepository.Delete(id); return(CityMappers.FromCityToCityDto(city)); }