public ActionResult Delete(int id, FormCollection collection) { try { BilietasEditViewModel bilietas = bilietaiRepository.getBilietas(id); // bool naudojama = false; // if (modeliuRepository.getModelisCount(id)>0) // { // naudojama = true; // ViewBag.naudojama = "Negalima pašalinti modelio, yra sukurtų automobilių su šiuo modeliu."; // return View(modelis); // } bilietaiRepository.deleteBilietas(id); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create() { BilietasEditViewModel bilietas = new BilietasEditViewModel(); PopulateSelections(bilietas); return(View(bilietas)); }
public ActionResult Edit(int id) { BilietasEditViewModel bilietas = bilietaiRepository.getBilietas(id); PopulateSelections(bilietas); return(View(bilietas)); }
public BilietasEditViewModel getBilietas(int id) { BilietasEditViewModel bilietas = new BilietasEditViewModel(); string conn = ConfigurationManager.ConnectionStrings["MysqlConnection"].ConnectionString; MySqlConnection mySqlConnection = new MySqlConnection(conn); string sqlquery = @"SELECT m.* FROM " + @"bilietai m WHERE m.bilieto_id=" + 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) { bilietas.id = Convert.ToInt32(item["bilieto_id"]); bilietas.kaina = Convert.ToInt32(item["kaina"]); bilietas.fk_klientas = Convert.ToInt32(item["fk_klientaikliento_id"]); } return(bilietas); }
public void PopulateSelections(BilietasEditViewModel bilietas) { var klientai = klientaiRepository.getKlientai(); List <SelectListItem> selectListKlientai = new List <SelectListItem>(); foreach (var item in klientai) { selectListKlientai.Add(new SelectListItem() { Value = Convert.ToString(item.id), Text = (item.asmens_kodas + " " + item.vardas + " " + item.pavarde) }); } bilietas.KlientasList = selectListKlientai; }
public bool updateBilietas(BilietasEditViewModel bilietas) { string conn = ConfigurationManager.ConnectionStrings["MysqlConnection"].ConnectionString; MySqlConnection mySqlConnection = new MySqlConnection(conn); string sqlquery = @"UPDATE " + "bilietai a SET a.kaina=?kaina, a.fk_klientaikliento_id=?klientas WHERE a.bilieto_id=?id"; MySqlCommand mySqlCommand = new MySqlCommand(sqlquery, mySqlConnection); mySqlCommand.Parameters.Add("?id", MySqlDbType.Int32).Value = bilietas.id; mySqlCommand.Parameters.Add("?kaina", MySqlDbType.Int32).Value = bilietas.kaina; mySqlCommand.Parameters.Add("?klientas", MySqlDbType.Int32).Value = bilietas.fk_klientas; mySqlConnection.Open(); mySqlCommand.ExecuteNonQuery(); mySqlConnection.Close(); return(true); }
public bool addBilietas(BilietasEditViewModel bilietas) { string conn = ConfigurationManager.ConnectionStrings["MysqlConnection"].ConnectionString; MySqlConnection mySqlConnection = new MySqlConnection(conn); string sqlquery = @"INSERT INTO " + "bilietai(bilieto_id,kaina,fk_klientaikliento_id)VALUES(?id,?kaina,?raktas)"; MySqlCommand mySqlCommand = new MySqlCommand(sqlquery, mySqlConnection); mySqlCommand.Parameters.Add("?id", MySqlDbType.Int32).Value = bilietas.id; mySqlCommand.Parameters.Add("?kaina", MySqlDbType.Int32).Value = bilietas.kaina; mySqlCommand.Parameters.Add("?raktas", MySqlDbType.VarChar).Value = bilietas.fk_klientas; mySqlConnection.Open(); mySqlCommand.ExecuteNonQuery(); mySqlConnection.Close(); return(true); }
public ActionResult Edit(int id, BilietasEditViewModel collection) { try { // TODO: Add update logic here if (ModelState.IsValid) { bilietaiRepository.updateBilietas(collection); } return(RedirectToAction("Index")); } catch { PopulateSelections(collection); return(View(collection)); } }
public ActionResult Create(BilietasEditViewModel collection) { try { // TODO: Add insert logic here if (ModelState.IsValid) { collection.id = bilietaiRepository.getNewId(); bilietaiRepository.addBilietas(collection); } return(RedirectToAction("Index")); } catch { PopulateSelections(collection); return(View(collection)); } }
public ActionResult Delete(int id) { BilietasEditViewModel bilietas = bilietaiRepository.getBilietas(id); return(View(bilietas)); }