コード例 #1
0
        /*******Begin code to modify********/

        /// <summary>
        /// Returns a JSON array of the classes the given student is enrolled in.
        /// Each object in the array should have the following fields:
        /// "subject" - The subject abbreviation of the class (such as "CS")
        /// "number" - The course number (such as 5530)
        /// "name" - The course name
        /// "season" - The season part of the semester
        /// "year" - The year part of the semester
        /// "grade" - The grade earned in the class, or "--" if one hasn't been assigned
        /// </summary>
        /// <param name="uid">The uid of the student</param>
        /// <returns>The JSON array</returns>
        public IActionResult GetMyClasses(string uid)
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query =
                    from s in db.StudentEnrollment
                    join c in db.Classes
                    on s.ClassId equals c.ClassId

                    join course in db.Courses
                    on c.CourseNumber equals course.CourseNumber

                    where s.UId == uid
                    select new
                {
                    subject = course.SubjectAbbreviation,    //used to be subject
                    number  = c.CourseNumber,
                    name    = course.Name,
                    season  = c.SemesterSeason,
                    year    = c.SemesterYear,
                    grade   = s.Grade
                };


                return(Json(query.ToArray()));
            }
        }
コード例 #2
0
        /// <summary>
        /// Returns a JSON array of all class offerings of a specific course.
        /// Each object in the array should have the following fields:
        /// "season": the season part of the semester, such as "Fall"
        /// "year": the year part of the semester
        /// "location": the location of the class
        /// "start": the start time in format "hh:mm:ss"
        /// "end": the end time in format "hh:mm:ss"
        /// "fname": the first name of the professor
        /// "lname": the last name of the professor
        /// </summary>
        /// <param name="subject">The subject abbreviation, as in "CS"</param>
        /// <param name="number">The course number, as in 5530</param>
        /// <returns>The JSON array</returns>
        public IActionResult GetClassOfferings(string subject, int number)
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query =
                    from c1 in db.Courses
                    where c1.CourseNumber == number && c1.SubjectAbbreviation == subject
                    join c2 in db.Classes on c1.CourseNumber equals c2.CourseNumber
                    join prof in db.Professors on c2.ProfessorId equals prof.UId

                    select new
                {
                    season   = c2.SemesterSeason,
                    year     = c2.SemesterYear,
                    location = c2.Location,
                    start    = c2.StartTime,
                    end      = c2.EndTime,
                    fname    = prof.FirstName,
                    lname    = prof.LastName
                };


                return(Json(query.ToArray()));
            }
        }
コード例 #3
0
        /// <summary>
        /// Returns a JSON array of the assignment categories for a certain class.
        /// Each object in the array should have the folling fields:
        /// "name" - The category name
        /// "weight" - The category weight
        /// </summary>
        /// <param name="subject">The course subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
        /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
        /// <param name="category">The name of the assignment category in the class</param>
        /// <returns>The JSON array</returns>
        public IActionResult GetAssignmentCategories(string subject, int num, string season, int year)
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query =
                    from c in db.Classes
                    join course in db.Courses
                    on c.CourseNumber equals course.CourseNumber

                    where course.SubjectAbbreviation == subject && course.CourseNumber == num && c.SemesterSeason == season && c.SemesterYear == year
                    select c.ClassId;


                var query1 =


                    from ac in db.AssignmentCategories

                    where ac.ClassId == query.ToArray()[0]
                    select new
                {
                    name   = ac.Name,
                    weight = ac.GradingWeight
                };
                db.SaveChanges();//I am not sure here
                return(Json(query1.ToArray()));
            }
        }
コード例 #4
0
        /*******Begin code to modify********/


        /// <summary>
        /// Returns a JSON array of all the students in a class.
        /// Each object in the array should have the following fields:
        /// "fname" - first name
        /// "lname" - last name
        /// "uid" - user ID
        /// "dob" - date of birth
        /// "grade" - the student's grade in this class
        /// </summary>
        /// <param name="subject">The course subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
        /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
        /// <returns>The JSON array</returns>
        public IActionResult GetStudentsInClass(string subject, int num, string season, int year)
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query =
                    from c in db.Classes
                    join course in db.Courses
                    on c.CourseNumber equals course.CourseNumber



                    where course.SubjectAbbreviation == subject && course.CourseNumber == num && c.SemesterSeason == season && c.SemesterYear == year
                    select c.ClassId;


                var query1 =
                    from se in db.StudentEnrollment
                    join s in db.Students
                    on se.UId equals s.UId

                    where se.ClassId == query.ToArray()[0]
                    select new
                {
                    fname = s.FirstName,
                    lname = s.LastName,
                    uid   = s.UId,
                    dob   = s.DateOfBirth,
                    grade = se.Grade
                };
                return(Json(query1.ToArray()));
            }
        }
