public string getNewUid()
 {
     using (Team31LMSContext dab = new Team31LMSContext())
     {
         var query = (from u in dab.Users orderby u.UId descending select u.UId).Take(1);
         if (query != null)
         {
             string test = query.ToList()[0];
             string num  = test.Substring(1);
             uint   number;
             if (UInt32.TryParse(num, out number))
             {
                 return("u" + (number + 1).ToString().PadLeft(7, '0'));
             }
             else
             {
                 //Error message
                 Console.WriteLine("An error has occured while getting a new uID...");
             }
         }
         else
         {
             return("u0000000");
         }
     }
     return("THISSOMEHOWFAILED");
 }
Beispiel #2
0
        /// <summary>
        /// Calculates and returns the grade for the for the student with the given uid
        /// in the given class. A scaled total of points for each assignment in each
        /// assignment category is used to find the letter grade.
        /// </summary>
        /// <param name="db"></param>
        /// <param name="subject"></param>
        /// <param name="num"></param>
        /// <param name="season"></param>
        /// <param name="year"></param>
        /// <param name="category"></param>
        /// <param name="uid"></param>
        /// <returns></returns>
        public string calculateGrade(Team31LMSContext db, string subject, int num, string season, int year, string category, string uid)
        {
            double scaledTotal = 0.0;
            double weightTotal = 0.0;
            // Holds all the non-empty assignment categories for the given class
            var query = from co in db.Courses
                        where co.DeptAbbreviation == subject && co.Number == num
                        join cl in db.Classes on co.CourseId equals cl.CourseId
                        where cl.Season == season && cl.Year == year
                        join ac in db.AssignmentCategories on cl.ClassId equals ac.ClassId
                        where ac.Assignments.Any()
                        select ac;

            // loop through each category
            foreach (var cat in query.ToList())
            {
                var totalPoints = (from a in db.Assignments
                                   where a.CategoryId == cat.CategoryId
                                   select a).ToList().Sum(x => x.MaxPoints);

                var earnedPoints = (from a in db.Assignments
                                    where a.CategoryId == cat.CategoryId
                                    join s in db.Submissions on a.AssignmentId equals s.AssignmentId
                                    select s).ToList().Sum(x => x.Score);

                double percentage = earnedPoints > 0 ? totalPoints / earnedPoints : 0;
                scaledTotal += percentage * cat.GradingWeight;
                weightTotal += cat.GradingWeight;
            }
            // re-scale bc there is no assignment category weight limit
            double scalingFactor   = 100 / weightTotal;
            double totalPercentage = scaledTotal * scalingFactor;

            return(percentageToGrade(totalPercentage));
        }
Beispiel #3
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)
        {
            Boolean classCreated = false;

            using (Team31LMSContext db = new Team31LMSContext())
            {
                var courseQuery =
                    (from course in db.Courses
                     where course.Subject == subject
                     select course.Id).Take(1);

                Console.WriteLine(courseQuery);

                Classes classToAdd = new Classes
                {
                    SemesterSeason = season,
                    SemesterYear   = year,
                    OfferingOf     = courseQuery.First(),
                    Location       = location,
                    Start          = start,
                    End            = end,
                    Teacher        = instructor
                };

                db.Classes.Add(classToAdd);
                int result = db.SaveChanges();
                classCreated = (result == 1);
            }
            return(Json(new { success = classCreated }));
        }
        /// <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)
        {
            Boolean assignmentCreated = false;

            using (Team31LMSContext db = new Team31LMSContext())
            {
                Assignments newAssignment = new Assignments
                {
                    Name     = asgname,
                    Contents = asgcontents,
                    Due      = asgdue,
                    Points   = asgpoints,
                    Category = (from co in db.Courses
                                join c in db.Classes on co.Id equals c.OfferingOf
                                join ac in db.AssignmentCategories on c.Id equals ac.Class
                                where co.Subject == subject && co.Crn == num && c.SemesterSeason == season && c.SemesterYear == year && ac.Name == category
                                select ac.Id).First()
                };

                db.Assignments.Add(newAssignment);
                int result = db.SaveChanges();
                assignmentCreated = (result == 1);
            }
            return(Json(new { success = assignmentCreated }));
        }
