// GET: Banco/Delete/5 public ActionResult Delete(int id) { BancoModel bancoModel = new BancoModel(); DataTable dt = new DataTable(); BancoAppContext context = HttpContext.RequestServices.GetService(typeof(BancoApp.Models.BancoAppContext)) as BancoAppContext; MySqlConnection conn = context.GetConnection(); conn.Open(); string sqlquery = "SELECT * FROM Banco WHERE idBanco = @IdBanco"; MySqlDataAdapter sda = new MySqlDataAdapter(sqlquery, conn); sda.SelectCommand.Parameters.AddWithValue("@IdBanco", id); sda.Fill(dt); if (dt.Rows.Count == 1) { bancoModel.IdBanco = Convert.ToInt32(dt.Rows[0][0].ToString()); bancoModel.Nombre = dt.Rows[0][1].ToString(); bancoModel.Direccion = dt.Rows[0][2].ToString(); bancoModel.FechaRegistro = (System.DateTime)dt.Rows[0][3]; return(View(bancoModel)); } else { return(RedirectToAction("Index")); } }
public ActionResult Index(LoginClass lc) { BancoAppContext context = HttpContext.RequestServices.GetService(typeof(BancoApp.Models.BancoAppContext)) as BancoAppContext; MySqlConnection conn = context.GetConnection(); conn.Open(); string sqlquery = "SELECT userName, role FROM Users WHERE userName=@UserName AND password=@Password"; MySqlCommand cmd = new MySqlCommand(sqlquery, conn); cmd.Parameters.AddWithValue("@UserName", lc.UserName); cmd.Parameters.AddWithValue("@Password", lc.Password); MySqlDataReader sdr = cmd.ExecuteReader(); if (sdr.Read()) { //TempData["userName"] = lc.UserName.ToString(); //TempData["role"] = sdr["role"].ToString(); HttpContext.Session.SetString("roles", sdr["role"].ToString()); HttpContext.Session.SetString("username", lc.UserName.ToString()); //Session["username"] = lc.UserName.ToString(); return(RedirectToAction("Welcome")); } else { ViewData["Message"] = "User Login Failed"; } conn.Close(); return(View()); }
// GET: Banco/Details/5 public ActionResult Details(int id) { BancoModel bancoModel = new BancoModel(); DataTable dt = new DataTable(); BancoAppContext context = HttpContext.RequestServices.GetService(typeof(BancoApp.Models.BancoAppContext)) as BancoAppContext; MySqlConnection conn = context.GetConnection(); conn.Open(); string sqlquery = "SELECT * FROM Banco WHERE idBanco = @IdBanco"; MySqlDataAdapter sda = new MySqlDataAdapter(sqlquery, conn); sda.SelectCommand.Parameters.AddWithValue("@IdBanco", id); sda.Fill(dt); if (dt.Rows.Count == 1) { bancoModel.IdBanco = Convert.ToInt32(dt.Rows[0][0].ToString()); bancoModel.Nombre = dt.Rows[0][1].ToString(); bancoModel.Direccion = dt.Rows[0][2].ToString(); bancoModel.FechaRegistro = (System.DateTime)dt.Rows[0][3]; // get list sucursales DataTable dts = new DataTable(); string sqlquery_s = "SELECT * FROM Sucursal WHERE Banco_idBanco = @IdBanco"; MySqlCommand cmd = new MySqlCommand(sqlquery_s, conn); cmd.Parameters.AddWithValue("@IdBanco", id); MySqlDataReader sdr = cmd.ExecuteReader(); List <SucursalModel> list = new List <SucursalModel>(); while (sdr.Read()) { list.Add(new SucursalModel() { IdSucursal = Convert.ToInt32(sdr["IdSucursal"]), Nombre = sdr["Nombre"].ToString(), Direccion = sdr["Direccion"].ToString(), FechaRegistro = (System.DateTime)sdr["FechaRegistro"], IdBanco = Convert.ToInt32(sdr["Banco_idBanco"].ToString()), }); } ViewBag.sucursales = list; return(View(bancoModel)); } else { return(RedirectToAction("Index")); } }
public ActionResult Index() { BancoAppContext context = HttpContext.RequestServices.GetService(typeof(BancoApp.Models.BancoAppContext)) as BancoAppContext; MySqlConnection conn = context.GetConnection(); conn.Open(); DataTable dt = new DataTable(); string sqlquery = "SELECT * FROM Banco"; MySqlDataAdapter sda = new MySqlDataAdapter(sqlquery, conn); sda.Fill(dt); return(View(dt)); }
public ActionResult Delete(int id, IFormCollection collection) { BancoAppContext context = HttpContext.RequestServices.GetService(typeof(BancoApp.Models.BancoAppContext)) as BancoAppContext; MySqlConnection conn = context.GetConnection(); conn.Open(); string sqlquery = "DELETE FROM Banco WHERE idBanco=@IdBanco"; MySqlCommand cmd = new MySqlCommand(sqlquery, conn); cmd.Parameters.AddWithValue("@IdBanco", id); cmd.ExecuteNonQuery(); conn.Close(); return(RedirectToAction("Index")); }
public ActionResult Create(BancoModel bancoModel) { BancoAppContext context = HttpContext.RequestServices.GetService(typeof(BancoApp.Models.BancoAppContext)) as BancoAppContext; MySqlConnection conn = context.GetConnection(); conn.Open(); string sqlquery = "INSERT Into Banco (nombre, direccion, fechaRegistro)VALUES (@Nombre, @Direccion, @FechaRegistro)"; MySqlCommand cmd = new MySqlCommand(sqlquery, conn); //cmd.Parameters.AddWithValue("@IdBanco", bancoModel.IdBanco); cmd.Parameters.AddWithValue("@Nombre", bancoModel.Nombre); cmd.Parameters.AddWithValue("@Direccion", bancoModel.Direccion); cmd.Parameters.AddWithValue("@FechaRegistro", bancoModel.FechaRegistro); cmd.ExecuteNonQuery(); conn.Close(); return(RedirectToAction("Index")); }
public ActionResult Edit(BancoModel bancoModel) { BancoAppContext context = HttpContext.RequestServices.GetService(typeof(BancoApp.Models.BancoAppContext)) as BancoAppContext; MySqlConnection conn = context.GetConnection(); conn.Open(); string sqlquery = "Update Banco SET Nombre=@Nombre, Direccion=@Direccion, FechaRegistro=@FechaRegistro WHERE idBanco=@IdBanco"; MySqlCommand cmd = new MySqlCommand(sqlquery, conn); cmd.Parameters.AddWithValue("@IdBanco", bancoModel.IdBanco); cmd.Parameters.AddWithValue("@Nombre", bancoModel.Nombre); cmd.Parameters.AddWithValue("@Direccion", bancoModel.Direccion); cmd.Parameters.AddWithValue("@FechaRegistro", bancoModel.FechaRegistro); cmd.ExecuteNonQuery(); conn.Close(); return(RedirectToAction("Index")); }
public ActionResult Create(Models.SucursalModel sucursalModel, int id) { BancoAppContext context = HttpContext.RequestServices.GetService(typeof(BancoApp.Models.BancoAppContext)) as BancoAppContext; MySqlConnection conn = context.GetConnection(); conn.Open(); string sqlquery = "INSERT Into Sucursal (nombre, direccion, fechaRegistro, Banco_idBanco) VALUES ( @Nombre, @Direccion, @FechaRegistro, @Banco_idBanco)"; MySqlCommand cmd = new MySqlCommand(sqlquery, conn); //cmd.Parameters.AddWithValue("@IdSucursal", sucursalModel.IdSucursal); cmd.Parameters.AddWithValue("@Nombre", sucursalModel.Nombre); cmd.Parameters.AddWithValue("@Direccion", sucursalModel.Direccion); cmd.Parameters.AddWithValue("@FechaRegistro", sucursalModel.FechaRegistro); cmd.Parameters.AddWithValue("@Banco_idBanco", id); cmd.ExecuteNonQuery(); conn.Close(); return(RedirectToAction("Details", "Banco", new { @id = id })); }