public ItensOrcamentoModel Post(ItensOrcamentoModel itensOrcamento) { try { var where = $"ORCAMENTO_ID = {itensOrcamento.ORCAMENTO_ID}"; if (string.IsNullOrEmpty(MetodosGenericosService.DlookupOrcamentaria("ORCAMENTO_ID", "T_ORCA_ORCAMENTO", where))) { throw new Exception(); } if (itensOrcamento.VALOR_COMPRIMENTO < 0 || itensOrcamento.AREA < 0) { throw new Exception(); } where = $"ORCAMENTO_ID = {itensOrcamento.ORCAMENTO_ID}"; var ultimaNumeroLinha = MetodosGenericosService.DlookupOrcamentaria("IF(MAX(NUMERO_LINHA) IS NULL, 0, MAX(NUMERO_LINHA))", "T_ORCA_ITENS_ORCAMENTO", where); itensOrcamento.NUMERO_LINHA = int.Parse(ultimaNumeroLinha) + 1; var novoItensOrcamento = ItensOrcamentoRepository.Create(itensOrcamento); return(novoItensOrcamento); } catch (Exception) { throw; } }
public void Update(int itensOrcamentoId, ItensOrcamentoModel itensOrcamento) { try { using (var cn = Conexao.AbrirConexao()) { cn.Execute(@"UPDATE T_ORCA_ITENS_ORCAMENTO SET NUMERO_LINHA = @NUMERO_LINHA, VALOR_COMPRIMENTO = @VALOR_COMPRIMENTO, AREA = @AREA WHERE ITENS_ORCAMENTO_ID = @itensOrcamentoId", new { itensOrcamento.NUMERO_LINHA, itensOrcamento.VALOR_COMPRIMENTO, itensOrcamento.AREA, itensOrcamentoId }); } } catch (Exception) { throw; } }
public ItensOrcamentoModel Create(ItensOrcamentoModel itensOrcamento) { try { using (var cn = Conexao.AbrirConexao()) { cn.Execute(@"INSERT INTO T_ORCA_ITENS_ORCAMENTO (ORCAMENTO_ID, NUMERO_LINHA, VALOR_COMPRIMENTO, AREA) VALUES(@ORCAMENTO_ID, @NUMERO_LINHA, @VALOR_COMPRIMENTO, @AREA)", new { itensOrcamento.ORCAMENTO_ID, itensOrcamento.NUMERO_LINHA, itensOrcamento.VALOR_COMPRIMENTO, itensOrcamento.AREA }); return(Find(cn.Query <int>("SELECT ITENS_ORCAMENTO_ID FROM T_ORCA_ITENS_ORCAMENTO ORDER BY ITENS_ORCAMENTO_ID DESC LIMIT 1").ToArray()[0])); } } catch (Exception) { throw; } }
public void Put(int itensOrcamentoId, ItensOrcamentoModel itensOrcamento) { try { var where = $"ITENS_ORCAMENTO_ID = {itensOrcamentoId}"; if (string.IsNullOrEmpty(MetodosGenericosService.DlookupOrcamentaria("ITENS_ORCAMENTO_ID", "T_ORCA_ITENS_ORCAMENTO", where))) { throw new Exception(); } var itensOrcamentoDB = GetComParametro(new ItensOrcamentoQO(itensOrcamentoId, 0)).ToArray()[0]; if (itensOrcamento.VALOR_COMPRIMENTO < 0 || itensOrcamento.AREA < 0) { throw new Exception(); } ItensOrcamentoRepository.Update(itensOrcamentoId, itensOrcamento); } catch (Exception) { throw; } }