Beispiel #5
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)
        {
            // HAS NOT BEEN TESTED
            using (Team31LMSContext db = new Team31LMSContext())
            {
                //checking student
                var studQuery =
                    from stud in db.Students
                    where stud.UId == uid
                    select new
                {
                    fname      = stud.FirstName,
                    lname      = stud.LastName,
                    uid        = stud.UId,
                    department = stud.Major
                };

                if (studQuery.ToArray().Count() > 0)
                {
                    return(Json(studQuery.ToArray()[0]));
                }

                // checking prof
                var profQuery =
                    from prof in db.Professors
                    where prof.UId == uid
                    select new
                {
                    fname      = prof.FirstName,
                    lname      = prof.LastName,
                    uid        = prof.UId,
                    department = prof.Works
                };

                if (profQuery.ToArray().Count() > 0)
                {
                    return(Json(profQuery.ToArray()[0]));
                }


                // checking admin
                var adminQuery =
                    from admin in db.Administrators
                    where admin.UId == uid
                    select new
                {
                    fname = admin.FirstName,
                    lname = admin.LastName,
                    uid   = admin.UId
                };

                if (adminQuery.ToArray().Count() > 0)
                {
                    return(Json(adminQuery.ToArray()[0]));
                }
            }

            return(Json(new { success = false }));
        }
