Exemplo n.º 1
0
        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."));
            }
        }
Exemplo n.º 2
0
        public void Update(CountryRegionDto countryRegionDto)
        {
            CountryRegionModels countryRegion =
                ObjectConverter <CountryRegionDto, CountryRegionModels> .Convert(countryRegionDto);

            _repository.Update(countryRegion);
        }
Exemplo n.º 3
0
        public CountryRegionDto GetDetailById(int id)
        {
            CountryRegionModels countryRegion    = _repository.GetById(id);
            CountryRegionDto    countryRegionDto =
                ObjectConverter <CountryRegionModels, CountryRegionDto> .Convert(countryRegion);

            return(countryRegionDto);
        }
Exemplo n.º 4
0
        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);
        }