コード例 #1
0
        public IActionResult PutCountry(Guid id, CountryPutPostDto countryDto)
        {
            var country = _countryRepository.GetById(id);

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

            _mapper.Map(countryDto, country);

            try
            {
                _countryRepository.Update(country);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CountryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok("Updated"));
        }
コード例 #2
0
        public ActionResult <CountryPutPostDto> PostCountry(CountryPutPostDto countryDto)
        {
            var country = _mapper.Map <Country>(countryDto);

            _countryRepository.Insert(country);

            return(CreatedAtAction("GetCountry", new { id = country.Id }, _mapper.Map <CountryGetDto>(country)));
        }