Beispiel #1
0
        public List <LecturerModel> getLecturers()
        {
            using (xinyuedbEntities db = new xinyuedbEntities())
            {
                List <LecturerModel> lecturerList = new List <LecturerModel>();
                var lecturers = db.Lecturers;
                foreach (var lecturer in lecturers)
                {
                    LecturerModel lec = new LecturerModel();
                    lec.lecturerId = lecturer.lecturerId;
                    lec.fName      = lecturer.fName;
                    lec.lName      = lecturer.lName;
                    lec.email      = lecturer.User.email;

                    var teachings = db.Teachings.Where(t => t.lecturerId == lecturer.lecturerId);
                    foreach (var teaching in teachings)
                    {
                        lec.moduleList.Add(teaching.Module);
                    }

                    lecturerList.Add(lec);
                }
                return(lecturerList);
            }
        }
Beispiel #2
0
        public ActionResult Edit(ModuleModel updatedModule)
        {
            try
            {
                if (this.ModelState.IsValid)
                {
                    using (xinyuedbEntities db = new xinyuedbEntities())
                    {
                        var module = db.Modules.SingleOrDefault(x => x.moduleId == updatedModule.moduleId);
                        if (module != null)
                        {
                            module.name     = updatedModule.name;
                            module.degree   = updatedModule.degree;
                            module.year     = updatedModule.year;
                            module.semester = updatedModule.semester;

                            db.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(this.RedirectToAction("Index"));
        }
Beispiel #3
0
        public ActionResult Add(ModuleModel module)
        {
            try
            {
                if (this.ModelState.IsValid)
                {
                    using (xinyuedbEntities db = new xinyuedbEntities())
                    {
                        db.Modules.Add(new Module
                        {
                            name     = module.name,
                            degree   = module.degree,
                            year     = module.year,
                            semester = module.semester
                        });

                        db.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(this.RedirectToAction("Index"));
        }
Beispiel #4
0
        public static void editLecturer(int lecturerId, IEnumerable <string> selected_modules, string fname, string lname, string email)
        {
            using (xinyuedbEntities db = new xinyuedbEntities())
            {
                var lecturer = db.Lecturers.Where(l => l.lecturerId == lecturerId).FirstOrDefault();
                lecturer.User.email = email;
                lecturer.fName      = fname;
                lecturer.lName      = lname;

                var modules = db.Teachings.Where(t => t.lecturerId == lecturerId);
                db.Teachings.RemoveRange(modules);

                foreach (var module in selected_modules)
                {
                    Teaching teaching = new Teaching
                    {
                        lecturerId = lecturer.lecturerId,
                        moduleId   = Int32.Parse(module)
                    };
                    db.Teachings.Add(teaching);
                }

                db.SaveChanges();
            }
        }
Beispiel #5
0
        public ActionResult Delete(int id)
        {
            try
            {
                using (xinyuedbEntities db = new xinyuedbEntities())
                {
                    var module = db.Modules.SingleOrDefault(x => x.moduleId == id);
                    if (module != null)
                    {
                        var classes = db.Classes.Where(x => x.moduleId == id).ToList();
                        if (classes.Any())
                        {
                            foreach (var cla in classes)
                            {
                                var allocations = db.Allocations.Where(x => x.classId == cla.classId).ToList();
                                db.Allocations.RemoveRange(allocations);
                            }
                            db.Classes.RemoveRange(classes);
                        }

                        var teachings = db.Teachings.Where(x => x.moduleId == id).ToList();
                        db.Teachings.RemoveRange(teachings);

                        db.Modules.Remove(module);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(this.RedirectToAction("Index"));
        }
Beispiel #6
0
        public static void addLecturer(IEnumerable <string> selected_modules, string fname, string lname, string email, string password)
        {
            using (xinyuedbEntities db = new xinyuedbEntities())
            {
                User user = new User
                {
                    email       = email,
                    accountType = "lecturer",
                    password    = PasswordHash.HashPassword(password)
                };
                db.Users.Add(user);

                Lecturer lecturer = new Lecturer
                {
                    fName  = fname,
                    lName  = lname,
                    userId = user.userId,
                };
                db.Lecturers.Add(lecturer);

                foreach (var module in selected_modules)
                {
                    Teaching teaching = new Teaching
                    {
                        lecturerId = lecturer.lecturerId,
                        moduleId   = Int32.Parse(module)
                    };
                    db.Teachings.Add(teaching);
                }

                db.SaveChanges();
            }
        }
Beispiel #7
0
 public static bool getPublishState()
 {
     using (xinyuedbEntities db = new xinyuedbEntities())
     {
         var  config    = db.Configs.FirstOrDefault(c => c.name.Equals("published"));
         bool published = config.value != 0;
         return(published);
     }
 }
Beispiel #8
0
 public static void resetPassword(int lecturerId, string password)
 {
     using (xinyuedbEntities db = new xinyuedbEntities())
     {
         var lecturer = db.Lecturers.Where(l => l.lecturerId == lecturerId).FirstOrDefault();
         lecturer.User.password = PasswordHash.HashPassword(password);
         db.SaveChanges();
     }
 }
Beispiel #9
0
 public void changePublishState()
 {
     using (xinyuedbEntities db = new xinyuedbEntities())
     {
         var config = db.Configs.Where(c => c.name.Equals("published")).FirstOrDefault();
         config.value = config.value != 0 ? 0 : 1;
         db.SaveChanges();
     }
 }
Beispiel #10
0
        public void createAllocation()
        {
            xinyuedbEntities db = new xinyuedbEntities();

            if (db.Students.Any() && db.Classes.Where(x => x.type == "lab").Any())
            {
                allocateAlgorithm1(); //allocate for sememster 1
                allocateAlgorithm2(); //allocate for sememster 2
            }
        }
Beispiel #11
0
        public void deleteLecturer(int lecturerId)
        {
            using (xinyuedbEntities db = new xinyuedbEntities())
            {
                db.Teachings.RemoveRange(db.Teachings.Where(t => t.lecturerId == lecturerId));
                db.Users.Remove(db.Lecturers.Where(l => l.lecturerId == lecturerId).FirstOrDefault().User);
                db.Lecturers.Remove(db.Lecturers.Where(l => l.lecturerId == lecturerId).FirstOrDefault());

                db.SaveChanges();
            }
        }
Beispiel #12
0
 public void deleteApplication(int userId)
 {
     using (xinyuedbEntities db = new xinyuedbEntities())
     {
         var usr = db.Users.Find(userId);
         db.Users.Remove(usr);
         db.Students.Remove(db.Students.Where(s => s.userId == userId).FirstOrDefault());
         db.Preferences.RemoveRange(db.Preferences.Where(p => p.Student.userId == userId));
         db.Allocations.RemoveRange(db.Allocations.Where(a => a.Student.userId == userId));
         db.SaveChanges();
     }
 }
Beispiel #13
0
        public static void saveWeight(int prefWeight, int yearWeight, int stuWeight)
        {
            using (xinyuedbEntities db = new xinyuedbEntities())
            {
                var config = db.Configs;
                config.Where(c => c.name.Equals("prefWeight")).FirstOrDefault().value = prefWeight;
                config.Where(c => c.name.Equals("yearWeight")).FirstOrDefault().value = yearWeight;
                config.Where(c => c.name.Equals("stuWeight")).FirstOrDefault().value  = stuWeight;

                db.SaveChanges();
            }
        }
Beispiel #14
0
 public static void deleteClass(int classId)
 {
     using (xinyuedbEntities db = new xinyuedbEntities())
     {
         // remember to delete class from "preference" and "allocation" table
         var cla = db.Classes.Where(c => c.classId == classId).FirstOrDefault();
         if (cla != null)
         {
             db.Classes.Remove(cla);
             db.SaveChanges();
         }
     }
 }
Beispiel #15
0
 public static Object checkOldPassword(int lecturerId, string password)
 {
     using (xinyuedbEntities db = new xinyuedbEntities())
     {
         var result   = new Object();
         var lecturer = db.Lecturers.Where(l => l.lecturerId == lecturerId).FirstOrDefault();
         result = (new
         {
             valid = PasswordHash.ValidatePassword(password, lecturer.User.password)
         });
         return(result);
     }
 }
Beispiel #16
0
        public static void saveStudentsForMultiselectList(IEnumerable <string> selected_students, int classId)
        {
            using (xinyuedbEntities db = new xinyuedbEntities())
            {
                var    lab       = db.Classes.Where(c => c.classId == classId).FirstOrDefault();
                double classTime = (lab.endTime - lab.startTime).TotalHours;

                //remove old allocations
                var allocations = db.Allocations.Where(a => a.classId == classId);
                foreach (var allocation in allocations)
                {
                    var oldstudent = db.Students.Where(s => s.studentId == allocation.studentId).FirstOrDefault();
                    if (lab.Module.semester == 1)
                    {
                        oldstudent.workingHour1 -= classTime;
                    }
                    else
                    {
                        oldstudent.workingHour2 -= classTime;
                    }
                }
                db.Allocations.RemoveRange(allocations);

                //store new allocations
                if (selected_students != null)
                {
                    foreach (var stu in selected_students)
                    {
                        int studentId = Int32.Parse(stu);

                        Allocation allo = new Allocation();
                        allo.classId   = classId;
                        allo.studentId = studentId;
                        db.Allocations.Add(allo);

                        var newstudent = db.Students.Where(s => s.studentId == studentId).FirstOrDefault();
                        if (lab.Module.semester == 1)
                        {
                            newstudent.workingHour1 += classTime;
                        }
                        else
                        {
                            newstudent.workingHour2 += classTime;
                        }
                    }
                }

                db.SaveChanges();
            }
        }
Beispiel #17
0
        public void clearStudentData()
        {
            using (xinyuedbEntities db = new xinyuedbEntities())
            {
                db.Students.RemoveRange(db.Students);
                db.Preferences.RemoveRange(db.Preferences);
                db.Allocations.RemoveRange(db.Allocations);
                db.Users.RemoveRange(db.Users.Where(x => x.accountType == "student"));
                var config = db.Configs.Where(c => c.name.Equals("published")).FirstOrDefault();
                config.value = 0;

                db.SaveChanges();
            }
        }
Beispiel #18
0
        public static void updateClass(int classId, int moduleId, string type, int tutorNumber)
        {
            using (xinyuedbEntities db = new xinyuedbEntities())
            {
                var cla = db.Classes.FirstOrDefault(c => c.classId == classId);
                if (cla != null)
                {
                    cla.moduleId    = moduleId;
                    cla.type        = type;
                    cla.tutorNumber = tutorNumber;

                    db.SaveChanges();
                }
            }
        }
Beispiel #19
0
 public void deleteAllocation()
 {
     using (xinyuedbEntities db = new xinyuedbEntities())
     {
         var students = db.Students;
         foreach (var student in students)
         {
             student.workingHour1 = 0;
             student.workingHour2 = 0;
         }
         db.Allocations.RemoveRange(db.Allocations);
         var config = db.Configs.Where(c => c.name.Equals("published")).FirstOrDefault();
         config.value = 0;
         db.SaveChanges();
     }
 }
Beispiel #20
0
        public static Object getNImaxHour(int studentId)
        {
            using (xinyuedbEntities db = new xinyuedbEntities())
            {
                var stu = db.Students.Where(s => s.studentId == studentId).FirstOrDefault();

                var NImaxHour = new Object();

                NImaxHour = (new
                {
                    ni = stu.NI,
                    maxHour = stu.maxHour
                });
                return(NImaxHour);
            }
        }
Beispiel #21
0
        public static Object getWeight()
        {
            using (xinyuedbEntities db = new xinyuedbEntities())
            {
                var weights = new Object();
                var config  = db.Configs;

                weights = (new
                {
                    prefWeight = config.Where(c => c.name.Equals("prefWeight")).FirstOrDefault().value,
                    yearWeight = config.Where(c => c.name.Equals("yearWeight")).FirstOrDefault().value,
                    stuWeight = config.Where(c => c.name.Equals("stuWeight")).FirstOrDefault().value
                });

                return(weights);
            }
        }
Beispiel #22
0
 public static List <Object> getModules(int year, int semester)
 {
     using (xinyuedbEntities db = new xinyuedbEntities())
     {
         var modules    = db.Modules.Where(m => m.year == year).Where(m => m.semester == semester);
         var moduleList = new List <Object>();
         foreach (var module in modules)
         {
             moduleList.Add(new
             {
                 title    = module.name,
                 moduleId = module.moduleId
             });
         }
         return(moduleList);
     }
 }
Beispiel #23
0
        public ActionResult Index()
        {
            var modules = new List <ModuleModel>();

            using (xinyuedbEntities db = new xinyuedbEntities())
            {
                modules = db.Modules.Select(x => new ModuleModel
                {
                    moduleId = x.moduleId,
                    name     = x.name,
                    degree   = x.degree,
                    year     = x.year,
                    semester = x.semester
                }).ToList();
            }

            return(View("Index", modules));
        }
Beispiel #24
0
        public JsonResult Edit(int id)
        {
            using (xinyuedbEntities db = new xinyuedbEntities())
            {
                var module    = db.Modules.SingleOrDefault(x => x.moduleId == id);
                var viewModel = new ModuleModel
                {
                    moduleId = module.moduleId,
                    name     = module.name,
                    degree   = module.degree,
                    year     = module.year,
                    semester = module.semester
                };

                var result = JsonConvert.SerializeObject(viewModel);

                return(this.Json(result, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #25
0
        //public void getAllClasses(int userId)
        //{
        //    using (xinyuedbEntities db = new xinyuedbEntities())
        //    {
        //        var usr = db.Users.Find(userId);

        //        student = db.Students.Where(s => s.userId == usr.userId).FirstOrDefault();

        //        List<ClassInfo> myClass = getMyClass();

        //        getLabClass(myClass);

        //    }

        //}


        //public List<ClassInfo> getMyClass()
        //{
        //    using (xinyuedbEntities db = new xinyuedbEntities())
        //    {
        //        var myModules = db.Modules.Where(m => m.degree.Contains(student.degree) && m.year == student.year);

        //        List<ClassInfo> myClass = new List<ClassInfo>();
        //        foreach (var m in myModules)
        //        {
        //            var myCla = db.Classes.Where(c => c.moduleId == m.moduleId);
        //            foreach (var c in myCla)
        //            {
        //                ClassInfo cla = new ClassInfo();
        //                cla.moduleId = m.moduleId;
        //                cla.title = m.name;
        //                cla.classId = c.classId;

        //                cla.startTime = c.startTime.ToString("yyyy-MM-ddTHH:mm:ss");
        //                cla.endTime = c.endTime.ToString("yyyy-MM-ddTHH:mm:ss");
        //                myClass.Add(cla);//add to a list which contains only the classes this applicant is studying

        //                cla.myclass = true;
        //                classInfo.Add(cla);//add to a list which contains all classes presented on the view timetable, including classes that can be selected and classes that this applicant is studying
        //            }
        //        }

        //        return myClass;
        //    }

        //}


        //public void getLabClass(List<ClassInfo> myClass)
        //{
        //    using (xinyuedbEntities db = new xinyuedbEntities())
        //    {
        //        var grades = db.Grades.Where(g => g.studentId == student.studentId); // only get classes that the applicant has studied (have grades for it)

        //        foreach (var g in grades)
        //        {
        //            if (g.Module.year < student.year) //choose from classes that are lower year classes
        //            {
        //                var classes = db.Classes.Where(c => c.moduleId == g.Module.moduleId).Where(c => c.type == "lab");

        //                foreach (var c in classes)
        //                {
        //                    bool noTimeClash = true;
        //                    for (int i = 0; i < myClass.Count(); i++)
        //                    {
        //                        // (myClass[i] ends before this class starts) || (myClass[i] starts after this class ends)
        //                        if (!((DateTime.Compare(DateTime.Parse(myClass[i].endTime), c.startTime) <= 0) || (DateTime.Compare(DateTime.Parse(myClass[i].startTime), c.endTime) >= 0)))
        //                        {
        //                            noTimeClash = false;

        //                            ClassInfo cla = new ClassInfo();
        //                            cla.title = g.Module.name;
        //                            cla.classId = c.classId;
        //                            cla.startTime = c.startTime.ToString("yyyy-MM-ddTHH:mm:ss");
        //                            cla.endTime = c.endTime.ToString("yyyy-MM-ddTHH:mm:ss");
        //                            cla.myclass = false;
        //                            cla.moduleId = g.moduleId;
        //                            timeClashClass.Add(cla);
        //                            break;
        //                        }
        //                    }

        //                    if (noTimeClash)
        //                    {
        //                        ClassInfo cla = new ClassInfo();
        //                        cla.title = g.Module.name;
        //                        cla.classId = c.classId;
        //                        cla.startTime = c.startTime.ToString("yyyy-MM-ddTHH:mm:ss");
        //                        cla.endTime = c.endTime.ToString("yyyy-MM-ddTHH:mm:ss");
        //                        cla.myclass = false;
        //                        cla.moduleId = g.moduleId;
        //                        classInfo.Add(cla);
        //                    }

        //                }
        //            }
        //        }
        //    }
        //}


        //public void addApplication(int userId)
        //{
        //    using (xinyuedbEntities db = new xinyuedbEntities())
        //    {
        //        var usr = db.Users.Find(userId);
        //        Student stu = new Student();
        //        stu = db.Students.Where(s => s.userId == usr.userId).FirstOrDefault();
        //        stu.maxHour = student.maxHour;
        //        stu.NI = student.NI;
        //        stu.applied = true;
        //        db.SaveChanges();

        //    }
        //}

        public void readApplication(int userId)
        {
            using (xinyuedbEntities db = new xinyuedbEntities())
            {
                var usr = db.Users.Find(userId);

                student = db.Students.Where(s => s.userId == usr.userId).FirstOrDefault();

                var pref = db.Preferences.Where(p => p.studentId == student.studentId);

                //var grades = db.Grades.Where(g => g.studentId == student.studentId);

                //foreach (var item in grades)
                //{
                //    if (item.Module.year < student.year)
                //    {
                //        var result = db.Classes.Where(c => c.moduleId == item.Module.moduleId);

                //        foreach (var i in result)
                //        {
                //            ClassInfo cla = new ClassInfo();
                //            cla.title = item.Module.name;
                //            cla.classId = i.classId;
                //            cla.startTime = i.startTime.ToString("yyyy-MM-ddTHH:mm:ss");
                //            cla.endTime = i.endTime.ToString("yyyy-MM-ddTHH:mm:ss");
                //            cla.prefered = "neutral";
                //            foreach (var p in pref)
                //            {
                //                if (p.classId == cla.classId)
                //                {
                //                    if (p.prefered.Equals("liked")) { cla.prefered = "liked"; }
                //                    else if (p.prefered.Equals("disliked")) { cla.prefered = "disliked"; }
                //                    else if (p.prefered.Equals("neutral")) { cla.prefered = "neutral"; }
                //                }
                //            }
                //            classInfo.Add(cla);
                //        }
                //    }

                //}
            }
        }
Beispiel #26
0
        public static Object getClassInfo(int classId)
        {
            using (xinyuedbEntities db = new xinyuedbEntities())
            {
                var classInfo = new Object();
                var lab       = db.Classes.Where(c => c.classId == classId).FirstOrDefault();

                var tutors      = new List <Object>();
                var allocations = db.Allocations.Where(a => a.classId == classId);
                if (allocations != null)
                {
                    foreach (var allo in allocations)
                    {
                        tutors.Add(new
                        {
                            name         = allo.Student.fName + " " + allo.Student.lName,
                            matricNumber = allo.Student.matricNumber,
                            degree       = allo.Student.degree,
                            year         = allo.Student.year,
                            email        = allo.Student.User.email
                        });
                    }
                }
                else
                {
                    tutors = null;
                }


                classInfo = (new
                {
                    year = lab.Module.year,
                    degree = lab.Module.degree,
                    module = lab.Module.name,
                    semester = lab.Module.semester,
                    time = lab.startTime.ToString("dddd HH:mm") + " ~ " + lab.endTime.ToString("HH:mm"),
                    tutors = tutors
                });

                return(classInfo);
            }
        }
Beispiel #27
0
        public static void updateEventTime(int classId, string newStart, string newEnd)
        {
            // EventStart comes ISO 8601 format, eg:  "2000-01-10T10:00:00Z" - need to convert to DateTime
            using (xinyuedbEntities db = new xinyuedbEntities())
            {
                var cla = db.Classes.FirstOrDefault(c => c.classId == classId);
                if (cla != null)
                {
                    newStart = newStart.Replace("GMT+0000", "").Trim();
                    newEnd   = newEnd.Replace("GMT+0000", "").Trim();
                    newStart = newStart.Insert(3, ",");
                    newEnd   = newEnd.Insert(3, ",");

                    cla.startTime = DateTime.Parse(newStart, null, DateTimeStyles.RoundtripKind);
                    cla.endTime   = DateTime.Parse(newEnd, null, DateTimeStyles.RoundtripKind);

                    db.SaveChanges();
                }
            }
        }
Beispiel #28
0
        public JsonResult Login(string email, string password)
        {
            using (xinyuedbEntities db = new xinyuedbEntities())
            {
                var usr = db.Users.Where(u => u.email == email).FirstOrDefault();
                if (usr != null)
                {
                    bool validPassword = PasswordHash.ValidatePassword(password, usr.password);
                    if (validPassword)
                    {
                        Session["userId"] = usr.userId.ToString();
                        if (usr.accountType.Equals("coordinator"))
                        {
                            Session["name"] = "Coordinator";
                        }
                        else if (usr.accountType.Equals("student"))
                        {
                            Session["name"] = db.Students.Where(s => s.userId == usr.userId).FirstOrDefault().lName;
                        }
                        else
                        {
                            var lecturer = db.Lecturers.Where(l => l.userId == usr.userId).FirstOrDefault();
                            Session["name"]   = lecturer.lName;
                            Session["userId"] = lecturer.lecturerId.ToString();
                        }

                        Session["account"] = usr.accountType.ToString();
                        return(Json(new { success = true, account = usr.accountType.ToString() }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
                }
            }
        }
Beispiel #29
0
        public JsonResult Register(string email, string password, string first_name, string last_name, int matric_number, string degree, int level)
        {
            using (xinyuedbEntities db = new xinyuedbEntities())
            {
                var existing_user    = db.Users.Where(u => u.email == email);
                var existing_student = db.Students.Where(s => s.matricNumber == matric_number);

                if (existing_student.Any() || existing_user.Any())
                {
                    return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    User user = new User();
                    user.email       = email;
                    user.password    = PasswordHash.HashPassword(password);
                    user.accountType = "student";
                    db.Users.Add(user);

                    Student student = new Student();
                    student.userId       = user.userId;
                    student.fName        = first_name;
                    student.lName        = last_name;
                    student.matricNumber = matric_number;
                    student.degree       = degree;
                    student.year         = level;
                    student.maxHour      = 4;
                    student.applied      = true;
                    db.Students.Add(student);

                    db.SaveChanges();

                    Session["account"] = "student";
                    Session["userId"]  = user.userId.ToString();
                    Session["name"]    = first_name;
                    return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
                }
            }
        }
Beispiel #30
0
        public static List <Object> getModules()
        {
            using (xinyuedbEntities db = new xinyuedbEntities())
            {
                var moduleList = new List <Object>();
                var modules    = db.Modules;

                foreach (var module in modules)
                {
                    moduleList.Add(new
                    {
                        value = module.moduleId,
                        label = module.name,
                        title = "Year: " + module.year + "\n" +
                                "Degree: " + module.degree + "\n" +
                                "Semester: " + module.semester
                    });
                }

                return(moduleList);
            }
        }