public ActionResult Edit([Bind(Include = "LecturerID,Firstname,LastName")] Lecturer lecturer, string password) { if (ModelState.IsValid) { lecturer.L_Password = EncryptionDll.EncryptData(password, "ffhhgfgh"); db.Entry(lecturer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("ViewTest")); } return(View(lecturer)); }
public ActionResult Edit([Bind(Include = "StudentNumber,Age,Firstname,LastName")] Student student, string password) { if (ModelState.IsValid) { student.S_Password = EncryptionDll.EncryptData(password, "ffhhgfgh"); db.Entry(student).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("StudentViewMarks")); } return(View(student)); }
public ActionResult CreateTest([Bind(Include = "TestName, Publish")] Test test) { if (ModelState.IsValid) { //checks if the fields are not empty - data validation if (test.TestName != null && test.Publish != null) { //iterates through the database to see if the test name by Lecturer matchs one in the database bool notFound = false; using (MCQDatabaseEntities db = new MCQDatabaseEntities()) { var obj = db.Tests.Where(a => a.TestName.Equals(test.TestName)).FirstOrDefault(); if (obj == null) { notFound = true; test.LecturerID = Session["LecturerID"].ToString(); int count = 1; List <Test> list = db.Tests.ToList(); for (int i = 0; i < list.Count; i++) { Test item = list[i]; if (count != Int32.Parse(item.TestID.Substring(2, 3))) { if (count < 10) { test.TestID = "TE00" + count; } else if (count < 100 && count > 10) { test.TestID = "TE0" + count; } else { test.TestID = "TE" + count; } } else { count++; if (count > list.Count) { if (count < 10) { test.TestID = "TE00" + count; } else if (count < 100 && count >= 10) { test.TestID = "TE0" + count; } else { test.TestID = "TE" + count; } } } } db.Tests.Add(test); db.SaveChanges(); Session["TestID"] = test.TestID; return(RedirectToAction("CreateQuestionsView")); } } if (notFound == false) { ViewBag.Error = "This test already exists"; return(View()); } } else { ViewBag.Error = "Please fill in all fields!"; return(View()); } } return(View(test)); }