public Retorno IncluirValor(TabelaPreco entity) { try { CommandSQL = new StringBuilder(); CommandSQL.AppendLine("INSERT INTO TB_TABELA_PRECO_VALORES( "); CommandSQL.AppendLine("IMPOSTO, "); CommandSQL.AppendLine("LUCRO, "); CommandSQL.AppendLine("DATA_INICIO, "); CommandSQL.AppendLine("CODIGO_TABELA_PRECO) "); CommandSQL.AppendLine("VALUES ("); CommandSQL.AppendLine("@IMPOSTO, "); CommandSQL.AppendLine("@LUCRO, "); CommandSQL.AppendLine("@DATA_INICIO, "); CommandSQL.AppendLine("@CODIGO_TABELA_PRECO) "); Command = CriaComandoSQL(CommandSQL.ToString()); Command.Parameters.AddWithValue("@IMPOSTO", entity.Imposto); Command.Parameters.AddWithValue("@LUCRO", entity.Lucro); Command.Parameters.AddWithValue("@DATA_INICIO", DateTime.Now); Command.Parameters.AddWithValue("@CODIGO_TABELA_PRECO", entity.Codigo); Abrir(); Command.ExecuteNonQuery(); return(new Retorno(true, String.Format(Mensagens.MSG_02, "Salvo"))); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> PutTabelaPreco([FromRoute] int id, [FromBody] TabelaPreco tabelaPreco) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tabelaPreco.CdTabelaPreco) { return(BadRequest()); } tabelaPreco.DtAlteracao = DateTime.Now; _context.Entry(tabelaPreco).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TabelaPrecoExists(id)) { return(NotFound()); } else { throw; } } return(Ok(tabelaPreco)); }
public ActionResult DeleteConfirmed(int id) { TabelaPreco tabelaPreco = tabelaprecoregras.buscarporID(id); tabelaprecoregras.Remover(tabelaPreco); return(RedirectToAction("Index")); }
public async Task <IActionResult> PostTabelaPreco([FromBody] TabelaPreco tabelaPreco) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } tabelaPreco.DtRegistro = DateTime.Now; _context.TabelaPreco.Add(tabelaPreco); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (TabelaPrecoExists(tabelaPreco.CdTabelaPreco)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetTabelaPreco", new { id = tabelaPreco.CdTabelaPreco }, tabelaPreco)); }
public Retorno Consultar(TabelaPreco Entity) { try { TabelaPreco TabelaPreco = new TabelaPreco(); CommandSQL = new StringBuilder(); CommandSQL.AppendLine("SELECT "); CommandSQL.AppendLine("T.CODIGO, "); CommandSQL.AppendLine("T.DESCRICAO, "); CommandSQL.AppendLine("T.ESPECIAL, "); CommandSQL.AppendLine("TV.IMPOSTO, "); CommandSQL.AppendLine("TV.LUCRO "); CommandSQL.AppendLine("FROM TB_TABELA_PRECO AS T "); CommandSQL.AppendLine("LEFT JOIN TB_TABELA_PRECO_VALORES TV ON TV.CODIGO_TABELA_PRECO = T.CODIGO "); CommandSQL.AppendLine("AND T.DATA BETWEEN TV.DATA_INICIO AND IFNULL(TV.DATA_FIM, '9999-12-31 23:59:59.997') "); CommandSQL.AppendLine("WHERE T.CODIGO = @CODIGO "); Command = CriaComandoSQL(CommandSQL.ToString()); Abrir(); Command.Parameters.AddWithValue("@CODIGO", Entity.Codigo); Reader = Command.ExecuteReader(); while (Reader.Read()) { TabelaPreco = FillEntity(Reader); } return(new Retorno(TabelaPreco)); } catch (Exception ex) { throw ex; } finally { Fechar(); } }
public Retorno VerificarExistencia(TabelaPreco Entity) { try { CommandSQL = new StringBuilder(); CommandSQL.AppendLine("SELECT 1 FROM TB_TABELA_PRECO "); CommandSQL.AppendLine("WHERE TB_TABELA_PRECO.DESCRICAO = @DESCRICAO "); CommandSQL.AppendLine("AND TB_TABELA_PRECO.CODIGO <> @CODIGO "); Command = CriaComandoSQL(CommandSQL.ToString()); Abrir(); Command.Parameters.AddWithValue("@DESCRICAO", Entity.Descricao); Command.Parameters.AddWithValue("@CODIGO", Entity.Codigo); Reader = Command.ExecuteReader(); while (Reader.Read()) { return(new Retorno(false, String.Format(Mensagens.MSG_04, "TabelaPreco", "Descricao"))); } return(new Retorno(true)); } catch (Exception ex) { throw ex; } finally { Fechar(); } }
public Retorno Excluir(TabelaPreco Entity) { try { CommandSQL = new StringBuilder(); CommandSQL.AppendLine("DELETE FROM TB_TABELA_PRECO WHERE CODIGO = @CODIGO "); Command = CriaComandoSQL(CommandSQL.ToString()); Command.Parameters.AddWithValue("@CODIGO", Entity.Codigo); Abrir(); Command.ExecuteNonQuery(); return(new Retorno(true, String.Format(Mensagens.MSG_02, "Excluido "))); } catch (Exception ex) { if (((MySqlException)ex).Number == 1451) { if (((MySqlException)ex).Number == 1451) { CommandSQL = new StringBuilder(); CommandSQL.AppendLine("UPDATE TB_TABELA_PRECO SET ATIVO = 0 WHERE CODIGO = @CODIGO"); Command = CriaComandoSQL(CommandSQL.ToString()); Command.Parameters.AddWithValue("@CODIGO", Entity.Codigo); Abrir(); Command.ExecuteNonQuery(); } else { throw; } } } finally { Fechar(); } return(new Retorno(true, String.Format(Mensagens.MSG_02, "Excluido "))); }
public Retorno Pesquisar(TabelaPreco Entity, int Pagina, int QntPagina) { try { List <TabelaPreco> TabelaPrecos = new List <TabelaPreco>(); int Limite = (Pagina - 1) * QntPagina; CommandSQL = new StringBuilder(); CommandSQL.AppendLine("SELECT "); CommandSQL.AppendLine("TB_TABELA_PRECO.CODIGO, "); CommandSQL.AppendLine("TB_TABELA_PRECO.DESCRICAO, "); CommandSQL.AppendLine("TB_TABELA_PRECO.IMPOSTO, "); CommandSQL.AppendLine("TB_TABELA_PRECO.LUCRO, "); CommandSQL.AppendLine("TB_TABELA_PRECO.DATA_INICIO, "); CommandSQL.AppendLine("TB_TABELA_PRECO.DATA_FIM "); CommandSQL.AppendLine("FROM TB_TABELA_PRECO "); CommandSQL.AppendLine("WHERE (TB_TABELA_PRECO.DESCRICAO LIKE '%" + Entity.Descricao + "%' )"); CommandSQL.AppendLine("LIMIT @QNT_PAGINA OFFSET @LIMITE"); Command = CriaComandoSQL(CommandSQL.ToString()); Abrir(); Command.Parameters.AddWithValue("@QNT_PAGINA", QntPagina); Command.Parameters.AddWithValue("@LIMITE", Limite); Reader = Command.ExecuteReader(); while (Reader.Read()) { TabelaPrecos.Add(FillEntity(Reader)); } return(new Retorno(TabelaPrecos)); } catch (Exception ex) { throw ex; } finally { Fechar(); } }
public ActionResult Create([Bind(Include = "ID,EmpresaID,Descricao")] TabelaPreco tabela) { ViewBag.UsuarioLogado = Utils.User.GetCookieUsuarioLogado(Request, Session); if (!string.IsNullOrEmpty(ViewBag.UsuarioLogado)) { Utils.User.UsuarioLogado usuariologado = Utils.User.GetDadosUsuarioLogado(ViewBag.UsuarioLogado); ViewBag.ModuloFinanceiro = usuariologado.moduloFinanceiro; ViewBag.RuleAdmin = usuariologado.admin; ViewBag.RuleFinanceiro = usuariologado.RuleFinanceiro; ViewBag.RuleMovimentacao = usuariologado.RuleMovimentacao; ViewBag.RuleCadastro = usuariologado.RuleCadastro; if (tabela.ID != 0) { var tabExame = db.TabExame.Where(x => x.TabID == tabela.ID && x.EmpresaID == usuariologado.empresaId); tabela.Descricao = LibProdusys.FS(tabela.Descricao); tabela.TabelaPrecos = tabExame.ToList(); db.Entry(tabela).State = EntityState.Modified; db.SaveChanges(); ViewBag.Exame = true; return(View(tabela)); } else { if (!string.IsNullOrEmpty(tabela.Descricao)) { tabela.ID = GetNewCode("tabelapreco", "id", " empresaid = " + usuariologado.empresaId.ToString()); tabela.EmpresaID = Convert.ToInt32(usuariologado.empresaId); tabela.Descricao = LibProdusys.FS(tabela.Descricao); try { db.TabPreco.Add(tabela); var tabExame = db.TabExame.Where(x => x.TabID == tabela.ID && x.EmpresaID == usuariologado.empresaId); tabela.TabelaPrecos = tabExame.ToList(); db.SaveChanges(); ViewBag.sucesso = "Operação efetuada com sucesso !"; ViewBag.Exame = true; return(Redirect("~/Tabela/Create/" + tabela.ID)); } catch (Exception e) { ViewBag.erro = "Erro ao gravar, entre em contato com o Suporte Técnico !"; e.ToString(); throw; } } else { var TabelaPrecos = new List <TabelaPreco.TabelaPrecoExame>(); tabela.TabelaPrecos = TabelaPrecos; ViewBag.Exame = false; return(View(tabela)); } } } else { TempData["MensagemRetorno"] = "Faça Login para continuar."; return(Redirect("~/Login")); } }
public async Task <IActionResult> Edit(int id, [Bind("Id,DataCadastro,Nome,ConvenioId,PostoColetaId")] TabelaPreco tabelaPreco) { if (id != tabelaPreco.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(tabelaPreco); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TabelaPrecoExists(tabelaPreco.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ConvenioId"] = new SelectList(_context.Convenio, "Id", "Id", tabelaPreco.ConvenioId); ViewData["PostoColetaId"] = new SelectList(_context.PostoColeta, "Id", "Id", tabelaPreco.PostoColetaId); return(View(tabelaPreco)); }
public void CamposObrigatoriosEVazios() { using (TabelaPrecoRepositorio tabPreRep = new TabelaPrecoRepositorio()) { TabelaPreco tabela = new TabelaPreco(); try { tabela.descricao = "Teste"; tabela.inicioVigencia = new DateTime(2017, 06, 01); tabela.finalVigencia = new DateTime(2017, 06, 10); tabela.valorHoraInicial = 2; tabela.valorHoraAdicional = 1; tabPreRep.Adicionar(tabela); tabPreRep.Salvar(); Assert.IsTrue(true); } catch (DbEntityValidationException dbEx) { string erros = string.Join("\n", dbEx.EntityValidationErrors.Where(item => !item.IsValid).Select(item => string.Join("\n", item.ValidationErrors.Select(erro => erro.ErrorMessage).ToArray <string>())).ToArray <string>()); Assert.IsTrue(false, erros); } } }
public TabelaPreco Persistir(TabelaPreco objTabelaPreco) { TabelaPreco tmpTabelaPreco = null; if (objTabelaPreco.ID.HasValue) { tmpTabelaPreco = RepositoryService.TabelaPreco.ObterPor(objTabelaPreco.ID.Value); if (tmpTabelaPreco != null) { objTabelaPreco.ID = tmpTabelaPreco.ID; RepositoryService.TabelaPreco.Update(objTabelaPreco); //Altera Status - Se necessário if (!tmpTabelaPreco.Status.Equals(objTabelaPreco.Status) && objTabelaPreco.Status != null) { this.MudarStatus(tmpTabelaPreco.ID.Value, objTabelaPreco.Status.Value); } return(tmpTabelaPreco); } else { return(null); } } else { objTabelaPreco.ID = RepositoryService.TabelaPreco.Create(objTabelaPreco); return(objTabelaPreco); } }
public ActionResult DeleteConfirmed(int id) { TabelaPreco tabelaPreco = db.TabelaPrecos.Find(id); db.TabelaPrecos.Remove(tabelaPreco); db.SaveChanges(); return(RedirectToAction("Index")); }
public void Delete(TabelaPreco obj) { var Repository = new TabelaPrecoRepository(); Repository.Delete(obj); Mensagem = $"Tabela de preços {obj.ds_descricao} excluída com sucesso"; }
public void Put([FromBody] TabelaPreco tb) { using (var context = new WebServiceDBContext()) { context.Entry(tb).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
private void ValidaTabela(TabelaPreco data) { var validationResults = _validator.Validate(data); if (!validationResults.IsValid) { throw new ModelValidateException("Tabela de Preço não é Válida!", validationResults); } }
public ActionResult Edit([Bind(Include = "TabelaPrecoID,DataInicio,DataFim,Preco,PrecoHoraAdicional")] TabelaPreco tabelaPreco) { if (ModelState.IsValid) { db.Entry(tabelaPreco).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tabelaPreco)); }
private void BindModel() { if (tblPreco == null) { tblPreco = new TabelaPreco(); } tblPreco.id_codigo = txtCodTabelaPreco.Text; tblPreco.ds_descricao = txtDescricaoTabelaPreco.Text; }
public TabelaPreco BuscaTabelaPrecoPorCodigo(int itbc_codigo_tabela) { TabelaPreco tabelaPreco = RepositoryService.TabelaPreco.ObterPor(itbc_codigo_tabela); if (tabelaPreco != null) { return(tabelaPreco); } return(null); }
public TabelaPreco BuscaTabelaPreco(Guid itbc_tabeladeprecoid) { TabelaPreco tabelaPreco = RepositoryService.TabelaPreco.ObterPor(itbc_tabeladeprecoid); if (tabelaPreco != null) { return(tabelaPreco); } return(null); }
public ActionResult Edit([Bind(Include = "handle,descricao,inicioVigencia,finalVigencia,valorHoraInicial,valorHoraAdicional")] TabelaPreco tabelaPreco) { if (ModelState.IsValid) { tabePrecRepo.Atualizar(tabelaPreco); tabePrecRepo.Salvar(); return(RedirectToAction("Index")); } return(View(tabelaPreco)); }
// GET: TabelaPrecos/Delete/5 public ActionResult Delete(int id) { TabelaPreco tabelaPreco = tabelaprecoregras.buscarporID(id); if (tabelaPreco == null) { return(HttpNotFound()); } return(View(tabelaPreco)); }
public ActionResult Edit([Bind(Include = "Id,Nome,ValorHora,TipoVeiculoId")] TabelaPreco tabelaPreco) { if (ModelState.IsValid) { tabelaprecoregras.Atualizar(tabelaPreco); return(RedirectToAction("Index")); } ViewBag.TipoVeiculoId = new SelectList(modeloveiculoregras.buscarTodos(), "Id", "Nome", tabelaPreco.TipoVeiculoId); return(View(tabelaPreco)); }
public ActionResult Create([Bind(Include = "TabelaPrecoID,DataInicio,DataFim,Preco,PrecoHoraAdicional")] TabelaPreco tabelaPreco) { if (ModelState.IsValid) { db.TabelaPrecos.Add(tabelaPreco); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tabelaPreco)); }
public Retorno Pesquisar(TabelaPreco Entity, int Pagina, int QntPagina) { try { return(new DataTabelaPreco().Pesquisar(Entity, Pagina, QntPagina)); } catch (Exception ex) { return(Retorno.CriarRetornoExcecao(ex)); } }
private Retorno VerificarExistencia(TabelaPreco Entity) { try { return(new DataTabelaPreco().VerificarExistencia(Entity)); } catch (Exception ex) { return(Retorno.CriarRetornoExcecao(ex)); } }
public Retorno Excluir(TabelaPreco Entity) { try { return(new DataTabelaPreco().Excluir(Entity)); } catch (Exception ex) { return(Retorno.CriarRetornoExcecao(ex)); } }
// GET: TabelaPrecos/Edit/5 public ActionResult Edit(int id) { TabelaPreco tabelaPreco = tabelaprecoregras.buscarporID(id); if (tabelaPreco == null) { return(HttpNotFound()); } ViewBag.TipoVeiculoId = new SelectList(modeloveiculoregras.buscarTodos(), "Id", "Nome", tabelaPreco.TipoVeiculoId); return(View(tabelaPreco)); }
public TabelaPreco Get(long id) { TabelaPreco tb = null; using (var context = new WebServiceDBContext()) { tb = context.TabelaPrecos.Find(id); } return(tb); }
public HttpResponseMessage Delete(long id) { using (var context = new WebServiceDBContext()) { TabelaPreco tb = context.TabelaPrecos.Find(id); context.Entry(tb).State = System.Data.Entity.EntityState.Deleted; context.SaveChanges(); } return(new HttpResponseMessage(HttpStatusCode.Accepted)); }