public ActionResult SubmitAssignment(string text_submission, HttpPostedFileBase assignment_file)
        {
            gds = new LMS_GRINDEntities1();
            StudentAssignment sa = new StudentAssignment();

            if (AssignmentList.AssignmentItem.SubmissionType == "File")
            {
                if (assignment_file != null)
                {
                    var instructor = (from ic in gds.InstructorCourses
                                      where ic.instructor_course_id == AssignmentList.AssignmentItem.InstructorCourseId
                                      select ic).First();

                    var instructor_l_name = (from i in gds.ulUsers
                                             where i.ulUser_id == instructor.instructor_id
                                             select i).First();

                    string course_directory  = instructor_l_name.last_name + "_" + AssignmentList.AssignmentItem.CourseNum;
                    string student_directory = Name.first_name + Name.last_name;
                    string file_name         = Path.GetFileNameWithoutExtension(assignment_file.FileName) +
                                               DateTime.Now.ToString("yymmssfff") +
                                               Path.GetExtension(assignment_file.FileName);

                    // Set file path to the course directory within the Assignment Submissions folder
                    string file_path = Path.Combine(Server.MapPath("~/AssignmentSubmissions/"), file_name);

                    sa.file_submission = "~/AssignmentSubmissions/" + file_name;
                    sa.assignment_id   = AssignmentList.AssignmentItem.AssignmentId;
                    sa.student_id      = Name.user_id;
                    sa.submission_date = DateTime.Now;
                    assignment_file.SaveAs(file_path);

                    gds.StudentAssignments.Add(sa);
                    gds.SaveChanges();

                    ViewBag.IsSubmitted = true;
                }
                else
                {
                    ViewBag.IsSubmitted = false;
                }
            }
            else // TEXT SUBMISSION
            {
                sa.text_submission = text_submission;
                sa.assignment_id   = AssignmentList.AssignmentItem.AssignmentId;
                sa.student_id      = Name.user_id;
                sa.submission_date = DateTime.Now;

                gds.StudentAssignments.Add(sa);
                gds.SaveChanges();
                ViewBag.IsSubmitted = true;
            }

            ToDoList.GenerateStudentToDoList();
            return(View("StudentAssignmentView"));
        }
        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 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));
            }
        }
Пример #4
0
        public ActionResult SubmitGradeAssignment(int assignmentGradeId, int grade, string instructorFeedback)
        {
            gds = new LMS_GRINDEntities1();
            //Save grade to database
            StudentAssignment stuAssignment = gds.StudentAssignments.Where(x => x.assignment_grade_id == assignmentGradeId).FirstOrDefault();
            int?id    = gds.StudentAssignments.Where(x => x.assignment_grade_id == assignmentGradeId).Select(x => x.assignment_id).FirstOrDefault();
            int ic_id = gds.Assignments.Where(x => x.assignment_id == id).Select(x => x.instructor_course_id).FirstOrDefault();

            try
            {
                stuAssignment.grade = grade;
                stuAssignment.instructor_feedback = instructorFeedback;
                gds.SaveChanges();
                AssignmentList.GenerateThisStudentsSubmissionsForCourse(stuAssignment.student_id, ic_id);
            }
            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("GradeAssignmentView"));
            }
            return(RedirectToAction("InstructorGrading", new { assignmentId = id }));
        }
        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 }));
        }
        public ActionResult UpdateAssignment(int id, string assignmentName, string assignmentDesc, int maxPoints,
                                             DateTime dueDate, string assignmentType, string submissionType)
        {
            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();

            try
            {
                assignment.assignment_name = assignmentName;
                assignment.assignment_desc = assignmentDesc;
                assignment.max_points      = maxPoints;
                assignment.due_date        = dueDate;
                assignment.assignment_type = assignmentType;
                assignment.submission_type = submissionType;
                gds.SaveChanges();
            }
            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("EditAssignmentView"));
            }

            AssignmentList.GenerateInstructorAssignmentList(courseId);
            return(RedirectToAction("InstructorCourseDetail", "CoursesAndRegistration", new { id = courseId }));
        }
