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("")); } }
public ActionResult DeleteCourse(int id) { cs = new CourseRegistration(); cs.DeleteCourse2(id); CourseCardList.GenerateInstructorCourseList(); return(RedirectToAction("InstructorCView")); }
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)); } }
/// <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")); }
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")); } }
public ActionResult InstructorAssignment(int id) { gds = new LMS_GRINDEntities1(); var courseNum = gds.Courses.Where(x => x.course_id == id).Select(x => x.course_num).FirstOrDefault(); var courseName = gds.Courses.Where(x => x.course_id == id).Select(x => x.course_name).FirstOrDefault(); CourseCardList.GenerateInstructorCourseList(); AssignmentList.GenerateInstructorAssignmentList(id); @ViewBag.CourseId = id; @ViewBag.CourseNum = courseNum; @ViewBag.CourseName = courseName; return(View("InstructorAssignmentView")); }
public void SaveCourse2(string courseNum, string courseName, string courseDesc, int courseCredits, int maxCapacity, string courseLocation, int courseRoom, int departments, string monday, string tuesday, string wednesday, string thursday, string friday, TimeSpan startTime, TimeSpan endTime, int instructor_id) { LMS_GRINDEntities1 gds = new LMS_GRINDEntities1(); Cours course = new Cours(); course.course_name = courseName; Course.courseName = courseName; course.course_desc = courseDesc; Course.courseDesc = courseDesc; course.course_num = courseNum; Course.courseNum = courseNum; course.max_capacity = maxCapacity; Course.maxCapacity = maxCapacity; course.dept_id = departments; course.num_credits = courseCredits; Course.numCredits = courseCredits; course.days_of_week = monday + tuesday + wednesday + thursday + friday; Course.meetingDays = monday + tuesday + wednesday + thursday + friday; course.start_time = startTime; Course.startTime = startTime; course.end_time = endTime; Course.endTime = endTime; course.building = courseLocation; Course.location = courseLocation; course.room_no = courseRoom; Course.roomNum = courseRoom; gds.Courses.Add(course); gds.SaveChanges(); Course.courseId = course.course_id; InstructorCours insCourse = new InstructorCours(); InstructorCourseContext.courseId = course.course_id; insCourse.course_id = course.course_id; InstructorCourseContext.instructorId = instructor_id; insCourse.instructor_id = instructor_id; Course.instructorFullName = Name.first_name + " " + Name.last_name; Course.instructorLastName = Name.last_name; Course.instructorFirstName = Name.first_name; gds.InstructorCourses.Add(insCourse); gds.SaveChanges(); CourseCardList.GenerateInstructorCourseList(); }
public ActionResult InstructorCview(string search) { gds = new LMS_GRINDEntities1(); var departments = (from d in gds.Departments // select all departments select d); if (!String.IsNullOrEmpty(search)) { departments = departments.Where(x => x.dept_name.Contains(search)); // filter based on search } CourseCardList.GenerateInstructorCourseList(); return(View("InstructorCview", departments.ToList().OrderBy(x => x.dept_name))); }
public ActionResult SaveAssignment(string assignmentName, string assignmentDesc, int maxPoints, DateTime dueDate, string assignmentType, string submissionType) { var courseId = int.Parse(Request.Form["CourseId"]); var courseNum = Request.Form["CourseNum"]; var courseName = Request.Form["CourseName"]; gds = new LMS_GRINDEntities1(); Assignment newAssignment = new Assignment(); var query = from course in gds.Courses join insCourse in gds.InstructorCourses on course.course_id equals insCourse.course_id where course.course_id == courseId select new { instructorCourseID = insCourse.instructor_course_id }; foreach (var insCourse in query) { newAssignment.instructor_course_id = insCourse.instructorCourseID; } newAssignment.assignment_name = assignmentName; newAssignment.assignment_desc = assignmentDesc; newAssignment.max_points = maxPoints; newAssignment.due_date = dueDate; newAssignment.assignment_type = assignmentType; newAssignment.submission_type = submissionType; gds.Assignments.Add(newAssignment); gds.SaveChanges(); AssignmentList.GenerateInstructorAssignmentList(courseId); CourseCardList.GenerateInstructorCourseList(); @ViewBag.CourseNum = courseNum; @ViewBag.CourseName = courseName; @ViewBag.CourseId = courseId; ToDoList.GenerateInstructorToDoList(); return(RedirectToAction("InstructorCourseDetail", "CoursesAndRegistration", new { id = courseId })); }
public ActionResult UpdateCourse(int id, string courseNum, string courseName, string courseDesc, int courseCredits, int maxCapacity, string courseLocation, int courseRoom, int departments, string monday, string tuesday, string wednesday, string thursday, string friday, TimeSpan startTime, TimeSpan endTime) { gds = new LMS_GRINDEntities1(); Cours course = gds.Courses.Where(x => x.course_id == id).FirstOrDefault(); try { course.course_name = courseName; course.course_desc = courseDesc; course.course_num = courseNum; course.max_capacity = maxCapacity; course.dept_id = departments; course.num_credits = courseCredits; course.days_of_week = monday + tuesday + wednesday + thursday + friday; course.start_time = startTime; course.end_time = endTime; course.building = courseLocation; course.room_no = courseRoom; ViewBag.selectedCourse = course; Department department = gds.Departments.Where(x => x.dept_id == course.dept_id).FirstOrDefault(); ViewBag.courseDepartment = department; gds.SaveChanges(); CourseCardList.GenerateInstructorCourseList(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { System.Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } catch { return(View("EditCourseView")); } return(View("InstructorCourseInformationView")); //return View("InstructorCview"); }
public ActionResult DeleteAssignment(int id) { gds = new LMS_GRINDEntities1(); Assignment assignment = gds.Assignments.Where(x => x.assignment_id == id).FirstOrDefault(); int insCourse = gds.Assignments.Where(x => x.assignment_id == id).Select(x => x.instructor_course_id).FirstOrDefault(); int courseId = gds.InstructorCourses.Where(x => x.instructor_course_id == insCourse).Select(x => x.course_id).FirstOrDefault(); var courseNum = gds.Courses.Where(x => x.course_id == courseId).Select(x => x.course_num).FirstOrDefault(); var courseName = gds.Courses.Where(x => x.course_id == courseId).Select(x => x.course_name).FirstOrDefault(); gds.Assignments.Remove(assignment); gds.SaveChanges(); //Delete from assignments table, and student assignments table //TODO: implement delete from studentAssignments table' ViewBag.CourseNum = courseNum; ViewBag.CourseName = courseName; ViewBag.CourseId = courseId; AssignmentList.GenerateInstructorAssignmentList(courseId); CourseCardList.GenerateInstructorCourseList(); ToDoList.GenerateInstructorToDoList(); return(RedirectToAction("InstructorCourseDetail", "CoursesAndRegistration", new { id = courseId })); }
/// <summary> /// Display course details for instructor /// </summary> /// <param name="id"></param> /// <returns>Display details of the selected course</returns> public ActionResult InstructorCourseDetail(int id) { gds = new LMS_GRINDEntities1(); Cours course = gds.Courses.Where(x => x.course_id == id).FirstOrDefault(); Department department = gds.Departments.Where(x => x.dept_id == course.dept_id).FirstOrDefault(); int ic_id = gds.InstructorCourses.Where(x => x.course_id == id).Select(x => x.instructor_course_id).FirstOrDefault(); CourseCardList.GenerateInstructorCourseList(); AssignmentList.GenerateInstructorAssignmentList(id); // Calculate overall spread of letter grades for students in course LetterGradeList.GenerateCourseLetterGrades(id); ViewBag.percentA = LetterGradeList.PercentA; ViewBag.percentB = LetterGradeList.PercentB; ViewBag.percentC = LetterGradeList.PercentC; ViewBag.percentD = LetterGradeList.PercentD; ViewBag.percentF = LetterGradeList.PercentF; ViewBag.percentUngraded = LetterGradeList.PercentUngraded; ViewBag.selectedCourse = course; ViewBag.courseDepartment = department; return(View("InstructorCourseDetailView")); }