コード例 #5
0
        /// <summary>
        /// This method does NOT return JSON. It returns plain text (containing html).
        /// Use "return Content(...)" to return plain text.
        /// Returns the contents of an assignment submission.
        /// Returns the empty string ("") if there is no submission.
        /// </summary>
        /// <param name="subject">The course subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
        /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
        /// <param name="category">The name of the assignment category in the class</param>
        /// <param name="asgname">The name of the assignment in the category</param>
        /// <param name="uid">The uid of the student who submitted it</param>
        /// <returns>The submission text</returns>
        public IActionResult GetSubmissionText(string subject, int num, string season, int year, string category, string asgname, string uid)
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query =
                    from s in db.Submission
                    join a1 in db.Assignments
                    on s.AssignmentId equals a1.AssignmentId
                    where a1.Name == asgname && s.UId == uid


                    join a2 in db.AssignmentCategories
                    on a1.AssignmentCategoryId equals a2.AssignmentCategoryId
                    where a2.Name == category

                    join c in db.Classes
                    on a2.ClassId equals c.ClassId
                    where c.SemesterSeason == season && c.SemesterYear == year

                    join course in db.Courses
                    on c.CourseNumber equals course.CourseNumber
                    where course.CourseNumber == num && course.SubjectAbbreviation == subject

                    select s.Contents;

                if (query.Count() == 0)
                {
                    return(Content(""));
                }
                // not sure how to return content
                return(Content(query.First()));
            }
        }
コード例 #6
0
        /// <summary>
        /// Enrolls a student in a class.
        /// </summary>
        /// <param name="subject">The department subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester</param>
        /// <param name="year">The year part of the semester</param>
        /// <param name="uid">The uid of the student</param>
        /// <returns>A JSON object containing {success = {true/false}.
        /// false if the student is already enrolled in the class, true otherwise.</returns>
        public IActionResult Enroll(string subject, int num, string season, int year, string uid)
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query0 =
                    from c in db.Classes
                    join course in db.Courses
                    on c.CourseNumber equals course.CourseNumber

                    where course.SubjectAbbreviation == subject && course.CourseNumber == num && c.SemesterSeason == season && c.SemesterYear == year
                    select c;

                var query =
                    from se in db.StudentEnrollment
                    where se.ClassId == query0.ToArray()[0].ClassId && se.UId == uid
                    select se;

                if (query.Count() != 0)
                {
                    return(Json(new { success = false }));
                }
                else
                {
                    Models.LMSModels.StudentEnrollment s = new Models.LMSModels.StudentEnrollment();
                    s.ClassId = query0.ToArray()[0].ClassId;
                    s.UId     = uid;
                    s.Grade   = "--";
                    db.StudentEnrollment.Add(s);
                    db.SaveChanges();
                }

                return(Json(new { success = true }));
            }
        }
コード例 #7
0
        /// <summary>
        /// Creates a new assignment category for the specified class.
        /// If a category of the given class with the given name already exists, return success = false.
        /// </summary>
        /// <param name="subject">The course subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
        /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
        /// <param name="category">The new category name</param>
        /// <param name="catweight">The new category weight</param>
        /// <returns>A JSON object containing {success = true/false} </returns>
        public IActionResult CreateAssignmentCategory(string subject, int num, string season, int year, string category, int catweight)
        {
            var chars       = "0123456789";
            var stringChars = new char[5];
            var random      = new Random();

            for (int i = 0; i < stringChars.Length; i++)
            {
                stringChars[i] = chars[random.Next(chars.Length)];
            }

            var acID = new String(stringChars);

            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query =
                    from c in db.Classes
                    join course in db.Courses
                    on c.CourseNumber equals course.CourseNumber

                    where course.SubjectAbbreviation == subject && course.CourseNumber == num && c.SemesterSeason == season && c.SemesterYear == year
                    select c.ClassId;

                var query1 =
                    from ac in db.AssignmentCategories
                    where ac.Name == category && ac.ClassId == query.ToArray()[0]
                    select ac;
                if (query1.Count() != 0)
                {
                    return(Json(new { success = false }));
                }

                Models.LMSModels.AssignmentCategories ac1 = new Models.LMSModels.AssignmentCategories();
                ac1.ClassId = query.ToArray()[0];
                ac1.AssignmentCategoryId = acID;
                ac1.GradingWeight        = catweight;
                ac1.Name = category;
                db.AssignmentCategories.Add(ac1);
                db.SaveChanges();


                // update all students' grades for this class

                var findAllStudents =
                    from se in db.StudentEnrollment
                    where se.ClassId == query.ToArray()[0]
                    select se.UId;

                foreach (var x in findAllStudents)
                {
                    updateStudentGradeForClass(query.ToArray()[0], x);
                }
                return(Json(new { success = true }));
            }
        }
