public ApiResponse Create(TipoUsuario tipoUsuario) { ApiResponse resp = this.ValidateTipoUsuario(tipoUsuario); if (resp.Success == false) { return(resp); } else { resp = new ApiResponse(); } try { DAOBase <TipoUsuario> daoA = new DAOBase <TipoUsuario>(); daoA.Insert(tipoUsuario); resp.Success = true; resp.data = tipoUsuario; return(resp); } catch (Exception e) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add(e.Message); return(resp); } }
public ApiResponse Create(Empresa empresa) { ApiResponse resp = this.ValidateEmpresa(empresa); if (resp.Success == false) { return(resp); } else { resp = new ApiResponse(); } try { DAOBase <Empresa> daoA = new DAOBase <Empresa>(); daoA.Insert(empresa); resp.Success = true; resp.data = empresa; return(resp); } catch (Exception e) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add(e.Message); return(resp); } }
public ActionResult <string> GetNFeFromDataBase(string id) { try { DAOBase <NotaFiscal> dao = new DAOBase <NotaFiscal>(); NotaFiscal nf = null; nf = dao.Get(w => w.access_key == id); if (nf != null) { string sTotalValue = nf.total_nota.ToString(); return("Nota: \"" + id + "\"\nValor: " + sTotalValue); } else { throw new Exception("Nota: \"" + id + "\" nao encontrada"); } } catch (Exception e) { Console.WriteLine("Erro: {0}", e); return(e.Message); } }
public ApiResponse Update(int id, TipoUsuario tipoUsuario) { ApiResponse resp = this.ValidateTipoUsuario(tipoUsuario); if (resp.Success == false) { return(resp); } else { resp = new ApiResponse(); } if (id <= 0) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Nivel usuario nao informado"); return(resp); } DAOBase <TipoUsuario> dao = new DAOBase <TipoUsuario>(); TipoUsuario n = dao.GetById(id); if (n == null) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Nivel de usuario: " + id + " informado inexistente"); return(resp); } // atribuicoes de campos n.id_alcada = tipoUsuario.id_alcada; n.s_codigo = tipoUsuario.s_codigo; n.s_descricao = tipoUsuario.s_descricao; try { dao.Update(n); resp.Success = true; resp.data = n; return(resp); } catch (Exception e) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add(e.Message); return(resp); } }
public ApiResponse Update(int id, TipoParticipante tipoParticipante) { ApiResponse resp = new ApiResponse(); if (tipoParticipante == null) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Conteudo vazio"); return(resp); } if (string.IsNullOrEmpty(tipoParticipante.s_descricao) == true) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Descricao nao informada"); return(resp); } DAOBase <TipoParticipante> daoA = new DAOBase <TipoParticipante>(); TipoParticipante a = daoA.GetById(id); if (a == null) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("TipoParticipante: " + tipoParticipante + " informada inexistente"); return(resp); } // atriuicao dos valores a.s_descricao = tipoParticipante.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 Update(int id, Empresa empresa) { ApiResponse resp = this.ValidateEmpresa(empresa); if (resp.Success == false) { return(resp); } else { resp = new ApiResponse(); } if (id <= 0) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Empresa nao informada"); return(resp); } DAOBase <Empresa> dao = new DAOBase <Empresa>(); Empresa n = dao.GetById(id); if (n == null) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Empresa: " + id + " informada inexistente"); return(resp); } // campos empresa.id = id; try { dao.Update(empresa); resp.Success = true; resp.data = empresa; return(resp); } catch (Exception e) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add(e.Message); return(resp); } }
public ApiResponse Update(int id, Alcada alcada) { ApiResponse resp = new ApiResponse(); if (alcada == null) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Conteudo vazio"); return(resp); } if (string.IsNullOrEmpty(alcada.s_descricao) == true) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Descricao nao informada"); return(resp); } DAOBase <Alcada> daoA = new DAOBase <Alcada>(); Alcada a = daoA.GetById(id); if (a == null) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Alcada: " + alcada + " informada inexistente"); return(resp); } // atriuicao dos valores a.s_descricao = alcada.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 void InsertNFeDataBase(Entity.ReceivedResponse respAPI) { int i = 0; try { Console.WriteLine("Inserindo notas na base de dados..."); //Para cada nota devolvida. //Obtem a chave de acesso e o valor total da nota. //Sava a nota no banco de dados. foreach (Entity.ReceivedResponse.Datum item in respAPI.data) { i += 1; //Obtem a chave de acesso. string accessKey = item.access_key; try { //Obtem o valor total da nota. double valorNF = GetNFTotalValue(item.xml); Console.WriteLine("AccessKey(" + i + "):" + accessKey); Console.WriteLine("NFe Value: " + valorNF); //Atribui os valores ao objeto nota fiscal. NotaFiscal nf = new NotaFiscal(); nf.access_key = accessKey; nf.total_nota = valorNF; //Insere a nota(chave e valor) na base de dados. DAOBase <NotaFiscal> dao = new DAOBase <NotaFiscal>(); dao.Insert(nf); } catch (Exception e) { Console.WriteLine("AccessKey(" + i + "):" + accessKey); Console.WriteLine("Error: " + e.Message); } } } catch (Exception e) { Console.WriteLine("Erro ao inserir nota na base de dados: {0}", e); throw; } }
public ApiResponse Get(int id) { ApiResponse resp = new ApiResponse(); try { DAOBase <Alcada> daoA = new DAOBase <Alcada>(); resp.data = daoA.GetById(id); 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 GetAll() { ApiResponse resp = new ApiResponse(); try { DAOBase <TipoUsuario> daoA = new DAOBase <TipoUsuario>(); resp.data = daoA.GetAll(); 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 Delete(int id) { ApiResponse resp = new ApiResponse(); if (id <= 0) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Alcada nao informada"); return(resp); } DAOBase <Alcada> daoAlacada = new DAOBase <Alcada>(); Alcada a = daoAlacada.GetById(id); if (a == null) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Alcada: " + 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(TipoParticipante tipoParticipante) { ApiResponse resp = new ApiResponse(); if (tipoParticipante == null) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Conteudo vazio"); return(resp); } if (string.IsNullOrEmpty(tipoParticipante.s_descricao) == true) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Descricao nao informada"); return(resp); } try { DAOBase <TipoParticipante> daoA = new DAOBase <TipoParticipante>(); daoA.Insert(tipoParticipante); resp.Success = true; resp.data = tipoParticipante; return(resp); } catch (Exception e) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add(e.Message); return(resp); } }
public ApiResponse Create(Alcada alcada) { ApiResponse resp = new ApiResponse(); if (alcada == null) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Conteudo vazio"); return(resp); } if (string.IsNullOrEmpty(alcada.s_descricao) == true) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Descricao nao informada"); return(resp); } try { DAOBase <Alcada> daoA = new DAOBase <Alcada>(); daoA.Insert(alcada); resp.Success = true; resp.data = alcada; 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("Nivel usuario nao informado"); return(resp); } DAOBase <TipoUsuario> dao = new DAOBase <TipoUsuario>(); TipoUsuario n = dao.GetById(id); if (n == null) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Nivel de usuario: " + id + " informado inexistente"); return(resp); } try { dao.Delete(n); resp.Success = true; return(resp); } catch (Exception e) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add(e.Message); return(resp); } }
public CategoryService() { dao = new DAOBase(); }
public SysDictService() { dao = new DAOBase(); }
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); }
private ApiResponse ValidateTipoUsuario(TipoUsuario tipoUsuario) { ApiResponse resp = new ApiResponse(); if (tipoUsuario == null) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Conteudo vazio"); return(resp); } if (string.IsNullOrEmpty(tipoUsuario.s_codigo) == true) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Codigo nao informada"); return(resp); } if (tipoUsuario.s_codigo.Length > 20) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Codigo informado possui mais que 20 caracters"); return(resp); } if (string.IsNullOrEmpty(tipoUsuario.s_descricao) == true) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Descricao nao informada"); return(resp); } if (tipoUsuario.s_descricao.Length > 200) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Descricao informado possui mais que 200 caracters"); return(resp); } if (tipoUsuario.id_alcada <= 0) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Alcada nao informada"); return(resp); } DAOBase <Alcada> daoAlacada = new DAOBase <Alcada>(); if (daoAlacada.GetById(tipoUsuario.id_alcada) == null) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Alcada: " + tipoUsuario.id_alcada + " informada inexistente"); return(resp); } resp.Success = true; return(resp); }
private ApiResponse ValidateUsuario(Usuario usuario) { ApiResponse resp = new ApiResponse(); if (usuario == null) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Conteudo vazio"); return(resp); } if (string.IsNullOrEmpty(usuario.s_nome) == true) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Nome nao informada"); return(resp); } if (usuario.s_nome.Length > 100) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Nome informado possui mais que 100 caracters"); return(resp); } if (usuario.id_nivel_usuario <= 0) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Nivel usuario nao informado"); return(resp); } DAOBase <NivelUsuario> dao = new DAOBase <NivelUsuario>(); if (dao.GetById(usuario.id_nivel_usuario) == null) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Nivel Usuário: " + usuario.id_nivel_usuario + " informado inexistente"); return(resp); } if (usuario.id_tipo_usuario <= 0) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Tipo usuario nao informado"); return(resp); } DAOBase <TipoUsuario> daoTU = new DAOBase <TipoUsuario>(); if (daoTU.GetById(usuario.id_tipo_usuario) == null) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Tipo Usuário: " + usuario.id_tipo_usuario + " informado inexistente"); return(resp); } if (string.IsNullOrEmpty(usuario.s_emailhost) == false) { if (usuario.s_emailhost.Length > 100) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Emailhost informado possui mais que 100 caracteres"); return(resp); } } // if (string.IsNullOrEmpty(usuario.s_emailnome) == false) { if (usuario.s_emailnome.Length > 100) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Emailnome informado possui mais que 100 caracteres"); return(resp); } } // if (string.IsNullOrEmpty(usuario.s_emaillogin) == false) { if (usuario.s_emaillogin.Length > 100) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Email login informado possui mais que 100 caracteres"); return(resp); } } // if (string.IsNullOrEmpty(usuario.s_emailsenha) == false) { if (usuario.s_emailsenha.Length > 100) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Email senha informado possui mais que 100 caracteres"); return(resp); } } // if (string.IsNullOrEmpty(usuario.s_cpf_cnpj) == false) { if (usuario.s_cpf_cnpj.Length > 30) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("CPF/CNPJ informado possui mais que 30 caracteres"); return(resp); } } // if (usuario.id_grupo_participante != null) { DAOBase <GrupoParticipante> daoGP = new DAOBase <GrupoParticipante>(); if (daoGP.GetById((int)usuario.id_grupo_participante) == null) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Grupo Participante: " + usuario.id_grupo_participante + " informado inexistente"); return(resp); } } if (usuario.id_tipo_participante != null) { DAOBase <GrupoParticipante> daoGP = new DAOBase <GrupoParticipante>(); if (daoGP.GetById((int)usuario.id_tipo_participante) == null) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Tipo Participante: " + usuario.id_tipo_participante + " informado inexistente"); return(resp); } } resp.Success = true; return(resp); }
public ApiResponse Update(int id, Usuario usuario) { ApiResponse resp = this.ValidateUsuario(usuario); if (resp.Success == false) { return(resp); } else { resp = new ApiResponse(); } if (id <= 0) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Usuario nao informado"); return(resp); } DAOBase <Usuario> dao = new DAOBase <Usuario>(); Usuario n = dao.GetById(id); if (n == null) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add("Nivel de usuario: " + id + " informado inexistente"); return(resp); } // atribuicoes de campos n.b_emailseg = usuario.b_emailseg; n.b_email_ssl = usuario.b_email_ssl; n.id_nivel_usuario = usuario.id_nivel_usuario; n.id_tipo_usuario = usuario.id_tipo_usuario; n.n_emailporta = usuario.n_emailporta; n.s_emailcopia = usuario.s_emailcopia; n.s_emailhost = usuario.s_emailhost; n.s_emaillogin = usuario.s_emaillogin; n.s_emailnome = usuario.s_emailnome; n.s_emailsenha = usuario.s_emailsenha; n.s_nome = usuario.s_nome; n.b_usuario_pf = usuario.b_usuario_pf; n.s_cpf_cnpj = usuario.s_cpf_cnpj; n.id_tipo_participante = usuario.id_tipo_participante; n.id_grupo_participante = usuario.id_grupo_participante; try { dao.Update(n); resp.Success = true; resp.data = n; return(resp); } catch (Exception e) { resp.Success = false; resp.ErrorList = new List <string>(); resp.ErrorList.Add(e.Message); return(resp); } }