public List<Conmodel> ConDisplay() { SqlConnection con = new SqlConnection(constr); con.Open(); using (con) { SqlCommand cmd = new SqlCommand("Select * from conus ", con); SqlDataReader rd = cmd.ExecuteReader(); while (rd.Read()) { p = new Conmodel(); p.FirstName = Convert.ToString(rd.GetSqlValue(1)); p.LastName = Convert.ToString(rd.GetSqlValue(2)); p.Email = Convert.ToString(rd.GetSqlValue(3)); p.Phone = Convert.ToString(rd.GetSqlValue(4)); p.Comments = Convert.ToString(rd.GetSqlValue(5)); Contacts.Add(p); } return Contacts; } }
public ActionResult Messages() { Conmodel p = new Conmodel(); List<Conmodel> Li = new List<Conmodel>(); Li = p.ConDisplay(); ViewData["ConDisplay"] = Li; return View(); }
public ActionResult SaveData(Conmodel f) { //αφου η φόρμα είναι σώστα συμπληρωμενη if (ModelState.IsValid) { /*καλόυμε την σύνδεση*/ D.Open(); //μέσω της συνάρτησης datainsert του CodeDb εισάγουμε τα δεδομένα στη βάση int i = D.DataInsert("INSERT INTO conus(First,Last,Email,Phone,Comments) VALUES ('" + f.FirstName + "','" + f.LastName + "','" + f.Email + "','" + f.Phone + "','" + f.Comments + "')"); TempData["notice"] = 1; } D.Close(); return RedirectToAction("Offices", "Home"); }
public ActionResult DeleteMessage(Conmodel f) { D.Open(); int i = D.DataDelete("DELETE FROM conus WHERE Comments= '" + f.Comments + "' "); D.Close(); if (i > 0) { ModelState.AddModelError("Success", "Save Success"); } else { ModelState.AddModelError("Error", "Save Error"); } return RedirectToAction("Messages", "Dashboard"); }