コード例 #8
0
        /*******Begin code to modify********/

        /// <summary>
        /// Create a new user of the LMS with the specified information.
        /// Assigns the user a unique uID consisting of a 'u' followed by 7 digits.
        /// </summary>
        /// <param name="fName">First Name</param>
        /// <param name="lName">Last Name</param>
        /// <param name="DOB">Date of Birth</param>
        /// <param name="SubjectAbbrev">The department the user belongs to (professors and students only)</param>
        /// <param name="SubjectAbbrev">The user's role: one of "Administrator", "Professor", "Student"</param>
        /// <returns>A unique uID that is not be used by anyone else</returns>
        public string CreateNewUser(string fName, string lName, DateTime DOB, string SubjectAbbrev, string role)
        {
            var chars       = "0123456789";
            var stringChars = new char[8];
            var random      = new Random();

            stringChars[0] = 'u';
            for (int i = 1; i < stringChars.Length; i++)
            {
                stringChars[i] = chars[random.Next(chars.Length)];
            }

            var uid = new String(stringChars);


            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                if (role.Equals("Student"))
                {
                    Models.LMSModels.Students s = new Models.LMSModels.Students();
                    s.FirstName           = fName;
                    s.LastName            = lName;
                    s.DateOfBirth         = DOB;
                    s.SubjectAbbreviation = SubjectAbbrev;
                    s.UId = uid;
                    db.Students.Add(s);
                    db.SaveChanges();
                }

                if (role.Equals("Professor"))
                {
                    Models.LMSModels.Professors p = new Models.LMSModels.Professors();
                    p.FirstName           = fName;
                    p.LastName            = lName;
                    p.DateOfBirth         = DOB;
                    p.SubjectAbbreviation = SubjectAbbrev;
                    p.UId = uid;
                    db.Professors.Add(p);
                    db.SaveChanges();
                }

                if (role.Equals("Administrator"))
                {
                    Models.LMSModels.Administrators admin = new Models.LMSModels.Administrators();
                    admin.FirstName   = fName;
                    admin.LastName    = lName;
                    admin.DateOfBirth = DOB;
                    admin.UId         = uid;
                    db.Administrators.Add(admin);
                    db.SaveChanges();
                }
            }

            return(uid);
        }
コード例 #9
0
        /// <summary>
        /// Retreive a JSON array of all departments from the database.
        /// Each object in the array should have a field called "name" and "subject",
        /// where "name" is the department name and "subject" is the subject abbreviation.
        /// </summary>
        /// <returns>The JSON array</returns>
        public IActionResult GetDepartments()
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query =
                    from d in db.Departments
                    select d;

                return(Json(query.ToArray()));
            }
        }
コード例 #10
0
        /// <summary>
        /// Returns a JSON array with all the assignments in an assignment category for a class.
        /// If the "category" parameter is null, return all assignments in the class.
        /// Each object in the array should have the following fields:
        /// "aname" - The assignment name
        /// "cname" - The assignment category name.
        /// "due" - The due DateTime
        /// "submissions" - The number of submissions to the assignment
        /// </summary>
        /// <param name="subject">The course subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
        /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
        /// <param name="category">The name of the assignment category in the class,
        /// or null to return assignments from all categories</param>
        /// <returns>The JSON array</returns>
        public IActionResult GetAssignmentsInCategory(string subject, int num, string season, int year, string category)
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                JsonResult result;
                var        query1 =
                    from c in db.Courses
                    join cla in db.Classes
                    on c.CourseNumber equals cla.CourseNumber
                    where c.SubjectAbbreviation == subject && c.CourseNumber == num && cla.SemesterSeason == season && cla.SemesterYear == year
                    join categories in db.AssignmentCategories
                    on cla.ClassId equals categories.ClassId
                    join a in db.Assignments
                    on categories.AssignmentCategoryId equals a.AssignmentCategoryId
                    select new { a, categories };

                if (category != null)
                {
                    var query2 =
                        from q in query1
                        where q.categories.Name == category
                        select new
                    {
                        aname       = q.a.Name,
                        cname       = q.categories.Name,
                        due         = q.a.DueDate,
                        submissions = (from s in db.Submission where s.AssignmentId == q.a.AssignmentId select s).Count()
                    };

                    result = Json(query2.ToArray());
                }
                else
                {
                    var query2 =
                        from q in query1
                        select new
                    {
                        aname       = q.a.Name,
                        cname       = q.categories.Name,
                        due         = q.a.DueDate,
                        submissions = (from s in db.Submission where s.AssignmentId == q.a.AssignmentId select s).Count()
                    };

                    result = Json(query2.ToArray());
                }

                return(result);
            }
        }
コード例 #11
0
        /// <summary>
        /// Creates a class offering of a given course.
        /// </summary>
        /// <param name="subject">The department subject abbreviation</param>
        /// <param name="number">The course number</param>
        /// <param name="season">The season part of the semester</param>
        /// <param name="year">The year part of the semester</param>
        /// <param name="start">The start time</param>
        /// <param name="end">The end time</param>
        /// <param name="location">The location</param>
        /// <param name="instructor">The uid of the professor</param>
        /// <returns>A JSON object containing {success = true/false}.
        /// false if another class occupies the same location during any time
        /// within the start-end range in the same semester, or if there is already
        /// a Class offering of the same Course in the same Semester,
        /// true otherwise.</returns>
        public IActionResult CreateClass(string subject, int number, string season, int year, DateTime start, DateTime end, string location, string instructor)
        {
            /*
             *   var chars = "0123456789";
             *   var stringChars = new char[5];
             *   var random = new Random();
             *
             *   for (int i = 0; i < stringChars.Length; i++)
             *   {
             *       stringChars[i] = chars[random.Next(chars.Length)];
             *   }
             *
             *   var classID = new String(stringChars);
             */
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query =
                    from departments in db.Departments
                    join courses in db.Courses
                    on departments.SubjectAbbreviation equals courses.SubjectAbbreviation
                    where courses.SubjectAbbreviation == subject &&
                    courses.CourseNumber == number
                    select courses.CourseNumber;

                Models.LMSModels.Classes c = new Models.LMSModels.Classes();
                c.SemesterYear   = (uint)year;
                c.SemesterSeason = season;
                c.StartTime      = start;
                c.EndTime        = end;
                c.Location       = location;
                c.CourseNumber   = query.First(); // First or default? Should there always be only 1 here?
                c.ProfessorId    = instructor;

                db.Classes.Add(c);

                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    return(Json(new { success = false }));
                }

                return(Json(new { success = true }));
            }
        }
