public ActionResult DeleteConfirmed(string id) { Student_tbl student_tbl = db.Student_tbl.Find(id); db.Student_tbl.Remove(student_tbl); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit() { Student_tbl student_tbl = db.Student_tbl.First(st => st.Email == User.Identity.Name); if (student_tbl == null) { return(HttpNotFound()); } return(View(student_tbl)); }
public ActionResult Edit(Student_tbl student_tbl) { if (ModelState.IsValid) { db.Entry(student_tbl).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details", new { id = student_tbl.ID })); } return(View(student_tbl)); }
public ActionResult LogIn(UserModel model) { using (LMSDBEntities db = new LMSDBEntities()) { Student_tbl std = db.Student_tbl.FirstOrDefault(st => st.Email == model.Email); Lecturer_tbl lec = db.Lecturer_tbl.FirstOrDefault(st => st.Email == model.Email); Admin_tbl ad = db.Admin_tbl.FirstOrDefault(st => st.Email == model.Email); //Confirmation booleans bool IsValidStudent = false; bool IsValidLecturer = false; bool IsValidAdmin = false; if (std != null) { var pass_std = Convert.ToBase64String(ComputeHMAC_SHA256(Encoding.UTF8.GetBytes(model.Password), std.Salt)); IsValidStudent = db.Student_tbl.Any(user => user.Email.ToLower() == model.Email.ToLower() && user.Password == pass_std); } else if (lec != null) { var pass_lec = Convert.ToBase64String(ComputeHMAC_SHA256(Encoding.UTF8.GetBytes(model.Password), lec.Salt)); IsValidLecturer = db.Lecturer_tbl.Any(user => user.Email.ToLower() == model.Email.ToLower() && user.Password == pass_lec); } else if (ad != null) { var pass_ad = Convert.ToBase64String(ComputeHMAC_SHA256(Encoding.UTF8.GetBytes(model.Password), ad.Salt)); IsValidAdmin = db.Admin_tbl.Any(user => user.Email.ToLower() == model.Email.ToLower() && user.Password == pass_ad); } //----------------------------------------------------- if (IsValidStudent) { FormsAuthentication.SetAuthCookie(model.Email, false); //Session["UserID"] = std.ID; //Go to profile page return(RedirectToAction("Index", "Home")); } if (IsValidLecturer) { FormsAuthentication.SetAuthCookie(model.Email, false); //Session["UserID"] = lec.ID; //Go to profile page return(RedirectToAction("Index", "Home")); } if (IsValidAdmin) { FormsAuthentication.SetAuthCookie(model.Email, false); //Session["UserID"] = ad.ID; //Go to profile page return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("", "invalid Username or Password"); return(View("LogIn")); } }
public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Student_tbl student_tbl = db.Student_tbl.Find(id); if (student_tbl == null) { return(HttpNotFound()); } return(View(student_tbl)); }
public ActionResult ChangePassword(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Student_tbl std = db.Student_tbl.Find(id); if (std == null) { return(HttpNotFound()); } return(View()); }
public ActionResult Create(Student_tbl student_tbl) { var salt = GenerateSalt(); if (ModelState.IsValid) { student_tbl.Password = Convert.ToBase64String(ComputeHMAC_SHA256(Encoding.UTF8.GetBytes(student_tbl.Password), salt)); student_tbl.salt = salt; db.Student_tbl.Add(student_tbl); db.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(View(student_tbl)); }
public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Student_tbl student_tbl = db.Student_tbl.Find(id); if (student_tbl == null) { return(HttpNotFound()); } ViewBag.Attend_Courses = new SelectList(db.Attendance_tbl, "ID", "StudentID", student_tbl.Attend_Courses); ViewBag.Registered_Courses = new SelectList(db.RegisteredCourses_tbl, "ID", "Course01", student_tbl.Registered_Courses); ViewBag.Results = new SelectList(db.Result_tbl, "ID", "CourseID", student_tbl.Results); return(View(student_tbl)); }
public ActionResult CoursesAvailable(string searchName, int currentPage = 1) { int pageSize = 2; //number of items in one page Student_tbl student = db.Student_tbl.First(st => st.Email == User.Identity.Name); var coursesAval = db.Course_tbl.Where(c => c.Level == student.Level); if (!string.IsNullOrEmpty(searchName)) { coursesAval = coursesAval.Where(c => c.Name.Contains(searchName)); } //Paging Session["PagesCount"] = (coursesAval.Count() / pageSize) + (coursesAval.Count() % pageSize); Session["CurrentP"] = currentPage; int skip = (currentPage - 1) * pageSize; return(View(coursesAval.OrderBy(c => c.ID).Skip(skip).Take(pageSize).ToList())); }
public ActionResult EditPassword(PasswordViewModel passwordVM) { Student_tbl std = db.Student_tbl.First(st => st.Email == User.Identity.Name); var pass = Convert.ToBase64String(ComputeHMAC_SHA256(Encoding.UTF8.GetBytes(passwordVM.OldPassword), std.salt)); bool IsValidStudent = false; if (pass == std.Password) { IsValidStudent = true; } if (IsValidStudent) { std.Password = Convert.ToBase64String(ComputeHMAC_SHA256(Encoding.UTF8.GetBytes(passwordVM.NewPassword), std.salt)); db.Entry(std).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details")); } return(View(passwordVM)); }
public ActionResult Create(Student_tbl student_tbl) { var salt = GenerateSalt(); if (ModelState.IsValid) { student_tbl.Password = Convert.ToBase64String(ComputeHMAC_SHA256(Encoding.UTF8.GetBytes(student_tbl.Password), salt)); student_tbl.Salt = salt; student_tbl.ForgetPassword = false; str = student_tbl.ID; db.Student_tbl.Add(student_tbl); db.SaveChanges(); return(RedirectToAction("UploadImage")); } ViewBag.Attend_Courses = new SelectList(db.Attendance_tbl, "ID", "StudentID", student_tbl.Attend_Courses); ViewBag.Registered_Courses = new SelectList(db.RegisteredCourses_tbl, "ID", "Course01", student_tbl.Registered_Courses); ViewBag.Results = new SelectList(db.Result_tbl, "ID", "CourseID", student_tbl.Results); return(View(student_tbl)); }
public ActionResult LogIn(UserModel model) { using (MostaLearningEntities db = new MostaLearningEntities()) { Student_tbl std = db.Student_tbl.First(st => st.Email == model.Email); var pass = Convert.ToBase64String(ComputeHMAC_SHA256(Encoding.UTF8.GetBytes(model.Password), std.salt)); bool IsValidStudent = db.Student_tbl.Any(user => user.Email.ToLower() == model.Email.ToLower() && user.Password == pass); bool IsValidLecturer = db.Lecturer_tbl.Any(user => user.Email.ToLower() == model.Email.ToLower() && user.Password == model.Password); bool IsValidAdmin = db.Admin_tbl.Any(user => user.Email.ToLower() == model.Email.ToLower() && user.Password == model.Password); if (IsValidStudent) { FormsAuthentication.SetAuthCookie(model.Email, false); //Go to profile page return(RedirectToAction("Index", "Home")); } if (IsValidLecturer) { FormsAuthentication.SetAuthCookie(model.Email, false); //Go to profile page return(RedirectToAction("Index", "Home")); } if (IsValidAdmin) { FormsAuthentication.SetAuthCookie(model.Email, false); //Go to profile page return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("", "invalid Username or Password"); return(View("LogIn")); } }