示例#1
0
        private void SalvarSocio(Socio socio)
        {
            var validator = EntityValidatorFactory.CreateValidator();

            if (!validator.IsValid(socio))
            {
                throw new AppException(validator.GetInvalidMessages <Socio>(socio));
            }

            var specExisteSocio = SocioSpecification.ConsultaTexto(socio.Nome);

            if (_socioRepository.AllMatching(specExisteSocio).Any())
            {
                throw new AppException("Já existe um sócio cadastrado com este nome.");
            }


            if (JaExisteCpf(socio.Cpf, socio.EntrevistaId, socio.Id))
            {
                throw new AppException("Já existe um sócio cadastrado com este CPF.");
            }

            if (socio.Administrador && socio.Assina)
            {
                bool x = JaExisteAdministrador(socio.EntrevistaId);
                bool y = JaExisteAssinaNaReceita(socio.EntrevistaId);

                if (!x && y)
                {
                    throw new AppException("Já existe um sócio assinando na receita.");
                }
                else if (x && !y)
                {
                    throw new AppException("Já existe um sócio administrador.");
                }
            }

            if (socio.Administrador)
            {
                if (JaExisteAdministrador(socio.EntrevistaId))
                {
                    throw new AppException("Já existe um sócio administrador.");
                }
            }
            if (socio.Assina)
            {
                if (JaExisteAssinaNaReceita(socio.EntrevistaId))
                {
                    throw new AppException("Já existe um sócio assinando na receita.");
                }
            }

            _socioRepository.Add(socio);
            _socioRepository.Commit();
        }
示例#2
0
 public long CountSocios(string texto)
 {
     try
     {
         var spec = SocioSpecification.ConsultaTexto(texto);
         return(_socioRepository.Count(spec));
     }
     catch (Exception ex)
     {
         throw ManipuladorDeExcecao.TrateExcecao(ex);
     }
 }
示例#3
0
        public List <SocioListDTO> FindSocios <KProperty>(string texto, Expression <Func <Socio, KProperty> > orderByExpression, bool ascending, int pageIndex, int pageCount)
        {
            try
            {
                var          spec   = SocioSpecification.ConsultaTexto(texto);
                List <Socio> Socios = _socioRepository.GetPaged <KProperty>(pageIndex, pageCount, spec, orderByExpression, ascending).ToList();

                var adapter = TypeAdapterFactory.CreateAdapter();
                return(adapter.Adapt <List <Socio>, List <SocioListDTO> >(Socios));
            }
            catch (Exception ex)
            {
                throw ManipuladorDeExcecao.TrateExcecao(ex);
            }
        }
示例#4
0
        private void AlterarSocio(Socio persistido, Socio corrente)
        {
            var validator = EntityValidatorFactory.CreateValidator();

            if (!validator.IsValid(corrente))
            {
                throw new AppException(validator.GetInvalidMessages <Socio>(corrente));
            }

            var specExisteSocio = SocioSpecification.ConsultaTexto(corrente.Nome);

            if (_socioRepository.AllMatching(specExisteSocio).Where(c => c.Id != persistido.Id).Any())
            {
                throw new AppException("Já existe um sócio cadastrado com este nome.");
            }

            if (JaExisteCpf(persistido.Cpf, persistido.EntrevistaId, persistido.Id))
            {
                throw new AppException("Já existe um sócio cadastrado com este CPF.");
            }

            _socioRepository.Merge(persistido, corrente);
            _socioRepository.Commit();
        }
示例#5
0
        public SocioDTO FindSocio(string nomeSocio)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(nomeSocio))
                {
                    throw new AppException("Informe o nome de sócio.");
                }

                var spec  = SocioSpecification.ConsultaTexto(nomeSocio);
                var Socio = _socioRepository.AllMatching(spec).SingleOrDefault();
                if (Socio == null)
                {
                    throw new AppException("Sócio não encontrado.");
                }

                var adapter = TypeAdapterFactory.CreateAdapter();
                return(adapter.Adapt <Socio, SocioDTO>(Socio));
            }
            catch (Exception ex)
            {
                throw ManipuladorDeExcecao.TrateExcecao(ex);
            }
        }