public ActionResult AddRegistration(FormCollection form)
        {
            StudentCours  sc          = new StudentCours();
            List <string> displayList = GetDisplayList();

            gds = new LMS_GRINDEntities1();
            string selectedItem = form["ddCourses"].ToString();
            var    courseList   = gds.Courses.ToList();
            int    index        = GetSelectedIndex(displayList, selectedItem);

            sc.course_id  = courseList[index].course_id;
            sc.student_id = Name.user_id;

            // check database for specified course id and student id
            var ret = (from s in gds.StudentCourses
                       where s.student_id == Name.user_id
                       where s.course_id == sc.course_id
                       select s).Count();

            if (ret > 0)
            {
                ViewBag.Message = "Could not register for course. You are already registered.";
                return(ViewRegistration(""));
            }
            else
            {
                gds.StudentCourses.Add(sc);
                gds.SaveChanges();
                CourseCardList.GenerateStudentCourseList();
                ToDoList.GenerateStudentToDoList();

                return(RedirectToAction("ReturnToView", "UserAccount", null));
            }
        }
        public ActionResult Unregister(FormCollection form) // TODO: Validation - verify user is enrolled in class before removing
        {
            gds = new LMS_GRINDEntities1();
            List <string> displayList  = GetDisplayList();
            var           courseList   = gds.Courses.ToList();
            string        selectedItem = form["ddCourses"].ToString(); // Item selected from dropdown
            int           index        = 0;

            try
            {
                // determine index of selected item
                index = GetSelectedIndex(displayList, selectedItem);

                // create a list of StudentCourses sc
                var sc = gds.StudentCourses.ToList();

                // query sc for the course to be unregistered and store in id
                var course = sc.First(x => x.student_id == Name.user_id && x.course_id == courseList[index].course_id);

                gds.StudentCourses.Remove(course);

                //Save the changes
                gds.SaveChanges();

                // update list and return to StudentView
                CourseCardList.GenerateStudentCourseList();
                ToDoList.GenerateStudentToDoList();
                return(RedirectToAction("ReturnToView", "UserAccount", null));
            }
            catch
            {
                ViewBag.Message = "Could not unregister from course because no registration exists";
                return(ViewRegistration(""));
            }
        }
        /// <summary>
        /// Display course details for student
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Display details of the selected course</returns>
        public ActionResult StudentCourseDetail(int id)
        {
            gds = new LMS_GRINDEntities1();
            Cours      course              = gds.Courses.Where(x => x.course_id == id).FirstOrDefault();
            int        ic_id               = gds.InstructorCourses.Where(x => x.course_id == id).Select(x => x.instructor_course_id).FirstOrDefault();
            Department department          = gds.Departments.Where(x => x.dept_id == course.dept_id).FirstOrDefault();
            int        instructorId        = gds.InstructorCourses.Where(x => x.instructor_course_id == ic_id).Select(x => x.instructor_id).FirstOrDefault();
            String     instructorFirstName = gds.ulUsers.Where(x => x.ulUser_id == instructorId).Select(x => x.first_name).FirstOrDefault();
            String     instructorLastName  = gds.ulUsers.Where(x => x.ulUser_id == instructorId).Select(x => x.last_name).FirstOrDefault();

            CourseCardList.GenerateStudentCourseList();
            AssignmentList.GenerateStudentAssignmentList(id);
            AssignmentList.GenerateThisStudentsSubmissions(Name.user_id);
            AssignmentList.GenerateThisStudentsSubmissionsForCourse(Name.user_id, ic_id);

            StudentCours studentCours = gds.StudentCourses.Where(x => (x.course_id == course.course_id) && (x.student_id == Name.user_id)).FirstOrDefault();

            // Calculate overall points
            int    maxPoints   = 0;
            int    points      = 0;
            double?gradePoints = 0;

            if (AssignmentList.StudentAssignments.Any())
            {
                foreach (var assignment in AssignmentList.StudentAssignments)
                {
                    AssignmentList.GenerateThisStudentsSubmissionForAssignment(assignment.AssignmentId);
                    if (AssignmentList.StudentAssignmentSubmission.isGraded)
                    {
                        points    += (int)AssignmentList.StudentAssignmentSubmission.Grade;
                        maxPoints += (int)assignment.MaxPoints;
                    }
                }

                ViewBag.points    = points;
                ViewBag.maxPoints = maxPoints;
                // Get letter grade
                gradePoints = ((double)points / maxPoints) * 100;
                // Display 2 decimal places
                gradePoints = Math.Truncate(100 * (double)gradePoints) / 100;
                if (gradePoints >= 0)
                {
                    ViewBag.gradePercentage = gradePoints + "%";  // Display percentage
                }
                else
                {
                    ViewBag.gradePercentage = " ";
                }
            }

            AssignmentList.GenerateThisStudentsSubmissionsForCourse(Name.user_id, ic_id);
            ViewBag.letterGrade      = studentCours.letter_grade; // Display letter grade
            ViewBag.selectedCourse   = course;
            ViewBag.courseDepartment = department;
            ViewBag.InstructorName   = instructorFirstName + " " + instructorLastName;

            return(View("StudentCourseDetailView"));
        }
Exemple #4
0
        public ActionResult Verify(User u)
        {
            //Encrypt password functionality
            byte[] data = System.Text.Encoding.ASCII.GetBytes(u.Password);
            data = new System.Security.Cryptography.SHA256Managed().ComputeHash(data);
            String hash = System.Text.Encoding.ASCII.GetString(data);

            gds = new LMS_GRINDEntities1();
            var query = gds.ulUsers.Where(x => x.email_address == u.Email && x.user_password == hash);

            if (query.Any())
            {
                foreach (ulUser user in query)
                {
                    // Set static name variables
                    Name.user_id       = user.ulUser_id;
                    Name.first_name    = user.first_name;
                    Name.last_name     = user.last_name;
                    Name.role          = user.role;
                    Name.email         = user.email_address;
                    Name.birthdate     = user.birthdate;
                    Name.streetAddress = user.street_address;
                    Name.phoneNum      = user.phone_num;
                    Name.bio           = user.bio;
                    Name.link1         = user.link1;
                    Name.link2         = user.link2;
                    Name.link3         = user.link3;
                    Name.profileImage  = user.profileImage;
                    Name.linkTitle1    = user.linkTitle1;
                    Name.linkTitle2    = user.linkTitle2;
                    Name.linkTitle3    = user.linkTitle3;
                }

                if (Name.role == "Student")
                {
                    ViewBag.ErrorMessage = "";
                    ToDoList.GenerateStudentToDoList();
                    CourseCardList.GenerateStudentCourseList();
                    return(View("StudentView"));
                }
                else
                {
                    ViewBag.ErrorMessage = "";
                    ToDoList.GenerateInstructorToDoList();
                    CourseCardList.GenerateInstructorCourseList();
                    return(View("InstructorView"));
                }
            }
            else
            {
                ViewBag.ErrorMessage = "Incorrect user credentials or account not yet created";
                return(View("Login"));
            }
        }