public async Task <IActionResult> CreateCountry([FromBody] CountryAddResource country) { if (country == null) { return(BadRequest()); } var countryModel = _mapper.Map <Country>(country); _countryRepository.AddCountry(countryModel); if (!await _unitOfWork.SaveAsync()) { return(StatusCode(500, "保存数据出错")); } var countryResource = _mapper.Map <CountryResource>(countryModel); return(CreatedAtRoute("GetCountry", new { id = countryModel.Id }, countryResource)); }
public async Task <IActionResult> CreateCountry([FromBody] CountryAddResource country) { if (country == null) { return(BadRequest()); } var countryModel = _mapper.Map <Country>(country); _countryRepository.AddCountry(countryModel); if (!await _unitOfWork.SaveAsync()) { throw new Exception("Error occurred when adding"); } var countryResource = Mapper.Map <CountryResource>(countryModel); return(CreatedAtRoute("GetCountry", new { id = countryModel.Id }, countryResource)); }
public async Task <IActionResult> CreateCountry([FromBody] CountryAddResource country) { if (country == null) { return(BadRequest()); } var countryModel = _mapper.Map <Country>(country); _countryRepository.AddCountry(countryModel); if (!await _unitOfWork.SaveAsync()) { throw new Exception("Error occurred when adding"); } var countryResource = Mapper.Map <CountryResource>(countryModel); var links = CreateLinksForCountry(countryModel.Id); var linkedCountryResource = countryResource.ToDynamic() as IDictionary <string, object>; linkedCountryResource.Add("links", links); return(CreatedAtRoute("GetCountry", new { id = linkedCountryResource["Id"] }, linkedCountryResource)); }