コード例 #12
0
        /*******Begin code to modify********/

        /// <summary>
        /// Returns a JSON array of all the courses in the given department.
        /// Each object in the array should have the following fields:
        /// "number" - The course number (as in 5530)
        /// "name" - The course name (as in "Database Systems")
        /// </summary>
        /// <param name="subject">The department subject abbreviation (as in "CS")</param>
        /// <returns>The JSON result</returns>
        public IActionResult GetCourses(string subject)
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query =
                    from c in db.Courses
                    where c.SubjectAbbreviation == subject
                    select new
                {
                    number = c.CourseNumber,
                    name   = c.Name
                };

                return(Json(query.ToArray()));
            }
        }
コード例 #13
0
        /// <summary>
        /// Returns a JSON array of all the professors working in a given department.
        /// Each object in the array should have the following fields:
        /// "lname" - The professor's last name
        /// "fname" - The professor's first name
        /// "uid" - The professor's uid
        /// </summary>
        /// <param name="subject">The department subject abbreviation</param>
        /// <returns>The JSON result</returns>
        public IActionResult GetProfessors(string subject)
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query =
                    from p in db.Professors
                    where p.SubjectAbbreviation == subject
                    select new
                {
                    lname = p.LastName,
                    fname = p.FirstName,
                    uid   = p.UId
                };

                return(Json(query.ToArray()));
            }
        }
コード例 #14
0
        /// <summary>
        /// Set the score of an assignment submission
        /// </summary>
        /// <param name="subject">The course subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
        /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
        /// <param name="category">The name of the assignment category in the class</param>
        /// <param name="asgname">The name of the assignment</param>
        /// <param name="uid">The uid of the student who's submission is being graded</param>
        /// <param name="score">The new score for the submission</param>
        /// <returns>A JSON object containing success = true/false</returns>
        public IActionResult GradeSubmission(string subject, int num, string season, int year, string category, string asgname, string uid, int score)
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query =
                    from c in db.Classes
                    join course in db.Courses
                    on c.CourseNumber equals course.CourseNumber

                    where course.SubjectAbbreviation == subject && course.CourseNumber == num && c.SemesterSeason == season && c.SemesterYear == year
                    select c.ClassId;

                var query1 =
                    from ac in db.AssignmentCategories
                    where ac.Name == category && ac.ClassId == query.ToArray()[0]
                    select ac.AssignmentCategoryId;

                var query2 =
                    from a in db.Assignments
                    where a.AssignmentCategoryId == query1.ToArray()[0] && a.Name == asgname
                    select a.AssignmentId;

                var query3 =
                    from s in db.Submission
                    where s.AssignmentId == query2.ToArray()[0] && s.UId == uid
                    select s;

                if (query3.Count() == 0)
                {
                    return(Json(new { success = false }));
                }

                query3.ToArray()[0].Score = score;
                db.SaveChanges();

                // change studuent's grade for this class automatically
                updateStudentGradeForClass(query.ToArray()[0], uid);



                return(Json(new { success = true }));
            }
        }
コード例 #15
0
        /// <summary>
        /// Gets a JSON array of all the submissions to a certain assignment.
        /// Each object in the array should have the following fields:
        /// "fname" - first name
        /// "lname" - last name
        /// "uid" - user ID
        /// "time" - DateTime of the submission
        /// "score" - The score given to the submission
        ///
        /// </summary>
        /// <param name="subject">The course subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
        /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
        /// <param name="category">The name of the assignment category in the class</param>
        /// <param name="asgname">The name of the assignment</param>
        /// <returns>The JSON array</returns>
        public IActionResult GetSubmissionsToAssignment(string subject, int num, string season, int year, string category, string asgname)
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query =
                    from c in db.Classes
                    join course in db.Courses
                    on c.CourseNumber equals course.CourseNumber

                    where course.SubjectAbbreviation == subject && course.CourseNumber == num && c.SemesterSeason == season && c.SemesterYear == year
                    select c.ClassId;

                var query1 =
                    from ac in db.AssignmentCategories
                    where ac.Name == category && ac.ClassId == query.ToArray()[0]
                    select ac.AssignmentCategoryId;

                var query2 =
                    from a in db.Assignments
                    where a.AssignmentCategoryId == query1.ToArray()[0] && a.Name == asgname
                    select a.AssignmentId;

                var query3 =
                    from s in db.Submission
                    join student in db.Students
                    on s.UId equals student.UId

                    where s.AssignmentId == query2.ToArray()[0]
                    select new
                {
                    fname = student.FirstName,
                    lname = student.LastName,
                    uid   = student.UId,
                    time  = s.SubmitTime,
                    score = s.Score
                };


                return(Json(query3.ToArray()));
            }
        }
