Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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 }));
        }
Exemplo n.º 3
0
 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)
     {
     }
 }
Exemplo n.º 4
0
 public void Remove(FormaPagamentoModel formaPagamento)
 {
     using (ISession session = NHibernateHelper.OpenSession())
         using (ITransaction transaction = session.BeginTransaction())
         {
             session.Delete(formaPagamento);
             transaction.Commit();
         }
 }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        public JsonResult EditarFormaPagamento(FormaPagamentoModel model)
        {
            var response = ServiceRequest.Put <FormaPagamentoModel>(model, "api/FormaPagamento/EditarFormaPagamento");

            return(ReturnResponse(response));
        }