Example #1
0
        public IActionResult Register([FromForm] ContasReceberModel model)
        {
            const string sql = "RegistarReceber";

            using (SqlConnection connection = new SqlConnection(
                       @"Data Source=TD50001424\SQLEXPRESS;Initial Catalog=Db_Contas;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"))


                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;

                    command.Parameters.Add(new SqlParameter(@"DataVencimento", System.Data.SqlDbType.Date));
                    command.Parameters[@"DataVencimento"].Value = model.DataVencimento;

                    command.Parameters.Add(new SqlParameter(@"ClienteId", System.Data.SqlDbType.Int));
                    command.Parameters[@"ClienteId"].Value = model.ClienteId;

                    command.Parameters.Add(new SqlParameter(@"Valor", System.Data.SqlDbType.Money));
                    command.Parameters[@"Valor"].Value = model.Valor;

                    connection.Open();

                    command.ExecuteNonQuery();

                    connection.Close();
                }

            return(View(model));
        }
Example #2
0
        public IActionResult Alterar(int Id)
        {
            DataTable results = new DataTable();

            using (SqlConnection connection = new SqlConnection(@"Data Source=TD50001424\SQLEXPRESS;Initial Catalog=Db_Contas;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"))
            {
                //Define a t-sql query string that has a parameter form id
                string sql = "select FaturaId, DataVencimento, DataPgamento, ClienteId, Valor, ValorPago from dbo.ContasReceber";

                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    connection.Open();

                    //run query by Execuetereader
                    using (SqlDataReader dataReader = command.ExecuteReader())
                    {
                        results.Load(dataReader);

                        dataReader.Close();
                    }
                    connection.Close();

                    var model = new ContasReceberModel
                    {
                        FaturaId = int.Parse(results.Rows[0]["FaturaId"].ToString()),
                        //DataVencimento = DateTime.Parse(results.Rows[0]["DataVencimento"].ToString()),
                        //DataPagamento = DateTime.Parse(results.Rows[0]["DataPgamento"].ToString()),
                        ClienteId = int.Parse(results.Rows[0]["ClienteId"].ToString()),
                        Valor     = decimal.Parse(results.Rows[0]["Valor"].ToString()),
                        //ValorPago = decimal.Parse(results.Rows[0]["ValorPago"].ToString()),
                    };

                    ContasReceberModel contas = new ContasReceberModel();
                    contas.CalcValorPago();

                    return(View(model));
                }
            }
        }