コード例 #16
0
        /// <summary>
        /// Returns a JSON array of the classes taught by the specified professor
        /// Each object in the array should have the following fields:
        /// "subject" - The subject abbreviation of the class (such as "CS")
        /// "number" - The course number (such as 5530)
        /// "name" - The course name
        /// "season" - The season part of the semester in which the class is taught
        /// "year" - The year part of the semester in which the class is taught
        /// </summary>
        /// <param name="uid">The professor's uid</param>
        /// <returns>The JSON array</returns>
        public IActionResult GetMyClasses(string uid)
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query =
                    from c in db.Classes
                    join course in db.Courses
                    on c.CourseNumber equals course.CourseNumber

                    where c.ProfessorId == uid
                    select new
                {
                    subject = course.SubjectAbbreviation,
                    number  = course.CourseNumber,
                    name    = course.Name,
                    season  = c.SemesterSeason,
                    year    = c.SemesterYear
                };

                return(Json(query.ToArray()));
            }
        }
コード例 #17
0
        /// <summary>
        /// Creates a course.
        /// A course is uniquely identified by its number + the subject to which it belongs
        /// </summary>
        /// <param name="subject">The subject abbreviation for the department in which the course will be added</param>
        /// <param name="number">The course number</param>
        /// <param name="name">The course name</param>
        /// <returns>A JSON object containing {success = true/false}.
        /// false if the course already exists, true otherwise.</returns>
        public IActionResult CreateCourse(string subject, int number, string name)
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query =
                    from c1 in db.Courses
                    where c1.CourseNumber == number && c1.SubjectAbbreviation == subject
                    select c1;

                if (query != null)
                {
                    return(Json(new { success = false }));
                }
                LMS.Models.LMSModels.Courses c = new Models.LMSModels.Courses();
                c.SubjectAbbreviation = subject;
                c.CourseNumber        = (ushort)number;
                c.Name = name;
                db.Courses.Add(c);
                db.SaveChanges();
                return(Json(new { success = true }));
            }
        }
コード例 #18
0
        /// <summary>
        /// Returns a JSON array representing the course catalog.
        /// Each object in the array should have the following fields:
        /// "subject": The subject abbreviation, (e.g. "CS")
        /// "dname": The department name, as in "Computer Science"
        /// "courses": An array of JSON objects representing the courses in the department.
        ///            Each field in this inner-array should have the following fields:
        ///            "number": The course number (e.g. 5530)
        ///            "cname": The course name (e.g. "Database Systems")
        /// </summary>
        /// <returns>The JSON array</returns>
        public IActionResult GetCatalog()
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query =
                    from d in db.Departments
                    select new
                {
                    subject = d.SubjectAbbreviation,
                    dname   = d.Name,
                    courses =
                        from c in db.Courses
                        where c.SubjectAbbreviation == d.SubjectAbbreviation
                        select new
                    {
                        number = c.CourseNumber,
                        cname  = c.Name
                    }
                };

                return(Json(query.ToArray()));
            }
        }
コード例 #19
0
        /// <summary>
        /// This method does NOT return JSON. It returns plain text (containing html).
        /// Use "return Content(...)" to return plain text.
        /// Returns the contents of an assignment.
        /// </summary>
        /// <param name="subject">The course subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
        /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
        /// <param name="category">The name of the assignment category in the class</param>
        /// <param name="asgname">The name of the assignment in the category</param>
        /// <returns>The assignment contents</returns>
        public IActionResult GetAssignmentContents(string subject, int num, string season, int year, string category, string asgname)
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query =
                    from a1 in db.Assignments
                    join a2 in db.AssignmentCategories
                    on a1.AssignmentCategoryId equals a2.AssignmentCategoryId


                    join c in db.Classes
                    on a2.ClassId equals c.ClassId

                    join course in db.Courses
                    on c.CourseNumber equals course.CourseNumber

                    where course.SubjectAbbreviation == subject && c.CourseNumber == num && c.SemesterSeason == season && c.SemesterYear == year && a2.Name == category && a1.Name == asgname
                    select a1.Contents;

                // not sure how to return content
                //return Content(query);
                return(Content(query.ToArray()[0]));
            }
        }
