public FormaPagamentoModel RecuperarPeloId(int id) { FormaPagamentoModel ret = null; Connection(); using (SqlCommand command = new SqlCommand("SELECT * FROM FormaPagamento WHERE Id=@Id", con)) { con.Open(); command.Parameters.AddWithValue("@Id", SqlDbType.Int).Value = id; var reader = command.ExecuteReader(); if (reader.Read()) { ret = new FormaPagamentoModel() { Id = (int)reader["Id"], Codigo = (string)reader["Codigo"], Nome = (string)reader["Nome"] }; } } return(ret); }
public JsonResult SalvarFormaPagamento(FormaPagamentoModel formaPagamentoModel) { var resultado = "OK"; var mensagens = new List <string>(); var idSalvo = string.Empty; if (!ModelState.IsValid) { resultado = "AVISO"; mensagens = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage).ToList(); } else { try { formaPagamentoRepositorio = new FormaPagamentoRepositorio(); var id = formaPagamentoRepositorio.Salvar(formaPagamentoModel); if (id > 0) { idSalvo = id.ToString(); } else { resultado = "ERRO"; } } catch (Exception ex) { resultado = "ERRO"; throw new Exception(ex.Source); } } return(Json(new { Resultado = resultado, Mensagens = mensagens, IdSalvo = idSalvo })); }
private void pckPagamento_SelectedIndexChanged(object sender, EventArgs e) { try { FormaPagamentoModel itemSelecionado = (FormaPagamentoModel)pckPagamento.SelectedItem; if (itemSelecionado != null) { GlobalVariables.formaPagamento = Convert.ToInt32(itemSelecionado.IdFormaPagamento); if (GlobalVariables.formaPagamento == 145) { pckPagamento.SelectedIndex = 36; ECpercDesc.IsEnabled = true; } else { ECpercDesc.IsEnabled = false; } btnProximoPagamento.IsVisible = true; } else { btnProximoPagamento.IsVisible = false; } } catch (Exception) { } }
public void Remove(FormaPagamentoModel formaPagamento) { using (ISession session = NHibernateHelper.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { session.Delete(formaPagamento); transaction.Commit(); } }
public int Salvar(FormaPagamentoModel formaPagamentoModel) { var ret = 0; var model = RecuperarPeloId(formaPagamentoModel.Id); if (model == null) { Connection(); using (SqlCommand command = new SqlCommand(" INSERT INTO FormaPagamento( Codigo, " + " Nome " + " ) " + " VALUES( @Codigo, " + " @Nome " + " ); " + " select convert(int, scope_identity()) ", con)) { con.Open(); command.Parameters.AddWithValue("@Codigo", SqlDbType.VarChar).Value = formaPagamentoModel.Codigo; command.Parameters.AddWithValue("@Nome", SqlDbType.VarChar).Value = formaPagamentoModel.Nome; ret = (int)command.ExecuteScalar(); } } else { Connection(); using (SqlCommand command = new SqlCommand(" UPDATE FormaPagamento " + " SET Codigo=@Codigo, " + " Nome=@Nome " + " WHERE Id=@Id", con)) { con.Open(); command.Parameters.AddWithValue("@Codigo", SqlDbType.VarChar).Value = formaPagamentoModel.Codigo; command.Parameters.AddWithValue("@Nome", SqlDbType.VarChar).Value = formaPagamentoModel.Nome; command.Parameters.AddWithValue("@Id", SqlDbType.Int).Value = formaPagamentoModel.Id; if (command.ExecuteNonQuery() > 0) { ret = formaPagamentoModel.Id; } } } return(ret); }
public Task <HttpResponseMessage> EditarFormaPagamento(FormaPagamentoModel model) { HttpResponseMessage response; try { var formaPagamento = Mapper.Map <FormaPagamento>(model); var formaPagamentoRetorno = _formaPagamentoService.AtualizarFormaPagamento(formaPagamento); response = ReturnSuccess(Mapper.Map <FormaPagamentoModel>(formaPagamentoRetorno)); } catch (Exception ex) { response = ReturnError(ex); } var tsc = new TaskCompletionSource <HttpResponseMessage>(); tsc.SetResult(response); return(tsc.Task); }
public JsonResult EditarFormaPagamento(FormaPagamentoModel model) { var response = ServiceRequest.Put <FormaPagamentoModel>(model, "api/FormaPagamento/EditarFormaPagamento"); return(ReturnResponse(response)); }