public AsistentasEditViewModel getAsistentas(int id) { AsistentasEditViewModel asistentas = new AsistentasEditViewModel(); string conn = ConfigurationManager.ConnectionStrings["MysqlConnection"].ConnectionString; MySqlConnection mySqlConnection = new MySqlConnection(conn); string sqlquery = @"SELECT m.* FROM asistentas m WHERE m.id_ASISTENTAS=" + id; MySqlCommand mySqlCommand = new MySqlCommand(sqlquery, mySqlConnection); mySqlConnection.Open(); MySqlDataAdapter mda = new MySqlDataAdapter(mySqlCommand); DataTable dt = new DataTable(); mda.Fill(dt); mySqlConnection.Close(); foreach (DataRow item in dt.Rows) { asistentas.Vardas = Convert.ToString(item["Vardas"]); asistentas.Pavarde = Convert.ToString(item["Pavarde"]); asistentas.Tautybe = Convert.ToString(item["Tautybe"]); asistentas.id = Convert.ToInt32(item["id_ASISTENTAS"]); asistentas.fk_treneris = Convert.ToInt32(item["fk__TRENERIS"]); } return(asistentas); }
public ActionResult Edit(int id) { AsistentasEditViewModel asistentas = asistentasRepository.getAsistentas(id); PopulateSelections(asistentas); return(View(asistentas)); }
public ActionResult Create() { AsistentasEditViewModel asistentas = new AsistentasEditViewModel(); PopulateSelections(asistentas); return(View(asistentas)); }
public void PopulateSelections(AsistentasEditViewModel asistentas) { var treneriai = trenerisRepository.getTreneris(); List <SelectListItem> selectListItems = new List <SelectListItem>(); foreach (var item in treneriai) { selectListItems.Add(new SelectListItem() { Value = Convert.ToString(item.id), Text = item.Vardas + " " + item.Pavarde }); } asistentas.TreneriaiList = selectListItems; }
public ActionResult Create(AsistentasEditViewModel collection) { try { if (ModelState.IsValid) { asistentasRepository.addAsistentas(collection); } return(RedirectToAction("Index")); } catch { PopulateSelections(collection); return(View(collection)); } }
public bool addAsistentas(AsistentasEditViewModel asistentas) { string conn = ConfigurationManager.ConnectionStrings["MysqlConnection"].ConnectionString; MySqlConnection mySqlConnection = new MySqlConnection(conn); string sqlquery = @"INSERT INTO asistentas(Vardas,Pavarde,Tautybe,fk__TRENERIS,id_ASISTENTAS) VALUES(?vardas,?pavarde,?tautybe,?treneris,?id)"; MySqlCommand mySqlCommand = new MySqlCommand(sqlquery, mySqlConnection); mySqlCommand.Parameters.Add("?vardas", MySqlDbType.VarChar).Value = asistentas.Vardas; mySqlCommand.Parameters.Add("?pavarde", MySqlDbType.VarChar).Value = asistentas.Pavarde; mySqlCommand.Parameters.Add("?tautybe", MySqlDbType.VarChar).Value = asistentas.Tautybe; mySqlCommand.Parameters.Add("?treneris", MySqlDbType.Int32).Value = asistentas.fk_treneris; mySqlCommand.Parameters.Add("?id", MySqlDbType.Int32).Value = getID(); mySqlConnection.Open(); mySqlCommand.ExecuteNonQuery(); mySqlConnection.Close(); return(true); }
public bool updateAsistentas(AsistentasEditViewModel asistentas) { string conn = ConfigurationManager.ConnectionStrings["MysqlConnection"].ConnectionString; MySqlConnection mySqlConnection = new MySqlConnection(conn); string sqlquery = @"UPDATE asistentas a SET a.Vardas=?vardas, a.Pavarde=?pavarde, a.Tautybe=?tautybe, a.fk__TRENERIS=?treneris WHERE a.id_ASISTENTAS=?id"; MySqlCommand mySqlCommand = new MySqlCommand(sqlquery, mySqlConnection); mySqlCommand.Parameters.Add("?id", MySqlDbType.Int32).Value = asistentas.id; mySqlCommand.Parameters.Add("?vardas", MySqlDbType.VarChar).Value = asistentas.Vardas; mySqlCommand.Parameters.Add("?pavarde", MySqlDbType.VarChar).Value = asistentas.Pavarde; mySqlCommand.Parameters.Add("?tautybe", MySqlDbType.VarChar).Value = asistentas.Tautybe; mySqlCommand.Parameters.Add("?treneris", MySqlDbType.Int32).Value = asistentas.fk_treneris; mySqlConnection.Open(); mySqlCommand.ExecuteNonQuery(); mySqlConnection.Close(); return(true); }
public ActionResult Delete(int id) { AsistentasEditViewModel asistentas = asistentasRepository.getAsistentas(id); return(View(asistentas)); }