コード例 #20
0
        /// <summary>
        /// Adds a submission to the given assignment for the given student
        /// The submission should use the current time as its DateTime
        /// You can get the current time with DateTime.Now
        /// The score of the submission should start as 0 until a Professor grades it
        /// If a Student submits to an assignment again, it should replace the submission contents
        /// and the submission time (the score should remain the same).
        /// </summary>
        /// <param name="subject">The course subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
        /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
        /// <param name="category">The name of the assignment category in the class</param>
        /// <param name="asgname">The new assignment name</param>
        /// <param name="uid">The student submitting the assignment</param>
        /// <param name="contents">The text contents of the student's submission</param>
        /// <returns>A JSON object containing {success = true/false}</returns>
        public IActionResult SubmitAssignmentText(string subject, int num, string season, int year,
                                                  string category, string asgname, string uid, string contents)
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query0 =
                    from a in db.Assignments
                    join ac in db.AssignmentCategories
                    on a.AssignmentCategoryId equals ac.AssignmentCategoryId

                    join c in db.Classes
                    on ac.ClassId equals c.ClassId

                    join course in db.Courses
                    on c.CourseNumber equals course.CourseNumber

                    where course.SubjectAbbreviation == subject && course.CourseNumber == num && c.SemesterSeason == season && c.SemesterYear == year && ac.Name == category &&
                    a.Name == asgname
                    select a;

                if (query0.Count() == 0)
                {
                    return(Json(new { success = false }));
                }

                var query =
                    from s in db.Submission
                    join a in db.Assignments
                    on s.AssignmentId equals a.AssignmentId

                    join ac in db.AssignmentCategories
                    on a.AssignmentCategoryId equals ac.AssignmentCategoryId

                    join c in db.Classes
                    on ac.ClassId equals c.ClassId

                    join course in db.Courses
                    on c.CourseNumber equals course.CourseNumber
                    where course.SubjectAbbreviation == subject && course.CourseNumber == num && c.SemesterSeason == season && c.SemesterYear == year && ac.Name == category &&
                    a.Name == asgname && s.UId == uid

                    select s;

                if (query.Count() != 0)
                {
                    query.ToArray()[0].Contents   = contents;
                    query.ToArray()[0].SubmitTime = DateTime.Now;
                    db.SaveChanges();
                }
                else
                {
                    Models.LMSModels.Submission s1 = new Models.LMSModels.Submission();
                    s1.Contents     = contents;
                    s1.SubmitTime   = DateTime.Now;
                    s1.UId          = uid;
                    s1.Score        = 0;
                    s1.AssignmentId = query0.ToArray()[0].AssignmentId;
                    db.Submission.Add(s1);
                    db.SaveChanges();
                }

                return(Json(new { success = true }));
            }
        }
コード例 #21
0
        /// <summary>
        /// Returns a JSON array of all the assignments in the given class that the given student is enrolled in.
        /// Each object in the array should have the following fields:
        /// "aname" - The assignment name
        /// "cname" - The category name that the assignment belongs to
        /// "due" - The due Date/Time
        /// "score" - The score earned by the student, or null if the student has not submitted to this assignment.
        /// </summary>
        /// <param name="subject">The course subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
        /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
        /// <param name="uid"></param>
        /// <returns>The JSON array</returns>
        public IActionResult GetAssignmentsInClass(string subject, int num, string season, int year, string uid)
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                /*
                 * var query =
                 *  from s in db.StudentEnrollment
                 *  join c in db.Classes
                 *  on s.ClassId equals c.ClassId
                 *  where c.SemesterSeason == season && c.SemesterYear == year
                 *
                 *  join course in db.Courses
                 *  on c.CourseNumber equals course.CourseNumber
                 *  where course.SubjectAbbreviation == subject && course.CourseNumber == num
                 *
                 *  join ac in db.AssignmentCategories
                 *  on c.ClassId equals ac.ClassId
                 *
                 *  join a in db.Assignments
                 *  on ac.AssignmentCategoryId equals a.AssignmentCategoryId
                 *
                 *
                 *  join submission in db.Submission
                 *  on a.AssignmentId equals submission.AssignmentId
                 *  where submission.UId == uid
                 *  select new
                 *  {
                 *      aname = a.Name,
                 *      cname = ac.Name,
                 *      due = a.DueDate,
                 *      score = submission.Score
                 *  };
                 *
                 *
                 * return Json(query.ToArray());
                 */
                var query1 =
                    from c in db.Courses // to check
                    where c.SubjectAbbreviation == subject && c.CourseNumber == num
                    join clas in db.Classes on c.CourseNumber equals clas.CourseNumber
                    where clas.SemesterSeason == season && clas.SemesterYear == year
                    join cat in db.AssignmentCategories on clas.ClassId equals cat.ClassId
                    join a in db.Assignments on cat.AssignmentCategoryId equals a.AssignmentCategoryId
                    select a;

                var query2 =
                    from q in query1
                    join s in db.Submission on
                    new { A = q.AssignmentId, B = uid } equals new { A = s.AssignmentId, B = s.UId }
                into join1
                from j in join1.DefaultIfEmpty()
                select new
                {
                    aname = q.Name,
                    cname = q.AssignmentCategory.Name,
                    due   = q.DueDate,
                    score = j == null ? null : (int?)j.Score
                };

                return(Json(query2.ToArray()));
            }
        }
