// PUT /tbEmpresaFilial/token/ public HttpResponseMessage Put(string token, [FromBody] tbEmpresaFilial param) { tbLogAcessoUsuario log = new tbLogAcessoUsuario(); try { log = Bibliotecas.LogAcaoUsuario.New(token, JsonConvert.SerializeObject(param), "Put"); HttpResponseMessage retorno = new HttpResponseMessage(); if (Permissoes.Autenticado(token)) { GatewayTbEmpresaFilial.Update(token, param); log.codResposta = (int)HttpStatusCode.OK; Bibliotecas.LogAcaoUsuario.Save(log); return(Request.CreateResponse(HttpStatusCode.OK)); } else { log.codResposta = (int)HttpStatusCode.Unauthorized; Bibliotecas.LogAcaoUsuario.Save(log); return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } } catch (Exception e) { log.codResposta = (int)HttpStatusCode.InternalServerError; log.msgErro = e.Message; Bibliotecas.LogAcaoUsuario.Save(log); throw new HttpResponseException(HttpStatusCode.InternalServerError); } }
/// <summary> /// Adiciona nova TbEmpresaFilial /// </summary> /// <param name="param"></param> /// <returns></returns> public static string Add(string token, tbEmpresaFilial param) { try { _db.tbEmpresaFiliais.Add(param); _db.SaveChanges(); return(param.nrCNPJ); } catch (Exception e) { if (e is DbEntityValidationException) { string erro = MensagemErro.getMensagemErro((DbEntityValidationException)e); throw new Exception(erro.Equals("") ? "Falha ao salvar TbEmpresaFilial" : erro); } throw new Exception(e.InnerException == null ? e.Message : e.InnerException.InnerException == null ? e.InnerException.Message : e.InnerException.InnerException.Message); } }
/// <summary> /// Altera tbEmpresaFilial /// </summary> /// <param name="param"></param> /// <returns></returns> public static void Update(string token, tbEmpresaFilial param) { try { tbEmpresaFilial value = _db.tbEmpresaFiliais .Where(e => e.nrCNPJ.Equals(param.nrCNPJ)) .First <tbEmpresaFilial>(); // OBSERVAÇÂO: VERIFICAR SE EXISTE ALTERAÇÃO NO PARAMETROS if (param.nrCNPJ != null && param.nrCNPJ != value.nrCNPJ) { value.nrCNPJ = param.nrCNPJ; } if (param.nrCNPJBase != null && param.nrCNPJBase != value.nrCNPJBase) { value.nrCNPJBase = param.nrCNPJBase; } if (param.nrCNPJSequencia != null && param.nrCNPJSequencia != value.nrCNPJSequencia) { value.nrCNPJSequencia = param.nrCNPJSequencia; } if (param.nrCNPJDigito != null && param.nrCNPJDigito != value.nrCNPJDigito) { value.nrCNPJDigito = param.nrCNPJDigito; } if (param.nmFantasia != null && param.nmFantasia != value.nmFantasia) { value.nmFantasia = param.nmFantasia; } if (param.nmRazaoSocial != null && param.nmRazaoSocial != value.nmRazaoSocial) { value.nmRazaoSocial = param.nmRazaoSocial; } if (param.dsEndereco != null && param.dsEndereco != value.dsEndereco) { value.dsEndereco = param.dsEndereco; } if (param.dsCidade != null && param.dsCidade != value.dsCidade) { value.dsCidade = param.dsCidade; } if (param.sgUF != null && param.sgUF != value.sgUF) { value.sgUF = param.sgUF; } if (param.nrCEP != null && param.nrCEP != value.nrCEP) { value.nrCEP = param.nrCEP; } if (param.nrTelefone != null && param.nrTelefone != value.nrTelefone) { value.nrTelefone = param.nrTelefone; } if (param.dsBairro != null && param.dsBairro != value.dsBairro) { value.dsBairro = param.dsBairro; } if (param.dsEmail != null && param.dsEmail != value.dsEmail) { value.dsEmail = param.dsEmail; } if (param.dtCadastro != null && param.dtCadastro != value.dtCadastro) { value.dtCadastro = param.dtCadastro; } if (param.flAtivo != null && param.flAtivo != value.flAtivo) { value.flAtivo = param.flAtivo; } if (param.cdEmpresaGrupo != null && param.cdEmpresaGrupo != value.cdEmpresaGrupo) { value.cdEmpresaGrupo = param.cdEmpresaGrupo; } if (param.nrFilial != null && param.nrFilial != value.nrFilial) { value.nrFilial = param.nrFilial; } if (param.nrInscEstadual != null && param.nrInscEstadual != value.nrInscEstadual) { value.nrInscEstadual = param.nrInscEstadual; } if (param.token != null && param.token != value.token) { value.token = param.token; } _db.SaveChanges(); } catch (Exception e) { if (e is DbEntityValidationException) { string erro = MensagemErro.getMensagemErro((DbEntityValidationException)e); throw new Exception(erro.Equals("") ? "Falha ao alterar TbEmpresaFilial" : erro); } throw new Exception(e.InnerException == null ? e.Message : e.InnerException.InnerException == null ? e.InnerException.Message : e.InnerException.InnerException.Message); } }