public ActionResult Delete(vStudent theStudent) { using (var db = new AdvWebDevProjectEntities()) { if (ModelState.IsValid) { try { db.Entry(theStudent).State = System.Data.Entity.EntityState.Deleted; db.vStudents.Remove(theStudent); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", $"An error occurred: {ex.Message}"); } } else { ModelState.AddModelError("", "Model state was invalid."); } } return(View(theStudent)); }
public void LoadStudents() { vStudentRepository sr = new vStudentRepository(); gvStudents.DataSource = sr.GetAllStudents(); gvStudents.DataBind(); vStudent st = new vStudent(); tbxSearch.Value = ""; }
// GET: Student/Edit/5 public ActionResult Edit(int id) { var db = new AdvWebDevProjectEntities(); vStudent theStudent = db.vStudents.Find(id); if (theStudent == null) { return(HttpNotFound()); } return(View(theStudent)); }
public vStudent FindvStudent(string stu) { vStudent result = null; SchoolDBEntities sd = conn.GetContext(); //-- SELECT * FROM vPhoneList WHERE PhobeID = phoneID result = (from r in sd.vStudents where r.StudentCode == stu select r).FirstOrDefault(); return(result); }
public vStudent FindByNatinalCode(string nationalCode) { vStudent result = null; using (SchoolDBEntities sd = conn.GetContext()) { //-- SELECT * FROM vPhoneList WHERE PhobeID = phoneID result = (from r in sd.vStudents where r.NationalCode == nationalCode select r).FirstOrDefault(); return(result); } }
public void load() { vStudent stu = srr.GetStudentByUsername("javad"); lblStuID.InnerText = stu.StuID.ToString(); lblStudentCode.InnerText = stu.StudentCode.ToString(); lblFirstName.InnerText = stu.FirstName; lblLastName.InnerText = stu.LastName; tbxFatherName.Value = stu.FathersFirstName; tbxBirthYear.Value = stu.BirthDate.Substring(0, 4); tbxIDNumber.Value = stu.NationalCode.ToString(); tbxFixTel.Value = stu.PhoneNumber; tbxMobile.Value = stu.MobileNumber; tbxZipCode.Value = stu.ZipCode; tbxEmail.Value = stu.Email; tbxAddress.InnerText = stu.Address; }
protected void Page_Load(object sender, EventArgs e) { vStudent stu = sr.GetStudentByUsername("mhmmd99"); lblStuID.InnerText = stu.StuID.ToString(); lblStudentCode.InnerText = stu.StudentCode.ToString(); lblFirstName.InnerText = stu.FirstName; lblLastName.InnerText = stu.LastName; lblFatherName.InnerText = stu.FathersFirstName; lblBirthYear.InnerText = stu.BirthDate.Substring(0, 4); lblIDNumber.InnerText = stu.NationalCode.ToString(); lblFixTel.InnerText = stu.PhoneNumber; lblMobile.InnerText = stu.MobileNumber; lblZipCode.InnerText = stu.ZipCode; lblEmail.InnerText = stu.Email; lblAddress.InnerText = stu.Address; imgUserPic.Src = stu.Image; }
public ActionResult Create(vStudent theStudent) { using (var db = new AdvWebDevProjectEntities()) { try { if (ModelState.IsValid) { db.vStudents.Add(theStudent); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (Exception ex) { ModelState.AddModelError("", $"An error occurred: {ex.Message}"); } } return(View(theStudent)); }
public ActionResult Edit(vStudent theStudent) { using (var db = new AdvWebDevProjectEntities()) { if (ModelState.IsValid) //verifies that the data submitted in the form can be used to modify (edit or update) { if (TryUpdateModel(theStudent)) { try { db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", $"An error occurred: {ex.Message}"); } } } } return(View(theStudent)); }
public vStudent GetStudentByUsername(string user) { vStudent stu = db.vStudents.Where(p => p.UserName == user).Single(); return(stu); }