// PUT api/countries/1
        public async Task <CountryDto> PutCountry(int id, CountryRequestModel requestModel)
        {
            Country country = await _countryService.GetByIdAsync(id);

            if (country == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            Country updatedCountry = requestModel.ToCountry(country);
            await _countryService.UpdateAsync(updatedCountry);

            CountryDto countryDto = _mapper.Map <Country, CountryDto>(country);

            return(countryDto);
        }
Ejemplo n.º 2
0
        // PUT api/countries/1
        public async Task <CountryDto> PutCountry(int id, CountryRequestModel requestModel)
        {
            Country country = await _countryService.GetByIdAsync(id);

            if (country == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            // NOTE: AutoMapper goes bananas over this as
            // EF creates the poroxy class for Country
            // Country updatedCountry = Mapper.Map<CountryRequestModel, Country>(requestModel, country);

            Country updatedCountry = requestModel.ToCountry(country);
            await _countryService.UpdateAsync(country);

            CountryDto countryDto = _mapper.Map <Country, CountryDto>(country);

            return(countryDto);
        }
        // PUT api/countries/1
        public CountryDto PutCountry(int id, CountryRequestModel requestModel)
        {
            Country country = _countryRepository.GetSingle(id);

            if (country == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            // NOTE: AutoMapper goes bananas over this as
            // EF creates the poroxy class for Country
            // Country updatedCountry = Mapper.Map<CountryRequestModel, Country>(requestModel, country);

            Country updatedCountry = requestModel.ToCountry(country);

            _countryRepository.Edit(updatedCountry);
            _countryRepository.Save();

            CountryDto countryDto = _mapper.Map <Country, CountryDto>(country);

            return(countryDto);
        }