Beispiel #6
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)
 {
     // TODO: I HAVE NOT TESTED THIS
     using (Team31LMSContext db = new Team31LMSContext())
     {
         var contentQuery =
             from assig in db.Assignments
             join as_cat in db.AssignmentCategories on assig.Category equals as_cat.Id
             join clas in db.Classes on as_cat.Class equals clas.Id
             join cours in db.Courses on clas.OfferingOf equals cours.Id
             select assig.Contents;
         return(Content(contentQuery.FirstOrDefault()));
     }
 }
        /*******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)
        {
            using (Team31LMSContext dab = new Team31LMSContext())
            {
                Users u = new Users();

                u.FirstName = fName;
                u.LastName  = lName;
                u.Dob       = DOB;
                u.UId       = getNewUid();
                dab.Users.Add(u);
                switch (role)
                {
                case "Student":
                    Students s = new Students();
                    s.Dob = u.Dob;
                    s.DeptAbbreviation = SubjectAbbrev;
                    s.UId      = u.UId;
                    s.U        = u;
                    u.Students = s;
                    dab.Students.Add(s);
                    dab.SaveChanges();
                    break;

                case "Professor":
                    Professors p = new Professors();
                    p.Dob = u.Dob;
                    p.DeptAbbreviation = SubjectAbbrev;
                    p.UId        = u.UId;
                    p.U          = u;
                    u.Professors = p;
                    dab.Professors.Add(p);
                    dab.SaveChanges();
                    break;

                default:
                    Admins a = new Admins();
                    a.Dob    = u.Dob;
                    a.UId    = u.UId;
                    a.U      = u;
                    u.Admins = a;
                    dab.Admins.Add(a);
                    dab.SaveChanges();
                    break;
                }
                return(u.UId);
            }
        }
        /// <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)
        {
            JsonResult json_query;

            using (Team31LMSContext db = new Team31LMSContext())
            {
                var query =
                    from c in db.Classes
                    join co in db.Courses on c.OfferingOf equals co.Id
                    where c.Teacher == uid
                    select new { subject = co.Subject, number = co.Crn, name = co.Name, season = c.SemesterSeason, year = c.SemesterYear };

                json_query = Json(query.ToArray());
            }
            return(json_query);
        }
Beispiel #9
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)
        {
            JsonResult json_query;

            using (Team31LMSContext db = new Team31LMSContext())
            {
                var query =
                    from e in db.Enrollment
                    join c in db.Classes on e.ClassId equals c.Id
                    join co in db.Courses on c.OfferingOf equals co.Id
                    where e.UId == uid
                    select new { subject = co.Subject, number = co.Crn, name = co.Name, season = c.SemesterSeason, year = c.SemesterYear, grade = e.Grade };

                json_query = Json(query.ToArray());
            }
            return(json_query);
        }
Beispiel #10
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)
        {
            Boolean submitted = false;

            using (Team31LMSContext db = new Team31LMSContext())
            {
                Submissions submission =
                    (from s in db.Submissions
                     join a in db.Assignments on s.AId equals a.Id
                     join ac in db.AssignmentCategories on a.Category equals ac.Id
                     join c in db.Classes on ac.Class equals c.Id
                     join co in db.Courses on c.OfferingOf equals co.Id
                     where s.UId == uid && a.Name == asgname && ac.Name == category && c.SemesterSeason == season && c.SemesterYear == year && co.Subject == subject && co.Crn == num
                     select s).FirstOrDefault();

                if (submission == null)
                {
                    Submissions newSubmission = new Submissions
                    {
                        UId      = uid,
                        Score    = 0,
                        Contents = contents,
                        Time     = DateTime.Now,
                        AId      = (from a in db.Assignments
                                    join ac in db.AssignmentCategories on a.Category equals ac.Id
                                    join c in db.Classes on ac.Class equals c.Id
                                    join co in db.Courses on c.OfferingOf equals co.Id
                                    where a.Name == asgname && ac.Name == category && c.SemesterSeason == season && c.SemesterYear == year && co.Subject == subject && co.Crn == num
                                    select a.Id).First()
                    };

                    db.Submissions.Add(newSubmission);
                    int result = db.SaveChanges();
                    submitted = (result == 1);
                }
                else
                {
                    submission.Contents = contents;
                    submission.Time     = DateTime.Now;
                    int result = db.SaveChanges();
                    submitted = (result == 1);
                }
            }
            return(Json(new { success = submitted }));
        }
        /// <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)
        {
            JsonResult json_query;

            using (Team31LMSContext db = new Team31LMSContext())
            {
                var query =
                    from co in db.Courses
                    join c in db.Classes on co.Id equals c.OfferingOf
                    join ac in db.AssignmentCategories on c.Id equals ac.Class
                    where co.Subject == subject && co.Crn == num && c.SemesterSeason == season && c.SemesterYear == year
                    select new { name = ac.Name, weight = ac.Weight };

                json_query = Json(query.ToArray());
            }
            return(json_query);
        }
Beispiel #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 (Team31LMSContext db = new Team31LMSContext())
            {
                var coursesQuery =
                    from course in db.Courses
                    where course.Subject == subject
                    select new
                {
                    number = course.Crn,
                    name   = course.Name
                };


                return(Json(coursesQuery.ToArray()));
            }
        }
        /*******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)
        {
            JsonResult json_query;

            using (Team31LMSContext db = new Team31LMSContext())
            {
                var query =
                    from s in db.Students
                    join e in db.Enrollment on s.UId equals e.UId
                    join c in db.Classes on e.ClassId equals c.Id
                    join co in db.Courses on c.OfferingOf equals co.Id
                    where co.Subject == subject && co.Crn == num && c.SemesterSeason == season && c.SemesterYear == year
                    select new { fname = s.FirstName, lname = s.LastName, uid = s.UId, dob = s.Dob, grade = e.Grade };

                json_query = Json(query.ToArray());
            }
            return(json_query);
        }
Beispiel #14
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 (Team31LMSContext db = new Team31LMSContext())
            {
                var profsQuery =
                    from prof in db.Professors
                    join dep in db.Departments on prof.Works equals dep.Subject
                    where prof.Works == subject
                    select new
                {
                    lname = prof.LastName,
                    fname = prof.FirstName,
                    uid   = prof.UId
                };

                return(Json(profsQuery.ToArray()));
            }
        }
        /// <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)
        {
            Boolean submissionGraded = false;

            using (Team31LMSContext db = new Team31LMSContext())
            {
                Submissions submission = (from co in db.Courses
                                          join c in db.Classes on co.Id equals c.OfferingOf
                                          join ac in db.AssignmentCategories on c.Id equals ac.Class
                                          join a in db.Assignments on ac.Id equals a.Category
                                          join s in db.Submissions on a.Id equals s.AId
                                          where co.Subject == subject && co.Crn == num && c.SemesterSeason == season && c.SemesterYear == year && ac.Name == category && a.Name == asgname && s.UId == uid
                                          select s).First();
                submission.Score = score;
                int result = db.SaveChanges();
                submissionGraded = (result == 1);
            }
            return(Json(new { success = submissionGraded }));
        }
        /// <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)
        {
            JsonResult json_query;

            using (Team31LMSContext db = new Team31LMSContext())
            {
                var query =
                    from a in db.Assignments
                    join ac in db.AssignmentCategories on a.Category equals ac.Id
                    join c in db.Classes on ac.Class equals c.Id
                    join co in db.Courses on c.OfferingOf equals co.Id
                    where co.Subject == subject && co.Crn == num && c.SemesterSeason == season && c.SemesterYear == year && (ac.Name == category || category == null)
                    select new { aname       = a.Name, cname = ac.Name, due = a.Due,
                                 submissions = (from s in a.Submissions select new { id = s.Id }).Count() };

                json_query = Json(query.Distinct().ToArray());
            }

            return(json_query);
        }
Beispiel #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)
        {
            Boolean courseCreated = false;

            using (Team31LMSContext db = new Team31LMSContext())
            {
                Courses course = new Courses
                {
                    Crn     = number,
                    Name    = name,
                    Subject = subject
                };

                db.Courses.Add(course);
                int result = db.SaveChanges();
                courseCreated = (result == 1) ? true : false;
            }

            return(Json(new { success = courseCreated }));
        }
Beispiel #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 (Team31LMSContext db = new Team31LMSContext())
            {
                var depQuery =
                    from dep in db.Departments
                    select new
                {
                    subject = dep.Subject,
                    dname   = dep.Name,
                    courses = from course in dep.Courses select new
                    {
                        number = course.Crn,
                        cname  = course.Name
                    }
                };

                return(Json(depQuery.ToArray()));
            }
        }
Beispiel #19
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()
        {
            // TODO: Do not return this hard-coded array.

            JsonResult departmentsQuery;

            using (Team31LMSContext db = new Team31LMSContext())
            {
                var query = from dep in db.Departments
                            select dep;

                departmentsQuery = Json(query.ToArray());
            }

            Console.WriteLine(departmentsQuery);

            return(departmentsQuery);

            //return Json(new[] { new { name = "None", subject = "NONE" } });
        }
        /// <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)
        {
            JsonResult json_query;

            using (Team31LMSContext db = new Team31LMSContext())
            {
                var query =
                    from co in db.Courses
                    join c in db.Classes on co.Id equals c.OfferingOf
                    join ac in db.AssignmentCategories on c.Id equals ac.Class
                    join a in db.Assignments on ac.Id equals a.Category
                    join s in db.Submissions on a.Id equals s.AId
                    join st in db.Students on s.UId equals st.UId
                    where co.Subject == subject && co.Crn == num && c.SemesterSeason == season && c.SemesterYear == year && ac.Name == category && a.Name == asgname
                    select new { fname = st.FirstName, lname = st.LastName, uid = st.UId, time = s.Time, score = s.Score };

                json_query = Json(query.ToArray());
            }
            return(json_query);
        }
Beispiel #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)
        {
            JsonResult json_query;

            using (Team31LMSContext db = new Team31LMSContext())
            {
                var query =
                    from e in db.Enrollment
                    join c in db.Classes on e.ClassId equals c.Id
                    join co in db.Courses on c.OfferingOf equals co.Id
                    join ac in db.AssignmentCategories on c.Id equals ac.Class
                    join a in db.Assignments on ac.Id equals a.Category
                    join s in db.Submissions on a.Id equals s.AId into sub
                    from s in sub.DefaultIfEmpty()
                    where e.UId == uid && co.Subject == subject && co.Crn == num && c.SemesterSeason == season && c.SemesterYear == year
                    select new { aname = a.Name, cname = ac.Name, due = a.Due, score = s == null ? null : s.Score };

                json_query = Json(query.ToArray());
            }
            return(json_query);
        }
        /// <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)
        {
            Boolean categoryCreated = false;

            using (Team31LMSContext db = new Team31LMSContext())
            {
                AssignmentCategories newCategories = new AssignmentCategories
                {
                    Name   = category,
                    Weight = (ushort)catweight,
                    Class  = (from co in db.Courses
                              join c in db.Classes on co.Id equals c.OfferingOf
                              where co.Subject == subject && co.Crn == num && c.SemesterSeason == season && c.SemesterYear == year
                              select c.Id).First()
                };

                db.AssignmentCategories.Add(newCategories);
                int result = db.SaveChanges();
                categoryCreated = (result == 1);
            }
            return(Json(new { success = categoryCreated }));
        }
Beispiel #23
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)
        {
            // HAS NOT BEEN TESTED
            using (Team31LMSContext db = new Team31LMSContext())
            {
                var subQuery =
                    from sub in db.Submissions
                    join asgn in db.Assignments on sub.AId equals asgn.Id
                    join asgnc in db.AssignmentCategories on asgn.Category equals asgnc.Id
                    join clas in db.Classes on asgnc.Class equals clas.Id
                    join cours in db.Courses on clas.OfferingOf equals cours.Id
                    where cours.Subject == subject
                    where cours.Crn == num
                    where clas.SemesterSeason == season
                    where clas.SemesterYear == year
                    where asgnc.Name == category
                    where asgn.Name == asgname
                    where sub.UId == uid
                    select sub.Contents;

                return(Content(subQuery.FirstOrDefault()));
            }
        }
Beispiel #24
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 (Team31LMSContext db = new Team31LMSContext())
            {
                var classOffQuery =
                    from clas in db.Classes
                    join course in db.Courses on clas.OfferingOf equals course.Id
                    where course.Subject == subject
                    where course.Crn == number
                    select new
                {
                    season   = clas.SemesterSeason,
                    year     = clas.SemesterYear,
                    location = clas.Location,
                    start    = clas.Start,
                    end      = clas.End,
                    fname    = from prof in db.Professors where prof.UId == clas.Teacher select prof.FirstName,
                    lname    = from prof in db.Professors where prof.UId == clas.Teacher select prof.LastName
                };

                return(Json(classOffQuery.ToArray()));
            }
        }
Beispiel #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)
        {
            JsonResult json_query;

            using (Team31LMSContext db = new Team31LMSContext())
            {
                var query =
                    from e in db.Enrollment
                    where e.UId == uid && e.Grade != null && e.Grade != "--"
                    select GPAFeed(e.Grade);

                if (query.Count() == 0)
                {
                    json_query = Json(new { gpa = 0.0 });
                }
                else
                {
                    // Taking a straight average because all courses are 4 credit hours
                    json_query = Json(new { gpa = query.Average() });
                }
            }
            return(json_query);
        }
Beispiel #26
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)
        {
            Boolean enrolled = false;

            using (Team31LMSContext db = new Team31LMSContext())
            {
                var query =
                    from e in db.Enrollment
                    join c in db.Classes on e.ClassId equals c.Id
                    join co in db.Courses on c.OfferingOf equals co.Id
                    where e.UId == uid && co.Subject == subject && co.Crn == num && c.SemesterSeason == season && c.SemesterYear == year
                    select e;

                if (query.Count() > 0)
                {
                    enrolled = false;
                }
                else
                {
                    Enrollment newEnrollment = new Enrollment
                    {
                        UId     = uid,
                        Grade   = "--",
                        ClassId = (from c in db.Classes
                                   join co in db.Courses on c.OfferingOf equals co.Id
                                   where co.Subject == subject && co.Crn == num && c.SemesterSeason == season && c.SemesterYear == year
                                   select c.Id).First()
                    };

                    db.Enrollment.Add(newEnrollment);
                    int result = db.SaveChanges();
                    enrolled = (result == 1);
                }
            }
            return(Json(new { success = enrolled }));
        }
Beispiel #27
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(Team31LMSContext ctx)
        {
            db = ctx;
        }
Beispiel #28
0
 public CommonController()
 {
     db = new Team31LMSContext();
 }
Beispiel #29
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)
        {
            String nextUid = "not filled";

            using (Team31LMSContext db = new Team31LMSContext())
            {
                var all_uIds = (from stud in db.Students orderby stud.UId descending select new { uId = stud.UId })
                               .Union(from prof in db.Professors orderby prof.UId descending select new { uId = prof.UId })
                               .Union(from adm in db.Administrators orderby adm.UId descending select new { uId = adm.UId });

                var uIds = all_uIds.OrderByDescending(x => x.uId).Take(1);

                // get new Uid
                String highestUid       = uIds.First().uId.ToString();
                int    highestUidNumber = Int32.Parse(highestUid.Substring(1, highestUid.Length - 1));
                int    nextUidNumber    = highestUidNumber + 1;
                nextUid = "u" + nextUidNumber.ToString();


                // chose role
                if (role == "Student")
                {
                    Students st = new Students
                    {
                        UId       = nextUid,
                        FirstName = fName,
                        LastName  = lName,
                        Dob       = DOB,
                        Major     = SubjectAbbrev
                    };
                    db.Students.Add(st);
                    db.SaveChanges();
                }
                else if (role == "Professor")
                {
                    Professors pr = new Professors
                    {
                        UId       = nextUid,
                        FirstName = fName,
                        LastName  = lName,
                        Dob       = DOB,
                        Works     = SubjectAbbrev
                    };
                    db.Professors.Add(pr);
                    db.SaveChanges();
                }
                else if (role == "Administrator")
                {
                    Administrators ad = new Administrators
                    {
                        UId       = nextUid,
                        FirstName = fName,
                        LastName  = lName,
                        Dob       = DOB
                    };
                    db.Administrators.Add(ad);
                    db.SaveChanges();
                }
            }

            return(nextUid);
        }