Esempio n. 1
0
        public async Task Update(CityDto cityDto)
        {
            var city = CityMappers.FromCityDtoToCity(cityDto);

            city.Updated = DateTime.UtcNow;
            await _cityRepository.Update(city);
        }
Esempio n. 2
0
        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)));
        }
Esempio n. 3
0
        public async Task <CityDto> Create(CityDto cityDto)
        {
            var city = CityMappers.FromCityDtoToCity(cityDto);

            city.Updated = DateTime.UtcNow;
            await _cityRepository.Create(city);

            return(CityMappers.FromCityToCityDto(city));
        }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
        public async Task <ActionResult <CityViewModel> > Get(int id)
        {
            var cityDto = await _cityService.GetById(id);

            if (cityDto == null)
            {
                return(NotFound());
            }

            return(CityMappers.FromCityDtoToCityViewModel(cityDto));
        }
Esempio n. 7
0
        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));
        }
Esempio n. 8
0
        public async Task <CityDto> Delete(int id)
        {
            var city = await _cityRepository.Delete(id);

            return(CityMappers.FromCityToCityDto(city));
        }