public ActionResult Partners() { Crew k = new Crew(); List<Crew> Lic = new List<Crew>(); Lic = k.IndexDisplay(); ViewData["IndexDisplay"] = Lic; return View(Lic); }
public ActionResult DeleteEmploy(Crew f) { string fullPath = Request.MapPath("~/ImagesCrew/" + f.nameofpic); System.IO.File.Delete(fullPath); D.Open(); int i = D.DataDelete("DELETE FROM Crew WHERE Email= '" + f.email + "' "); D.Close(); if (i > 0) { ModelState.AddModelError("Success", "Save Success"); } else { ModelState.AddModelError("Error", "Save Error"); } return RedirectToAction("Crew", "Dashboard"); }
//εδώ κάνουμε το έρωτημα sql και μετά αποθηκεύουμε αυτά που θέλουμε public List<Crew> IndexDisplay() { SqlConnection con = new SqlConnection(constr); con.Open(); using (con) { SqlCommand cmd = new SqlCommand("Select * from Crew ", con); SqlDataReader rd = cmd.ExecuteReader(); while (rd.Read()) { p = new Crew(); p.fname = Convert.ToString(rd.GetSqlValue(1)); p.sname = Convert.ToString(rd.GetSqlValue(2)); p.job = Convert.ToString(rd.GetSqlValue(3)); p.email = Convert.ToString(rd.GetSqlValue(4)); p.info = Convert.ToString(rd.GetSqlValue(5)); p.nameofpic = Convert.ToString(rd.GetSqlValue(6)); CrewList.Add(p); } } return CrewList; }
public ActionResult SaveNewPartner(Crew f) { if (ModelState.IsValid) { if (Request.Files.Count > 0) { var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { //αποθήκευση φωτογραφίας στον φάκελο f.nameofpic = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/ImagesCrew"), f.nameofpic); file.SaveAs(path); //ανοιγμα σύνδεσης με βδ και καταχώρηση εγραφή D.Open(); int i = D.DataInsert("INSERT INTO Crew(First_Name,Last_name,Job,Email,Info,ImageName) VALUES ('" + f.fname + "','" + f.sname + "','" + f.job + "','" + f.email + "','" + f.info + "','" + f.nameofpic + "')"); if (i > 0) { ModelState.AddModelError("Success", "Save Success");} else { ModelState.AddModelError("Error", "Save Error");} //κλείσιμο σύνδεση με βδ D.Close(); } else { TempData["check_db"] = 1; } } } return RedirectToAction("Partners", "Home"); }