public ActionResult LecturerLogin(Lecturer lecturerObj)
        {
            if (ModelState.IsValid)
            {
                bool found = false;
                if (lecturerObj.LecturerID != null && lecturerObj.L_Password != null)
                {
                    using (MCQDatabaseEntities db = new MCQDatabaseEntities())
                    {
                        string password = EncryptionDll.EncryptData(lecturerObj.L_Password, "ffhhgfgh");
                        //checks if any username and password are a match

                        var obj = db.Lecturers.Where(a => a.LecturerID.Equals(lecturerObj.LecturerID) && a.L_Password.Equals(password)).FirstOrDefault();
                        if (obj != null)
                        {
                            Session["LecturerID"] = lecturerObj.LecturerID.ToString();
                            Session["StudentID"]  = null;
                            return(RedirectToAction("ViewTest"));
                        }
                    }

                    if (!found)
                    {
                        ViewBag.Error = "Incorrect Details - please try again!";
                    }
                }
                else
                {
                    ViewBag.Error = "Please fill in all fields";
                }
                return(View());
            }
            return(View(lecturerObj));
        }
Example #2
0
        public ActionResult StudentLogin(Student studentObj)
        {
            if (ModelState.IsValid)
            {
                bool found = false;
                if (studentObj.StudentNumber.ToString() != null && studentObj.S_Password != null)
                {
                    using (MCQDatabaseEntities db = new MCQDatabaseEntities())
                    {
                        string password = EncryptionDll.EncryptData(studentObj.S_Password, "ffhhgfgh");
                        var    obj      = db.Students.Where(a => a.StudentNumber.Equals(studentObj.StudentNumber) && a.S_Password.Equals(password)).FirstOrDefault();
                        if (obj != null)
                        {
                            found = true;
                            Session["StudentID"]  = studentObj.StudentNumber.ToString();
                            Session["LecturerID"] = null;
                            return(RedirectToAction("StudentViewMarks"));
                        }
                    }

                    if (!found)
                    {
                        ViewBag.Error = "Incorrect Details - please try again!";
                    }
                }
                else
                {
                    ViewBag.Error = "Please fill in all fields";
                }
                return(View());
            }
            return(View(studentObj));
        }
        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));
        }