コード例 #22
0
        /// <summary>
        /// Gets information about a user as a single JSON object.
        /// The object should have the following fields:
        /// "fname": the user's first name
        /// "lname": the user's last name
        /// "uid": the user's uid
        /// "department": (professors and students only) the name (such as "Computer Science") of the department for the user.
        ///               If the user is a Professor, this is the department they work in.
        ///               If the user is a Student, this is the department they major in.
        ///               If the user is an Administrator, this field is not present in the returned JSON
        /// </summary>
        /// <param name="uid">The ID of the user</param>
        /// <returns>
        /// The user JSON object
        /// or an object containing {success: false} if the user doesn't exist
        /// </returns>
        public IActionResult GetUser(string uid)
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query1 =
                    from c1 in db.Professors
                    join d in db.Departments
                    on c1.SubjectAbbreviation equals d.SubjectAbbreviation

                    where c1.UId == uid
                    select new
                {
                    fname      = c1.FirstName,
                    lname      = c1.LastName,
                    uid        = c1.UId,
                    department = d.Name
                };

                if (query1 != null)
                {
                    return(Json(query1));
                }

                var query2 =
                    from c1 in db.Students
                    join d in db.Departments
                    on c1.SubjectAbbreviation equals d.SubjectAbbreviation

                    where c1.UId == uid
                    select new
                {
                    fname      = c1.FirstName,
                    lname      = c1.LastName,
                    uid        = c1.UId,
                    department = d.Name
                };

                if (query2 != null)
                {
                    return(Json(query2));
                }

                var query3 =
                    from c1 in db.Administrators

                    where c1.UId == uid
                    select new
                {
                    fname = c1.FirstName,
                    lname = c1.LastName,
                    uid   = c1.UId,
                };

                if (query3.Count() != 0)
                {
                    return(Json(query3));
                }

                return(Json(new { success = false }));
            }
        }
コード例 #23
0
        /*
         * WARNING: This is the quick and easy way to make the controller
         *          use a different LibraryContext - good enough for our purposes.
         *          The "right" way is through Dependency Injection via the constructor
         *          (look this up if interested).
         */

        // TODO: Uncomment and change 'X' after you have scaffoled

        public void UseLMSContext(Models.LMSModels.Team13LMSContext ctx)
        {
            db = ctx;
        }
コード例 #24
0
        public void updateStudentGradeForClass(String classId, String uid)
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var findAllAssignmentCategories =
                    from ac in db.AssignmentCategories
                    where ac.ClassId == classId
                    select ac;

                int    assignmentCategoriesWeightSum = 0;
                int    maxPointsForAllAssignments    = 0;
                int    pointsForAllAssignments       = 0;
                double curGrade = 0.0;
                foreach (var ac in findAllAssignmentCategories)
                {
                    int totalMaxPoints = 0;
                    int totalPoints    = 0;
                    var allAssignments =
                        from a in db.Assignments
                        where a.AssignmentCategoryId == ac.AssignmentCategoryId
                        select a;



                    // do not have any submitted assignment for this student in this assignmentCategory
                    // then skip this loop
                    if (allAssignments.Count() == 0)
                    {
                        continue;
                    }

                    assignmentCategoriesWeightSum += (int)ac.GradingWeight;


                    foreach (var x in allAssignments)
                    {
                        totalMaxPoints             += (int)x.MaxPointValue;
                        maxPointsForAllAssignments += (int)x.MaxPointValue;
                        var submission =
                            from s in db.Submission
                            where s.AssignmentId == x.AssignmentId && s.UId == uid
                            select s;
                        if (submission.Count() == 0)
                        {
                            totalPoints             += 0;
                            pointsForAllAssignments += 0;
                        }
                        else
                        {
                            totalPoints             += (int)submission.ToArray()[0].Score;
                            pointsForAllAssignments += (int)submission.ToArray()[0].Score;
                        }
                    }

                    // calculate percentage for this assignmentCategory
                    double percentage = (double)totalPoints / (double)totalMaxPoints;
                    curGrade += percentage * (double)ac.GradingWeight;
                }
                double scalingFactor = (double)100 / (double)assignmentCategoriesWeightSum;
                curGrade *= scalingFactor;
                //90 > X _ 87 B+ 80 > X _ 77 C+ 70 > X _ 67 D+
                //100 _ X _ 93 A 87 > X _ 83 B 77 > X _ 73 C 67 > X _ 63 D 60 > X _ 0 E
                //93 > X _ 90 A - 83 > X _ 80 B - 73 > X _ 70 C - 63 > X _ 60 D -

                String curGradeLetter = "";
                if (pointsForAllAssignments >= maxPointsForAllAssignments)
                {
                    curGradeLetter = "A";
                }
                if (curGrade >= 93)
                {
                    curGradeLetter = "A";
                }
                else if (curGrade >= 90 && curGrade < 93)
                {
                    curGradeLetter = "A-";
                }
                else if (curGrade >= 87 && curGrade < 90)
                {
                    curGradeLetter = "B+";
                }
                else if (curGrade >= 83 && curGrade < 87)
                {
                    curGradeLetter = "B";
                }
                else if (curGrade >= 80 && curGrade < 83)
                {
                    curGradeLetter = "B-";
                }
                else if (curGrade >= 77 && curGrade < 80)
                {
                    curGradeLetter = "C+";
                }
                else if (curGrade >= 73 && curGrade < 77)
                {
                    curGradeLetter = "C";
                }
                else if (curGrade >= 70 && curGrade < 73)
                {
                    curGradeLetter = "C-";
                }
                else if (curGrade >= 67 && curGrade < 70)
                {
                    curGradeLetter = "D+";
                }
                else if (curGrade >= 63 && curGrade < 67)
                {
                    curGradeLetter = "D";
                }
                else if (curGrade >= 60 && curGrade < 63)
                {
                    curGradeLetter = "D-";
                }
                else
                {
                    curGradeLetter = "E";
                }



                var findEnrollment =
                    from se in db.StudentEnrollment
                    where se.UId == uid && se.ClassId == classId
                    select se;


                findEnrollment.ToArray()[0].Grade = curGradeLetter;

                db.SaveChanges();
            }
        }