Пример #9
0
        //This method returns all of the submissions by a particular student with the parameter id
        //Generates a list of StudentAssignmentSubmissionItems
        public static void GenerateThisStudentsSubmissionsForCourse(int?studentId, int instructorCourseId)
        {
            ThisStudentsSubmissions = new List <StudentAssignmentSubmissionItem>();
            LMS_GRINDEntities1 gds = new LMS_GRINDEntities1();

            int totalPoints = 0;
            int maxPoints   = 0;

            var query = (from a in gds.Assignments
                         //join ic in gds.InstructorCourses on a.instructor_course_id equals ic.instructor_course_id
                         join sa in gds.StudentAssignments on a.assignment_id equals sa.assignment_id
                         join sc in gds.StudentCourses on sa.student_id equals sc.student_id
                         where sa.student_id == studentId
                         where a.instructor_course_id == instructorCourseId
                         select new
            {
                AssignmentGradeId = sa.assignment_grade_id,
                //AssignmentId = sa.assignment_id,
                StudentId = sa.student_id,
                Grade = sa.grade,

                /*InstructorFeedback = sa.instructor_feedback,
                 * SubmissionDate = sa.submission_date,
                 * TextSubmission = sa.text_submission,
                 * FileSubmission = sa.file_submission,*/
                MaxPoints = a.max_points
            }).ToList();

            int i = 0;

            foreach (var item in query)
            {
                ThisStudentsSubmissions.Add(new StudentAssignmentSubmissionItem());
                ThisStudentsSubmissions[i].AssignmentGradeId = item.AssignmentGradeId;
                //ThisStudentsSubmissions[i].AssignmentId = item.AssignmentId;
                ThisStudentsSubmissions[i].StudentId = item.StudentId;
                ThisStudentsSubmissions[i].Grade     = item.Grade;

                //ThisStudentsSubmissions[i].MaxPoints = (int)item.MaxPoints;

                /*ThisStudentsSubmissions[i].SubmissionDate = (DateTime)item.SubmissionDate;
                 * ThisStudentsSubmissions[i].TextSubmission = item.TextSubmission;
                 * ThisStudentsSubmissions[i].FileSubmission = item.FileSubmission;
                 * ThisStudentsSubmissions[i].InstructorFeedback = item.InstructorFeedback;*/

                if (item.Grade != null)
                {
                    ThisStudentsSubmissions[i].isGraded = true;
                    totalPoints += (int)item.Grade;     // Total points for all graded assignements
                    maxPoints   += (int)item.MaxPoints; // Max points for all graded assignments
                }
                else
                {
                    ThisStudentsSubmissions[i].isGraded = false;
                }
                i++;
            }
            //Calculate letter grade and save it to database
            int          courseId     = gds.InstructorCourses.Where(x => x.instructor_course_id == instructorCourseId).Select(x => x.course_id).FirstOrDefault();
            StudentCours studentCours = gds.StudentCourses.Where(x => (x.student_id == studentId) && (x.course_id == courseId)).FirstOrDefault();
            double       gradePoints  = ((double)totalPoints / maxPoints) * 100;

            gradePoints = Math.Truncate(100 * gradePoints) / 100;
            String letterGrade = getLetterGrade(gradePoints);

            studentCours.letter_grade = letterGrade;
            gds.SaveChanges();
        }
Пример #10
0
        public ActionResult SaveChanges(ulUser u)
        {
            gds = new LMS_GRINDEntities1();
            var user = gds.ulUsers.First(x => x.email_address == Name.email);

            try
            {
                // Set static name variables
                user.first_name     = u.first_name;
                Name.first_name     = user.first_name;
                user.last_name      = u.last_name;
                Name.last_name      = user.last_name;
                user.bio            = u.bio;
                Name.bio            = user.bio;
                user.street_address = u.street_address;
                Name.streetAddress  = user.street_address;
                user.phone_num      = u.phone_num;
                Name.phoneNum       = user.phone_num;
                user.link1          = u.link1;
                Name.link1          = user.link1;
                user.link2          = u.link2;
                Name.link2          = user.link2;
                user.link3          = u.link3;
                Name.link3          = user.link3;
                user.linkTitle1     = u.linkTitle1;
                Name.linkTitle1     = user.linkTitle1;
                user.linkTitle2     = u.linkTitle2;
                Name.linkTitle2     = u.linkTitle2;
                user.linkTitle3     = u.linkTitle3;
                Name.linkTitle3     = u.linkTitle3;

                if (u.File != null)
                {
                    string fileName = Path.GetFileNameWithoutExtension(u.File.FileName) +
                                      DateTime.Now.ToString("yymmssfff") +
                                      Path.GetExtension(u.File.FileName);
                    u.profileImage    = "~/ProfileImages/" + fileName;
                    Name.profileImage = u.profileImage;
                    user.profileImage = u.profileImage;
                    fileName          = Path.Combine(Server.MapPath("~/ProfileImages/"), fileName);
                    u.File.SaveAs(fileName);
                }

                gds.SaveChanges();
            }
            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 (Exception ex)
            {
                //Error
                return(Content(ex.Message));
            }


            return(View("ProfilePage"));
        }
