public async Task <IActionResult> CreateCountry([FromBody] CountryDetailsDto countryResource) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (_countryRepo.CheckCountryCode(countryResource.Code1, countryResource.Code1)) { ModelState.AddModelError("Error", "The Country with this Code already exists."); return(BadRequest(ModelState)); } var country = _mapper.Map <CountryDetailsDto, Country>(countryResource); country.Deleted = false; country.Protected = false; _countryRepo.Add(country); await _unitOfWork.CompleteAsync(); country = await _countryRepo.GetCountry(country.Id); var result = _mapper.Map <Country, CountryDetailsDto>(country); return(Ok(result)); } catch (Exception ex) { ModelState.AddModelError("Error", "An error occured while performing this operation."); return(BadRequest(ModelState)); } }