public override Empresa Delete(params object[] key)
        {
            if (_db.Negociacoes.Any(x => x.EmpresaId == (int)key[0]))
            {
                throw new Exception("Existem negociações cadastradas para essa empresa!");
            }
            if (_db.Litigios.Any(x => x.EmpresaId == (int)key[0]))
            {
                throw new Exception("Existem litígios cadastrados para essa empresa!");
            }

            _arquivosService.DeleteFiles(DependencyFileType.Empresa, (int)key[0]);
            _contatosEmpresaService.Query(x => x.EmpresaId == (int)key[0])
            .ToList().ForEach(x => _contatosService.Delete(x.ContatoId));
            return(base.Delete(key));
        }
Esempio n. 2
0
        public override SindicatoPatronal Delete(params object[] key)
        {
            if (_db.Empresas.Any(x => x.SindicatoPatronalId == (int)key[0]))
            {
                throw new Exception("Existem empresas relacionadas à esse sindicato!");
            }
            if (_db.Negociacoes.Any(x => x.SindicatoPatronalId == (int)key[0]))
            {
                throw new Exception("Existem negociações relacionadas à esse sindicato!");
            }
            if (_db.Litigios.Any(x => x.PatronalId == (int)key[0]))
            {
                throw new Exception("Existem litígios relacionados à esse sindicato!");
            }

            /*if (_db.PlanosAcao.Any(x => x.PatronalId == (int)key[0]))
             *  throw new Exception("Existem planos de ações relacionados à esse sindicato!");*/

            _arquivosService.DeleteFiles(DependencyFileType.SindicatoPatronal, (int)key[0]);
            _contatosSindService.Query(x => x.SindicatoPatronalId == (int)key[0])
            .ToList().ForEach(x => _contatosService.Delete(x.ContatoId));
            return(base.Delete(key));
        }