Пример #11
0
        public ActionResult SignUp(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);

            // If the query returns any results, then that
            // email address is already taken, otherwise
            // proceed to create user.
            if (query.Any())
            {
                return(View("SignUp"));
            }
            else
            {
                ulUser user = new ulUser();

                // set user's values
                user.first_name    = u.First_Name;
                user.last_name     = u.Last_Name;
                user.birthdate     = u.Birthdate;
                user.email_address = u.Email;
                user.user_password = hash;
                user.role          = u.Role;
                user.profileImage  = "~/ProfileImages/defaultAvatar.png";

                // add new user to database
                gds.ulUsers.Add(user);
                gds.SaveChanges();

                // set static variables
                Name.first_name    = u.First_Name;
                Name.last_name     = u.Last_Name;
                Name.role          = u.Role;
                Name.email         = user.email_address;
                Name.bio           = user.bio;
                Name.link1         = user.link1;
                Name.link2         = user.link2;
                Name.link3         = user.link3;
                Name.streetAddress = user.street_address;
                Name.phoneNum      = user.phone_num;
                Name.profileImage  = user.profileImage;
                Name.user_id       = user.ulUser_id;

                if (Name.role == "Instructor")
                {
                    // Redirect back to login page promting to sign in again
                    return(Redirect("Login"));
                    //return View("InstructorView");
                }
                else
                {
                    // Redirect back to login page promting to sign in again
                    return(Redirect("Login"));
                    //return View("StudentView");
                }
            }
        }
Пример #12
0
        /// <summary>
        /// Make Payment
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        public async Task <ActionResult> MakePayment(FormCollection form)
        {
            HttpClient client        = new HttpClient();
            string     date          = form["expiration"];
            int        month         = int.Parse(date.Substring(5));
            int        year          = int.Parse(date.Substring(0, 4));
            string     amount        = form["payment_amount"];
            string     paymentAmount = (double.Parse(amount) * 100).ToString();
            long       amt           = long.Parse(paymentAmount);

            try
            {
                StripeConfiguration.ApiKey = "sk_test_51INLgeIR2cxnZNWwi0AHsRoFifYouOH6QcLsIxEEOmBwXNyXXXX4Jt2MOHbR6d5KKMotvMYyrKa1AtrBpcc8q8IB009h5ew7Iw";

                var optionstoken = new TokenCreateOptions
                {
                    Card = new TokenCardOptions
                    {
                        Number   = form["card_number"],
                        ExpMonth = month,
                        ExpYear  = year,
                        Cvc      = form["cvc"]
                    }
                };

                var   servicetoken = new TokenService();
                Token stripetoken  = await servicetoken.CreateAsync(optionstoken);

                var options = new ChargeCreateOptions
                {
                    Amount      = amt,
                    Currency    = "usd",
                    Description = "Payment from " + Name.last_name + ", " + Name.first_name,
                    Source      = stripetoken.Id
                };

                var    service = new ChargeService();
                Charge charge  = await service.CreateAsync(options);

                if (charge.Paid)
                {
                    //update database
                    Payment p = new Payment();

                    p.payment_amount = decimal.Parse(amount);
                    p.user_id        = Name.user_id;
                    p.payment_date   = DateTime.Now;
                    gds.Payments.Add(p);
                    gds.SaveChanges();

                    return(Balance());
                }
                else
                {
                    return(View("PaymentInfoView"));
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }