public IActionResult Post([FromBody] CountryRegionDto countryRegionDto) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var countryRegion = Mapper.Map <CountryRegion>(countryRegionDto); if (_countryRegionRepository.CountryRegionExists(countryRegion)) { return(StatusCode(500, "CountryRegion already exists.")); } var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var profile = _accountRepository.GetUserProfile(userId); var createdCountryRegion = _countryRegionRepository.CreateCountryRegion(countryRegion, profile.UserProfileId); if (createdCountryRegion == null) { return(StatusCode(500, "A problem happened while handling your request.")); } var createdCountryRegionToReturn = Mapper.Map <CountryRegionDto>(createdCountryRegion); return(Created(createdCountryRegionToReturn)); } catch (Exception ex) { _logger.LogError($"Failed in Post /CountryRegions: {ex}"); return(StatusCode(500, "A problem happened while handling your request.")); } }
public void Update(CountryRegionDto countryRegionDto) { CountryRegionModels countryRegion = ObjectConverter <CountryRegionDto, CountryRegionModels> .Convert(countryRegionDto); _repository.Update(countryRegion); }
public CountryRegionDto GetDetailById(int id) { CountryRegionModels countryRegion = _repository.GetById(id); CountryRegionDto countryRegionDto = ObjectConverter <CountryRegionModels, CountryRegionDto> .Convert(countryRegion); return(countryRegionDto); }
public override async Task <DataPayLoad> SetCode(DataPayLoad payLoad, IDataServices dataServices) { IHelperDataServices helperDal = DataServices.GetHelperDataServices(); CountryRegionDto dto = payLoad.DataObject as CountryRegionDto; if (dto != null) { string codeId = await helperDal.GetMappedUniqueId <CountryRegionDto, CCAA>(dto); dto.Code = codeId.Substring(0, 2); payLoad.DataObject = dto; } return(payLoad); }