public ApiResponse Update(int id, TipoEmpresaPai tipoEmpresaPai)
        {
            ApiResponse resp = new ApiResponse();

            if (tipoEmpresaPai == null)
            {
                resp.Success   = false;
                resp.ErrorList = new List <string>();
                resp.ErrorList.Add("Conteudo vazio");
                return(resp);
            }

            if (string.IsNullOrEmpty(tipoEmpresaPai.s_descricao) == true)
            {
                resp.Success   = false;
                resp.ErrorList = new List <string>();
                resp.ErrorList.Add("Descricao nao informada");
                return(resp);
            }

            DAOBase <TipoEmpresaPai> daoA = new DAOBase <TipoEmpresaPai>();
            TipoEmpresaPai           a    = daoA.GetById(id);

            if (a == null)
            {
                resp.Success   = false;
                resp.ErrorList = new List <string>();
                resp.ErrorList.Add("TipoEmpresaPai: " + tipoEmpresaPai + " informada inexistente");
                return(resp);
            }

            // atriuicao dos valores
            a.s_descricao = tipoEmpresaPai.s_descricao;

            try
            {
                daoA.Update(a);

                resp.Success = true;
                resp.data    = a;

                return(resp);
            }
            catch (Exception e)
            {
                resp.Success   = false;
                resp.ErrorList = new List <string>();
                resp.ErrorList.Add(e.Message);
                return(resp);
            }
        }
        public ApiResponse Delete(int id)
        {
            ApiResponse resp = new ApiResponse();

            if (id <= 0)
            {
                resp.Success   = false;
                resp.ErrorList = new List <string>();
                resp.ErrorList.Add("TipoEmpresaPai nao informada");
                return(resp);
            }

            DAOBase <TipoEmpresaPai> daoAlacada = new DAOBase <TipoEmpresaPai>();
            TipoEmpresaPai           a          = daoAlacada.GetById(id);

            if (a == null)
            {
                resp.Success   = false;
                resp.ErrorList = new List <string>();
                resp.ErrorList.Add("TipoEmpresaPai: " + id + " informada inexistente");
                return(resp);
            }

            try
            {
                daoAlacada.Delete(a);
                resp.Success = true;

                return(resp);
            }
            catch (Exception e)
            {
                resp.Success   = false;
                resp.ErrorList = new List <string>();
                resp.ErrorList.Add(e.Message);
                return(resp);
            }
        }
        public ApiResponse Create(TipoEmpresaPai tipoEmpresaPai)
        {
            ApiResponse resp = new ApiResponse();

            if (tipoEmpresaPai == null)
            {
                resp.Success   = false;
                resp.ErrorList = new List <string>();
                resp.ErrorList.Add("Conteudo vazio");
                return(resp);
            }

            if (string.IsNullOrEmpty(tipoEmpresaPai.s_descricao) == true)
            {
                resp.Success   = false;
                resp.ErrorList = new List <string>();
                resp.ErrorList.Add("Descricao nao informada");
                return(resp);
            }

            try
            {
                DAOBase <TipoEmpresaPai> daoA = new DAOBase <TipoEmpresaPai>();
                daoA.Insert(tipoEmpresaPai);

                resp.Success = true;
                resp.data    = tipoEmpresaPai;

                return(resp);
            }
            catch (Exception e)
            {
                resp.Success   = false;
                resp.ErrorList = new List <string>();
                resp.ErrorList.Add(e.Message);
                return(resp);
            }
        }
예제 #4
0
        private ApiResponse ValidateEmpresa(Empresa empresa)
        {
            ApiResponse resp = new ApiResponse();

            if (empresa == null)
            {
                resp.Success   = false;
                resp.ErrorList = new List <string>();
                resp.ErrorList.Add("Conteudo vazio");
                return(resp);
            }

            if (string.IsNullOrEmpty(empresa.s_nomefantasia))
            {
                resp.Success   = false;
                resp.ErrorList = new List <string>();
                resp.ErrorList.Add("Nome fantasia nao informado");
                return(resp);
            }

            if (string.IsNullOrEmpty(empresa.s_cnpj))
            {
                resp.Success   = false;
                resp.ErrorList = new List <string>();
                resp.ErrorList.Add("CNPJ nao informado");
                return(resp);
            }

            if (empresa.id_empresa_pai != null)
            {
                if ((int)empresa.id_empresa_pai <= 0)
                {
                    resp.Success   = false;
                    resp.ErrorList = new List <string>();
                    resp.ErrorList.Add("Empresa pai invalida");
                    return(resp);
                }

                DAOBase <Empresa> dao = new DAOBase <Empresa>();
                Empresa           n   = dao.GetById((int)empresa.id_empresa_pai);
                if (n == null)
                {
                    resp.Success   = false;
                    resp.ErrorList = new List <string>();
                    resp.ErrorList.Add("Empresa pai: " + empresa.id_empresa_pai + " informado inexistente");
                    return(resp);
                }
            }

            if (empresa.id_tipo_empresa_pai != null)
            {
                if ((int)empresa.id_tipo_empresa_pai <= 0)
                {
                    resp.Success   = false;
                    resp.ErrorList = new List <string>();
                    resp.ErrorList.Add("Empresa pai invalida");
                    return(resp);
                }

                DAOBase <TipoEmpresaPai> dao = new DAOBase <TipoEmpresaPai>();
                TipoEmpresaPai           n   = dao.GetById((int)empresa.id_tipo_empresa_pai);
                if (n == null)
                {
                    resp.Success   = false;
                    resp.ErrorList = new List <string>();
                    resp.ErrorList.Add("Tipo empresa pai: " + empresa.id_tipo_empresa_pai + " informado inexistente");
                    return(resp);
                }
            }

            if (empresa.id_usuario_participante != null)
            {
                if ((int)empresa.id_usuario_participante <= 0)
                {
                    resp.Success   = false;
                    resp.ErrorList = new List <string>();
                    resp.ErrorList.Add("Participante invalido");
                    return(resp);
                }

                DAOBase <Usuario> dao = new DAOBase <Usuario>();
                Usuario           n   = dao.GetById((int)empresa.id_usuario_participante);
                if (n == null)
                {
                    resp.Success   = false;
                    resp.ErrorList = new List <string>();
                    resp.ErrorList.Add("Participante: " + empresa.id_usuario_participante + " informado inexistente");
                    return(resp);
                }
                else
                {
                    DAOBase <TipoUsuario> daoTU   = new DAOBase <TipoUsuario>();
                    TipoUsuario           tuParti = daoTU.Get(w => w.s_codigo == "PAR");
                    if (tuParti != null)
                    {
                        if (n.id_tipo_usuario != tuParti.id)
                        {
                            resp.Success   = false;
                            resp.ErrorList = new List <string>();
                            resp.ErrorList.Add("Usuario informado não é um participante");
                            return(resp);
                        }
                    }
                    else
                    {
                        resp.Success   = false;
                        resp.ErrorList = new List <string>();
                        resp.ErrorList.Add("Entidade Participante não encontrado no sistema");
                        return(resp);
                    }
                }
            }

            resp.Success = true;
            return(resp);
        }