public ServiceResult <MunicipioDtoOut> GetMunicipioByMunicipioId(int municipioId)
        {
            try
            {
                if (!municipioValidationService.IsExistingMunicipioId(municipioId))
                {
                    throw new ValidationException(MunicipioMessageConstants.NotExistingMunicipioId);
                }

                var municipio = masterRepository.Municipio.FindByCondition(m =>
                                                                           m.MunicipioId == municipioId).FirstOrDefault();

                var municipioDto = mapper.Map <MunicipioDtoOut>(municipio);

                return(ServiceResult <MunicipioDtoOut> .ResultOk(municipioDto));
            }
            catch (ValidationException e)
            {
                return(ServiceResult <MunicipioDtoOut> .ResultFailed(ResponseCode.Warning, e.Message));
            }
            catch (Exception e)
            {
                return(ServiceResult <MunicipioDtoOut> .ResultFailed(ResponseCode.Error, e.Message));
            }
        }
Exemple #2
0
        public ServiceResult <int> CreateDistritoMunicipal(DistritoMunicipalDtoIn distritoMunicipalDto)
        {
            try
            {
                if (generalValidationService.IsEmptyText(distritoMunicipalDto.Nombre))
                {
                    throw new ValidationException(DistritoMunicipalMessageConstants.EmptyDistritoMunicipalName);
                }

                if (distritoMunicipalValidationService.IsExistingDistritoMunicipalName(distritoMunicipalDto.Nombre))
                {
                    throw new ValidationException(DistritoMunicipalMessageConstants.ExistingDistritoMunicipalName);
                }

                if (!municipioValidationService.IsExistingMunicipioId(distritoMunicipalDto.MunicipioId))
                {
                    throw new ValidationException(MunicipioMessageConstants.NotExistingMunicipioId);
                }

                distritoMunicipalDto.Nombre = generalValidationService.GetRewrittenTextFirstCapitalLetter(
                    distritoMunicipalDto.Nombre);

                var distritoMunicipal = mapper.Map <DistritoMunicipal>(distritoMunicipalDto);

                masterRepository.DistritoMunicipal.Create(distritoMunicipal);
                masterRepository.Save();

                distritoMunicipal = masterRepository.DistritoMunicipal.FindByCondition(d =>
                                                                                       d.Nombre == distritoMunicipalDto.Nombre).FirstOrDefault();
                return(ServiceResult <int> .ResultOk(distritoMunicipal.DistritoMunicipalId));
            }
            catch (ValidationException e)
            {
                return(ServiceResult <int> .ResultFailed(ResponseCode.Warning, e.Message));
            }
            catch (Exception e)
            {
                return(ServiceResult <int> .ResultFailed(ResponseCode.Error, e.Message));
            }
        }
Exemple #3
0
        public ServiceResult <IEnumerable <EntidadMunicipalDtoOut> > GetAllEntidadesMunicipalesByMunicipioId(int municipioId)
        {
            try
            {
                if (!municipioValidationService.IsExistingMunicipioId(municipioId))
                {
                    throw new ValidationException(MunicipioMessageConstants.NotExistingMunicipioId);
                }

                var listEntidadesMunicipales = masterRepository.EntidadMunicipal.FindByCondition(e =>
                                                                                                 e.MunicipioId == municipioId);

                if (listEntidadesMunicipales.Count() == 0)
                {
                    throw new ValidationException(EntidadMunicipalMessageConstants.NotExistingEntidadMunicipalInMunicipio);
                }

                var listEntidadesMunicipalesDto = new List <EntidadMunicipalDtoOut>();

                foreach (var entidadMunicipal in listEntidadesMunicipales)
                {
                    var entidadMunicipalDto = MapToDto(entidadMunicipal);

                    listEntidadesMunicipalesDto.Add(entidadMunicipalDto);
                }

                return(ServiceResult <IEnumerable <EntidadMunicipalDtoOut> > .ResultOk(listEntidadesMunicipalesDto));
            }
            catch (ValidationException e)
            {
                return(ServiceResult <IEnumerable <EntidadMunicipalDtoOut> > .ResultFailed(ResponseCode.Warning, e.Message));
            }
            catch (Exception e)
            {
                return(ServiceResult <IEnumerable <EntidadMunicipalDtoOut> > .ResultFailed(ResponseCode.Error, e.Message));
            }
        }