コード例 #25
0
        /// <summary>
        /// Calculates a student's GPA
        /// A student's GPA is determined by the grade-point representation of the average grade in all their classes.
        /// Assume all classes are 4 credit hours.
        /// If a student does not have a grade in a class ("--"), that class is not counted in the average.
        /// If a student is not enrolled in any classes, they have a GPA of 0.0.
        /// Otherwise, the point-value of a letter grade is determined by the table on this page:
        /// https://advising.utah.edu/academic-standards/gpa-calculator-new.php
        /// </summary>
        /// <param name="uid">The uid of the student</param>
        /// <returns>A JSON object containing a single field called "gpa" with the number value</returns>
        public IActionResult GetGPA(string uid)
        {
            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query =
                    from se in db.StudentEnrollment
                    where se.UId == uid
                    select se.Grade;

                if (query.Count() == 0)
                {
                    return(Json(new { gpa = 0.0 }));
                }

                int    classCount = 0;
                double GPA        = 0.0;

                foreach (var grade in query)
                {
                    if (grade == "--")
                    {
                        continue;
                    }
                    else
                    {
                        classCount++;
                        if (grade == "A")
                        {
                            GPA += 4.0;
                        }
                        else if (grade == "A-")
                        {
                            GPA += 3.7;
                        }
                        else if (grade == "B+")
                        {
                            GPA += 3.3;
                        }
                        else if (grade == "B")
                        {
                            GPA += 3.0;
                        }
                        else if (grade == "B-")
                        {
                            GPA += 2.7;
                        }
                        else if (grade == "C+")
                        {
                            GPA += 2.3;
                        }
                        else if (grade == "C")
                        {
                            GPA += 2.0;
                        }
                        else if (grade == "C-")
                        {
                            GPA += 1.7;
                        }
                        else if (grade == "D+")
                        {
                            GPA += 1.3;
                        }
                        else if (grade == "D")
                        {
                            GPA += 1.0;
                        }
                        else if (grade == "D-")
                        {
                            GPA += 0.7;
                        }
                        else
                        {
                            GPA += 0.0;
                        }
                    };
                }
                GPA = GPA / classCount;



                return(Json(new { gpa = GPA }));
            }
        }
コード例 #26
0
        /// <summary>
        /// Creates a new assignment for the given class and category.
        /// </summary>
        /// <param name="subject">The course subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
        /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
        /// <param name="category">The name of the assignment category in the class</param>
        /// <param name="asgname">The new assignment name</param>
        /// <param name="asgpoints">The max point value for the new assignment</param>
        /// <param name="asgdue">The due DateTime for the new assignment</param>
        /// <param name="asgcontents">The contents of the new assignment</param>
        /// <returns>A JSON object containing success = true/false</returns>
        public IActionResult CreateAssignment(string subject, int num, string season, int year, string category, string asgname, int asgpoints, DateTime asgdue, string asgcontents)
        {
            var chars       = "0123456789";
            var stringChars = new char[5];
            var random      = new Random();

            for (int i = 0; i < stringChars.Length; i++)
            {
                stringChars[i] = chars[random.Next(chars.Length)];
            }

            var AssignmentID = new String(stringChars);

            using (Models.LMSModels.Team13LMSContext db = new Models.LMSModels.Team13LMSContext())
            {
                var query =
                    from c in db.Classes
                    join course in db.Courses
                    on c.CourseNumber equals course.CourseNumber

                    where course.SubjectAbbreviation == subject && course.CourseNumber == num && c.SemesterSeason == season && c.SemesterYear == year
                    select c.ClassId;

                var query1 =
                    from ac in db.AssignmentCategories
                    where ac.Name == category && ac.ClassId == query.ToArray()[0]
                    select ac.AssignmentCategoryId;

                var query2 =
                    from a in db.Assignments
                    where a.AssignmentCategoryId == query1.ToArray()[0] && a.Name == asgname
                    select a;

                if (query2.Count() != 0)
                {
                    return(Json(new { success = false }));
                }

                Models.LMSModels.Assignments a1 = new Models.LMSModels.Assignments();
                a1.AssignmentId         = AssignmentID;
                a1.DueDate              = asgdue;
                a1.Name                 = asgname;
                a1.Contents             = asgcontents;
                a1.MaxPointValue        = asgpoints;
                a1.AssignmentCategoryId = query1.ToArray()[0];
                db.Assignments.Add(a1);
                db.SaveChanges();

                var allStudents =
                    from se in db.StudentEnrollment
                    where se.ClassId == query.ToArray()[0]
                    select se;

                foreach (var s in allStudents)
                {
                    updateStudentGradeForClass(s.ClassId, s.UId);
                }

                return(Json(new { success = true }));
            }
        }
コード例 #27
0
 public CommonController()
 {
     db = new Models.LMSModels.Team13LMSContext();
 }