Пример #1
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. 6016)
        ///            "cname": The course name (e.g. "Database Systems and Applications")
        /// </summary>
        /// <returns>The JSON array</returns>
        // Example JSON string:
        //[{"subject":"ART","dname":"Art","courses":[{"number":2200,"cname":"Beginning Drawing"},
        //{"number":2060,"cname":"Digital Photography"}]},
        //{"subject":"CS","dname":"Computer Science","courses":[{"number":1410,"cname":"Object-Oriented Programming"},
        //{"number":6016,"cname":"Database Systems and Applications"},
        //{"number":2420,"cname":"Introduction to Algorithms and Data Structures"},
        //{"number":3500,"cname":"Software Practice"},
        //{"number":3810,"cname":"Computer Organization"},
        //{"number":5300,"cname":"Artificial Intelligence"}]}
        public IActionResult GetCatalog()
        {
            using (Team9Context db = new Team9Context())
            {
                //find list of departments
                var queryDeptAbbr =
                    from d in db.Department
                    select new { subject = d.Abbreviation, dname = d.Name };

                //get courses for each department and add to an array same size as number of departments
                object[] queryCourses = new object[queryDeptAbbr.Count()];
                for (int i = 0; i < queryDeptAbbr.Count(); i++)
                {
                    var queryCatalog =
                        from d in db.Department
                        join c in db.Course on d.Abbreviation equals c.DId
                        where d.Abbreviation == queryDeptAbbr.ToArray()[i].subject
                        select new { number = c.CourseNum, cname = c.Name };

                    queryCourses[i] = queryCatalog.ToArray();
                }

                //make an array of department names, abbrv, and course using two arrays above.
                object[] catalog = new object[queryDeptAbbr.Count()];
                for (int i = 0; i < catalog.Count(); i++)
                {
                    catalog[i] = new { subject = queryDeptAbbr.ToArray()[i].subject, dname = queryDeptAbbr.ToArray()[i].dname, courses = queryCourses[i] };
                }
                return(Json(catalog));
            };
        }
Пример #2
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)
        {
            //var query = enrolled where e.Student == uid && season, year dept number
            //from a in db.Assignments
            //
            using (Team9Context db = new Team9Context())
            {
                var queryAssignments =
                    from cr in db.Course
                    join cl in db.Class on cr.CatId equals cl.CatId into join1
                    from j1 in join1.DefaultIfEmpty()

                    join cat in db.AssignmentCategory on j1.ClassId equals cat.ClassId into join2
                    from j2 in join2.DefaultIfEmpty()

                    join ass in db.Assignment on j2.CatId equals ass.Category
                    where cr.CourseNum == num && j1.Season == season && j1.Year == year && cr.DId == subject
                    select new { aID = ass.AId, aname = ass.Name, cname = j2.Name, due = ass.DueDateTime };

                //take that query result and  join it with the submission table aID|Name --- left join---> uID|aID and get the nulls where the uid matches
                var queryResult =
                    from qa in queryAssignments
                    join sub in db.Submission on new { aID = qa.aID, uID = uid } equals new { aID = sub.AId, uID = sub.UId } into join3
                from j3 in join3.DefaultIfEmpty()
                select new { aname = qa.aname, cname = qa.cname, due = qa.due, score = j3 == null ? null : (int?)j3.Score };

                return(Json(queryResult.ToArray()));
            }
        }
Пример #3
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.</returns>
        public IActionResult Enroll(string subject, int num, string season, int year, string uid)
        {
            using (Team9Context db = new Team9Context())
            {
                //var queryEnrolled =
                //    from s in db.Student
                //    join e in db.Enrolled on s.UId equals e.UId
                //    join cl in db.Class on e.ClassId equals cl.ClassId
                //    join cr in db.Course on cl.CatId equals cr.CatId
                //    where e.UId == uid && cr.CourseNum == num && cl.Season == season && cl.Year == year && cr.DId == subject
                //    select new { uid = e.UId, classID = cl.ClassId };

                var queryEnrolled =
                    from cr in db.Course
                    join cl in db.Class on cr.CatId equals cl.CatId into join1
                    from j1 in join1.DefaultIfEmpty()

                    join e in db.Enrolled on j1.ClassId equals e.ClassId into join3
                    from j3 in join3.DefaultIfEmpty()

                    where cr.CourseNum == num && j1.Season == season && j1.Year == year && cr.DId == subject
                    select new { uid = j3.UId ?? null, classID = j1.ClassId };

                bool uidEnrolled = false;

                for (int i = 0; i < queryEnrolled.Count(); i++)
                {
                    if (queryEnrolled.ToArray()[0].uid == uid)
                    {
                        uidEnrolled = true;
                    }
                }

                if (!uidEnrolled)
                {
                    //insert into enroll, grade, uid, classID
                    Enrolled enroll = new Enrolled();
                    enroll.UId     = uid;
                    enroll.ClassId = queryEnrolled.ToArray()[0].classID;
                    enroll.Grade   = "--";

                    db.Enrolled.Add(enroll);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine("Problem saving changes: " + e);
                    }

                    return(Json(new { success = true }));
                }
                else
                {
                    return(Json(new { success = false }));
                }
            }
        }
 /// <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></returns>
 public IActionResult GetProfessors(string subject)
 {
     using (Team9Context db = new Team9Context())
     {
         var queryProf =
             from prof in db.Professor
             where prof.Department == subject
             select new { lname = prof.LastName, fname = prof.FirstName, uid = prof.UId };
         return(Json(queryProf.ToArray()));
     }
 }
Пример #5
0
        /*******Begin code to modify********/


        /// <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.
            using (Team9Context db = new Team9Context())
            {
                var queryDepartments =
                    from d in db.Department
                    select new { name = d.Name, subject = d.Abbreviation };

                return(Json(queryDepartments.ToArray()));
            }
        }
        /// <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 6016 for this course)
        /// "name" - The course name (as in "Database Systems..." for this course)
        /// </summary>
        /// <param name="subject">The department subject abbreviation</param>
        /// <returns></returns>
        public IActionResult GetCourses(string subject)
        {
            using (Team9Context db = new Team9Context())
            {
                var queryCourses =
                    from cr in db.Course
                    where cr.DId == subject
                    select new { number = cr.CourseNum, name = cr.Name };

                return(Json(queryCourses.ToArray()));
            }
        }
Пример #7
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.
        /// </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 (Team9Context db = new Team9Context())
            {
                var queryAssignSubmissionContents =
                    from cr in db.Course
                    join cl in db.Class on cr.CatId equals cl.CatId into join1
                    from j1 in join1.DefaultIfEmpty()

                    join ac in db.AssignmentCategory on j1.ClassId equals ac.ClassId into join2
                    from j2 in join2.DefaultIfEmpty()

                    join a in db.Assignment on j2.CatId equals a.Category into join3
                    from j3 in join3.DefaultIfEmpty()

                    join sub in db.Submission on j3.AId equals sub.AId into join4
                    from j4 in join4.DefaultIfEmpty()

                    where cr.DId == subject && cr.CourseNum == num && j1.Season == season && j1.Year == year &&
                    j2.Name == category && j3.Name == asgname && j4.UId == uid
                    select new { content = j4.Contents, uid = j4.UId, assName = j3.Name };

                if (queryAssignSubmissionContents.ToArray().Count() != 0)
                {
                    return(Content(queryAssignSubmissionContents.ToArray()[0].content));
                }
                else
                {
                    return(Content(""));
                }


                //bool subTextAdded = false;

                //for (int i = 0; i < queryAssignSubmissionContents.Count(); i++)
                //{
                //    if (queryAssignSubmissionContents.ToArray()[i].uid.Equals(uid) && queryAssignSubmissionContents.ToArray()[i].assName.Equals(asgname))
                //    {
                //        subTextAdded = true;
                //    }
                //}

                //if (!subTextAdded)
                //{
                //    return Content(queryAssignSubmissionContents.ToArray()[0].content);
                //}
                //else
                //{
                //    return Content("");
                //}
            }
        }
Пример #8
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 (Team9Context db = new Team9Context())
            {
                var queryAssSubmissions =
                    from cr in db.Course
                    join cl in db.Class on cr.CatId equals cl.CatId
                    join ac in db.AssignmentCategory on cl.ClassId equals ac.ClassId
                    join ass in db.Assignment on ac.CatId equals ass.Category
                    join sub in db.Submission on ass.AId equals sub.AId
                    join stud in db.Student on sub.UId equals stud.UId
                    where cr.CourseNum == num && cl.Season == season && cl.Year == year && cr.DId == subject &&
                    ac.Name == category && ass.Name == asgname
                    select new { fname = stud.FirstName, lname = stud.LastName, uid = stud.UId, time = sub.Time, score = sub.Score };

                if (queryAssSubmissions.Count() != 0)
                {
                    return(Json(queryAssSubmissions.ToArray()));
                }
                else
                {
                    return(Json(new { }));
                }


                //var queryAssSubmissions =
                //    from cr in db.Course
                //    join cl in db.Class on cr.CatId equals cl.CatId into join1
                //    from j1 in join1.DefaultIfEmpty()

                //    join ac in db.AssignmentCategory on j1.ClassId equals ac.ClassId into join2
                //    from j2 in join2.DefaultIfEmpty()

                //    join ass in db.Assignment on j2.CatId equals ass.Category into join3
                //    from j3 in join3.DefaultIfEmpty()

                //    join sub in db.Submission on j3.AId equals sub.AId into join4
                //    from j4 in join4.DefaultIfEmpty()

                //    join stud in db.Student on j4.UId equals stud.UId into join5
                //    from j5 in join5.DefaultIfEmpty()

                //    where cr.CourseNum == num && j1.Season == season && j1.Year == year && cr.DId == subject
                //    && j2.Name == category && j3.Name == asgname
                //    select new { fname = j5.FirstName ?? null, lname = j5.LastName ?? null, uid = j5.UId ?? null, time = j4.Time, score = j4.Score }; //(DateTime?) j4.Time == null ? null : j4.Time

                //if (queryAssSubmissions.ToArray().Count() <= 0) {
                //    return Json(new { });
                //}
            }
        }
Пример #9
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 (Team9Context db = new Team9Context())
            {
                var queryAssignCats =
                    from cr in db.Course
                    join cl in db.Class on cr.CatId equals cl.CatId
                    join ac in db.AssignmentCategory on cl.ClassId equals ac.ClassId
                    where cr.CourseNum == num && cl.Season == season && cl.Year == year
                    select new { name = ac.Name, weight = ac.Weight };

                return(Json(queryAssignCats.ToArray()));
            }
        }
Пример #10
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 6016)
        /// "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 (Team9Context db = new Team9Context())
            {
                var queryProf =
                    from p in db.Professor
                    join cr in db.Course on p.Department equals cr.DId
                    join cl in db.Class on cr.CatId equals cl.CatId
                    where p.UId == uid && cl.Instructor == uid
                    select new { subject = cr.DId, number = cr.CourseNum, name = cr.Name, season = cl.Season, year = cl.Year };

                return(Json(queryProf.ToArray()));
            }
        }
Пример #11
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"></param>
        /// <param name="number"></param>
        /// <returns></returns>
        public IActionResult GetClassOfferings(string subject, int number)
        {
            using (Team9Context db = new Team9Context())
            {
                var queryClass =
                    from cr in db.Course
                    join d in db.Class on cr.CatId equals d.CatId
                    join prof in db.Professor on d.Instructor equals prof.UId
                    where cr.CourseNum == number && subject == cr.DId
                    select new { season = d.Season, year = d.Year, location = d.Location, start = d.StartTime, end = d.EndTime, fname = prof.FirstName, lname = prof.LastName };

                return(Json(queryClass.ToArray()));
            }
        }
Пример #12
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 (Team9Context db = new Team9Context())
            {
                var queryAssignmentContents =
                    from cr in db.Course
                    join cl in db.Class on cr.CatId equals cl.CatId
                    join ac in db.AssignmentCategory on cl.ClassId equals ac.ClassId
                    join a in db.Assignment on ac.CatId equals a.Category
                    where cr.DId == subject && cr.CourseNum == num && cl.Season == season && cl.Year == year && ac.Name == category && a.Name == asgname
                    select new { content = a.Contents };

                return(Content(queryAssignmentContents.ToArray()[0].content));
            }
        }
Пример #13
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 (Team9Context db = new Team9Context())
            {
                var queryStudentsInClass =
                    from cr in db.Course
                    join cl in db.Class on cr.CatId equals cl.CatId
                    join e in db.Enrolled on cl.ClassId equals e.ClassId
                    join s in db.Student on e.UId equals s.UId
                    where cr.DId == subject && cr.CourseNum == num && cl.Season == season && cl.Year == year
                    select new { fname = s.FirstName, lname = s.LastName, uid = s.UId, dob = s.DOB, grade = e.Grade };

                return(Json(queryStudentsInClass.ToArray()));
            }
        }
Пример #14
0
        /// <summary>
        /// Creates a new assignment category for the specified class.
        /// A class can not have two categories with the same name.
        /// 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)
        {
            using (Team9Context db = new Team9Context())
            {
                var queryCatagory =
                    from cr in db.Course
                    join cl in db.Class on cr.CatId equals cl.CatId into join1
                    from j1 in join1.DefaultIfEmpty()

                    join ac in db.AssignmentCategory on j1.ClassId equals ac.ClassId into join2
                    from j2 in join2.DefaultIfEmpty()

                    where cr.CourseNum == num && j1.Season == season && j1.Year == year && cr.DId == subject
                    select new { catName = j2.Name ?? null, classID = j1.ClassId };

                bool categoryAdded = false;

                for (int i = 0; i < queryCatagory.Count(); i++)
                {
                    if (queryCatagory.ToArray()[i].catName != null && queryCatagory.ToArray()[i].catName.Equals(category))
                    {
                        categoryAdded = true;
                    }
                }

                if (!categoryAdded)
                {
                    //insert into enroll, grade, uid, classID
                    AssignmentCategory catToAdd = new AssignmentCategory();
                    catToAdd.Name    = category;
                    catToAdd.Weight  = catweight;
                    catToAdd.ClassId = queryCatagory.ToArray()[0].classID;

                    db.AssignmentCategory.Add(catToAdd);
                    try { db.SaveChanges(); }
                    catch (Exception e) {
                        System.Diagnostics.Debug.WriteLine("Problem saving changes: " + e);
                    }


                    return(Json(new { success = true }));
                }
                else
                {
                    return(Json(new { success = false }));
                }
            }
        }
Пример #15
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 (Team9Context db = new Team9Context())
            {
                if (score < 0)
                {
                    return(Json(new { success = false }));
                }

                var queryAssSubmissions =
                    from cr in db.Course
                    join cl in db.Class on cr.CatId equals cl.CatId
                    join ac in db.AssignmentCategory on cl.ClassId equals ac.ClassId
                    join ass in db.Assignment on ac.CatId equals ass.Category
                    join sub in db.Submission on ass.AId equals sub.AId
                    join stud in db.Student on sub.UId equals stud.UId

                    where cr.CourseNum == num && cl.Season == season && cl.Year == year && cr.DId == subject &&
                    ac.Name == category && ass.Name == asgname && stud.UId == uid
                    select new { sub, aPoints = ass.Points, classID = cl.ClassId };

                Submission newSub = null;
                if (queryAssSubmissions.Count() != 0)
                {
                    newSub       = queryAssSubmissions.ToArray()[0].sub;
                    newSub.Score = score;
                    //db.Submission.Update(newSub);
                    db.SaveChanges();
                }


                //calculate grade and submit to enroll
                string grade = CalculateGrade(queryAssSubmissions.ToArray()[0].classID, uid);

                var queryEnroll =
                    from e in db.Enrolled
                    where e.UId == uid && e.ClassId == queryAssSubmissions.ToArray()[0].classID
                    select e;

                Enrolled enroll = queryEnroll.ToArray()[0];
                enroll.Grade = grade;
                db.Enrolled.Update(enroll);

                db.SaveChanges();
                return(Json(new { success = true }));
            }
        }
Пример #16
0
 /// <summary>
 /// Assume that a specific class can not have two categories with the same name.
 /// 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 (Team9Context db = new Team9Context())
     {
         if (category == null)
         {
             var queryAssignments =
                 from cr in db.Course
                 join cl in db.Class on cr.CatId equals cl.CatId
                 join ac in db.AssignmentCategory on cl.ClassId equals ac.ClassId
                 join a in db.Assignment on ac.CatId equals a.Category
                 where cr.CourseNum == num && cl.Season == season && cl.Year == year
                 select new
             {
                 aname       = a.Name,
                 cname       = ac.Name,
                 due         = a.DueDateTime,
                 submissions = (from sub in db.Submission
                                where sub.AId == a.AId
                                select sub).Count()
             };
             return(Json(queryAssignments.ToArray()));
         }
         else
         {
             var queryAssignments =
                 from cr in db.Course
                 join cl in db.Class on cr.CatId equals cl.CatId
                 join ac in db.AssignmentCategory on cl.ClassId equals ac.ClassId
                 join a in db.Assignment on ac.CatId equals a.Category
                 where cr.CourseNum == num && cl.Season == season && cl.Year == year && ac.Name == category
                 select new
             {
                 aname       = a.Name,
                 cname       = ac.Name,
                 due         = a.DueDateTime,
                 submissions = (from sub in db.Submission
                                where sub.AId == a.AId
                                select sub).Count()
             };
             return(Json(queryAssignments.ToArray()));
         }
     }
 }
        /// <summary>
        /// Creates a course.
        /// </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 (Team9Context db = new Team9Context())
            {
                var queryAllCourse =
                    from cr in db.Course orderby cr.CatId descending
                    select cr;

                int maxCorId = queryAllCourse.ToArray()[0].CatId;

                var queryCourses =
                    from cr in db.Course
                    where cr.CourseNum == number && cr.Name == name && cr.DId == subject
                    select new { courseNumber = cr.CourseNum, courseName = cr.Name, courseSubject = cr.DId };

                if (queryCourses.Count() == 0)
                {
                    Course newCourse = new Course();
                    newCourse.DId       = subject;
                    newCourse.CourseNum = number;
                    newCourse.Name      = name;
                    newCourse.CatId     = maxCorId + 1;

                    db.Course.Add(newCourse);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine("Problem saving changes: " + e);
                    }


                    return(Json(new { success = true }));
                }
                else
                {
                    return(Json(new { success = false }));
                }
            }
        }
Пример #18
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 (Team9Context db = new Team9Context())
            {
                var queryProfessors =
                    from d in db.Professor
                    join dpt in db.Department on d.Department equals dpt.Abbreviation
                    where d.UId == uid
                    select new { fname = d.FirstName, lname = d.LastName, uid = d.UId, department = dpt.Name };

                var queryStudent =
                    from d in db.Student
                    join mjr in db.Department on d.Major equals mjr.Abbreviation
                    where d.UId == uid
                    select new { fname = d.FirstName, lname = d.LastName, uid = d.UId, department = mjr.Name };

                var queryAdmin =
                    from d in db.Administrator
                    where d.UId == uid
                    select new { fname = d.FirstName, lname = d.LastName, uid = d.UId }; //admin does not have dept or major


                if (queryProfessors.Count() != 0)
                {
                    return(Json(queryProfessors.ToArray()[0]));
                }
                else if (queryStudent.Count() != 0)
                {
                    return(Json(queryStudent.ToArray()[0]));
                }
                else if (queryAdmin.Count() != 0)
                {
                    return(Json(queryAdmin.ToArray()[0]));
                }

                return(Json(new { success = false }));
            }
        }
Пример #19
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 6016)
        /// "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 (Team9Context db = new Team9Context())
            {
                var queryStudent =
                    from s in db.Student
                    join en in db.Enrolled on s.UId equals en.UId
                    join cl in db.Class on en.ClassId equals cl.ClassId
                    join cr in db.Course on cl.CatId equals cr.CatId
                    where s.UId == uid
                    select new { subject = cr.DId, number = cr.CourseNum, name = cr.Name, season = cl.Season, year = cl.Year, grade = en.Grade };

                //for (int i = 0; i < 10; i++)
                //{
                //    System.Diagnostics.Debug.WriteLine("");
                //}
                //foreach (var item in queryStudent.ToArray())
                //{
                //    System.Diagnostics.Debug.WriteLine(item);
                //}
                //System.Diagnostics.Debug.WriteLine(Json(queryStudent.ToArray()).ToString());
                return(Json(queryStudent.ToArray()));
            }
        }
Пример #20
0
 public CommonController()
 {
     // TODO: Initialize your context once you have scaffolded your team database
     // for example:
     db = new Team9Context();
 }
        /// <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.</returns>
        public IActionResult CreateClass(string subject, int number, string season, int year, DateTime start, DateTime end, string location, string instructor)
        {
            using (Team9Context db = new Team9Context())
            {
                var queryAllClasses =
                    from cl in db.Class
                    orderby cl.ClassId descending
                    select cl;

                int maxClassID = queryAllClasses.ToArray()[0].ClassId;

                var queryClass =
                    from cr in db.Course
                    join cl in db.Class on cr.CatId equals cl.CatId

                    ////////////////////////////////////////////////////////// fix timing for class time range
                    where cr.DId == subject && cr.CourseNum == number && cl.Season == season && cl.Year == year && cl.Location == location &&
                    ((cl.StartTime <= start.TimeOfDay && cl.EndTime >= end.TimeOfDay)         //overlap fully
                     //|| (cl.StartTime >= start.TimeOfDay && cl.EndTime <= end.TimeOfDay) // inside fully
                     || (cl.EndTime > start.TimeOfDay && cl.EndTime <= end.TimeOfDay) ||     // end in middle
                     (cl.StartTime > start.TimeOfDay && cl.StartTime < end.TimeOfDay)           // start in middle
                    )
                    select cl;

                var queryCourse =
                    from cr in db.Course
                    where cr.DId == subject && cr.CourseNum == number
                    select cr.CatId;


                if (queryClass.Count() == 0)
                {
                    Class newClass = new Class();
                    newClass.Season     = season;
                    newClass.Year       = year;
                    newClass.StartTime  = start.TimeOfDay;
                    newClass.EndTime    = end.TimeOfDay;
                    newClass.Instructor = instructor;
                    newClass.Location   = location;
                    newClass.ClassId    = maxClassID + 1;
                    newClass.CatId      = queryCourse.ToArray()[0];

                    db.Class.Add(newClass);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine("Problem saving changes: " + e);
                    }


                    return(Json(new { success = true }));
                }
                else
                {
                    return(Json(new { success = false }));
                }
            }
        }
Пример #22
0
        /*******Begin code to modify********/

        public string generateUID()
        {
            string uid          = "u0000000";
            string studentUID   = "u0000000";
            string professorUID = "u0000000";
            string adminUID     = "u0000000";


            using (Team9Context db = new Team9Context())
            {
                //SELECT uID FROM Team9.Professor ORDER BY uID desc;
                var queryProf =
                    (from p in db.Professor
                     orderby p.UId descending
                     select new { uid = p.UId }).Take(1);

                if (queryProf.Count() > 0)
                {
                    professorUID = queryProf.First().ToString();
                }

                var queryAdmin =
                    (from a in db.Administrator
                     orderby a.UId descending
                     select new { uid = a.UId }).Take(1);

                if (queryAdmin.Count() > 0)
                {
                    adminUID = queryAdmin.First().ToString();
                }

                var queryStudent =
                    (from s in db.Student
                     orderby s.UId descending
                     select new { uid = s.UId }).Take(1);     //this didn't have take 1 on 7/19 at 6:11 pm

                if (queryStudent.Count() > 0)
                {
                    studentUID = queryStudent.First().ToString();
                }
                string[] maxUIDs = { professorUID, adminUID, studentUID };

                //Print Out Debug Stuff
                //System.Diagnostics.Debug.WriteLine("Professor uID:" + professorUID);
                //System.Diagnostics.Debug.WriteLine("Admin uID:" + adminUID);
                //System.Diagnostics.Debug.WriteLine("Student uID:" + studentUID);

                //for(int i = 0; i < 10; i++)
                //{
                //    System.Diagnostics.Debug.WriteLine("");
                //}
                //System.Diagnostics.Debug.WriteLine("Max UIDS:");
                //int count = 0;
                //foreach (string i in maxUIDs) {
                //    System.Diagnostics.Debug.WriteLine(count + ": " + i);
                //    count++;
                //}
                //for (int i = 0; i < 10; i++)
                //{
                //    System.Diagnostics.Debug.WriteLine("");
                //}

                int[] maxUIDsAsInts = new int[3];
                int   UIDAsInt;
                for (int i = 0; i < maxUIDs.Length; i++)
                {
                    if (!maxUIDs[i].Equals("u0000000"))
                    {
                        string[] splitID = maxUIDs[i].Split(" ");
                        maxUIDs[i] = splitID[3];
                    }

                    //drop the u
                    string numOnly = maxUIDs[i].TrimStart('u');

                    //convert uid to an int
                    try
                    {
                        UIDAsInt         = Convert.ToInt32(numOnly);
                        maxUIDsAsInts[i] = UIDAsInt;
                    }
                    catch (FormatException E)
                    {
                        Console.WriteLine(E);
                    }
                }

                //find the max uid out of the three uids
                int nextUID = maxUIDsAsInts[0];
                foreach (int id in maxUIDsAsInts)
                {
                    if (nextUID < id)
                    {
                        nextUID = id;
                    }
                }

                //increment the uid by 1
                nextUID++;

                System.Diagnostics.Debug.WriteLine("NEXT UID: " + nextUID);

                //edge case if we run out of user ids
                if (nextUID > 9999999)
                {
                    System.Diagnostics.Debug.WriteLine("No more user ids.");
                }

                //cast uid back to string, append u and padding
                uid = 'u' + nextUID.ToString().PadLeft(7, '0');
                System.Diagnostics.Debug.WriteLine(uid);
            }
            return(uid);
        }
Пример #23
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
        /// </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 (Team9Context db = new Team9Context())
            {
                if (contents == null)
                {
                    return(Json(new { success = false }));
                }

                var queryAssignments =
                    from cr in db.Course
                    join cl in db.Class on cr.CatId equals cl.CatId into join1
                    from j1 in join1.DefaultIfEmpty()

                    join ac in db.AssignmentCategory on j1.ClassId equals ac.ClassId into join2
                    from j2 in join2.DefaultIfEmpty()

                    join ass in db.Assignment on j2.CatId equals ass.Category into join3
                    from j3 in join3.DefaultIfEmpty()

                    where cr.CourseNum == num && j1.Season == season && j1.Year == year && cr.DId == subject &&
                    j2.Name == category && j3.Name == asgname
                    select new { aID = j3.AId };

                int assID = queryAssignments.ToArray()[0].aID;

                var querySubmission =
                    from sub in db.Submission
                    where sub.AId == assID && sub.UId == uid
                    select sub;


                Submission newSub = null;
                if (querySubmission.Count() != 0)
                {
                    newSub          = querySubmission.ToArray()[0];
                    newSub.Contents = contents;
                    newSub.Time     = DateTime.Now;

                    db.Submission.Update(newSub);
                }
                else
                {
                    newSub          = new Submission();
                    newSub.Time     = DateTime.Now;
                    newSub.Contents = contents;
                    newSub.Score    = 0;
                    newSub.UId      = uid;
                    newSub.AId      = assID;
                    //no need to add score value into the table here

                    db.Submission.Add(newSub);
                }
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("Problem saving changes: " + e);
                }
                return(Json(new { success = true }));
            }
        }
Пример #24
0
        /// <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. This uID must not be used by anyone else</returns>
        public string CreateNewUser(string fName, string lName, DateTime DOB, string SubjectAbbrev, string role)
        {
            string uid = generateUID();

            using (Team9Context db = new Team9Context())
            {
                if (role == "Administrator")
                {
                    Administrator admin = new Administrator();
                    admin.UId       = uid;
                    admin.FirstName = fName;
                    admin.LastName  = lName;
                    admin.DOB       = DOB;
                    admin.Password  = "";

                    db.Administrator.Add(admin);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine("Problem saving changes: " + e);
                    }
                }

                if (role == "Professor")
                {
                    Professor prof = new Professor();
                    prof.UId        = uid;
                    prof.FirstName  = fName;
                    prof.LastName   = lName;
                    prof.DOB        = DOB;
                    prof.Department = SubjectAbbrev;
                    prof.Password   = "";

                    db.Professor.Add(prof);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine("Problem saving changes: " + e);
                    }
                }

                if (role == "Student")
                {
                    Student student = new Student();
                    student.UId       = uid;
                    student.FirstName = fName;
                    student.LastName  = lName;
                    student.DOB       = DOB;
                    student.Major     = SubjectAbbrev;
                    student.Password  = "";

                    db.Student.Add(student);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine("Problem saving changes: " + e);
                    }
                }
            }
            return(uid);
        }
Пример #25
0
        /// <summary>
        /// Creates a new assignment for the given class and category.
        /// An assignment category (which belongs to a class) can not have two assignments with
        /// the same name.
        /// If an assignment of the given category 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 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)
        {
            using (Team9Context db = new Team9Context())
            {
                var queryAssignment =
                    from cr in db.Course
                    join cl in db.Class on cr.CatId equals cl.CatId into join1
                    from j1 in join1.DefaultIfEmpty()

                    join ac in db.AssignmentCategory on j1.ClassId equals ac.ClassId into join2
                    from j2 in join2.DefaultIfEmpty()

                    join ass in db.Assignment on j2.CatId equals ass.Category into join3
                    from j3 in join3.DefaultIfEmpty()

                    where cr.CourseNum == num && j1.Season == season && j1.Year == year && cr.DId == subject &&
                    j2.Name == category && j3.Name == asgname
                    select new { assignName = j3.Name ?? null, catID = j2.CatId, points = j3.Points, classID = j1.ClassId };

                var queryCatagory =
                    from cr in db.Course
                    join cl in db.Class on cr.CatId equals cl.CatId into join1
                    from j1 in join1.DefaultIfEmpty()

                    join ac in db.AssignmentCategory on j1.ClassId equals ac.ClassId into join2
                    from j2 in join2.DefaultIfEmpty()

                    where cr.CourseNum == num && j1.Season == season && j1.Year == year && cr.DId == subject && j2.Name == category
                    select new { catName = j2.Name ?? null, classID = j1.ClassId, catID = j2.CatId };

                var queryStudents =
                    from s in db.Student
                    join e in db.Enrolled
                    on s.UId equals e.UId
                    where e.ClassId == queryAssignment.ToArray()[0].classID
                    select s;


                bool assAdded = false;

                for (int i = 0; i < queryAssignment.Count(); i++)
                {
                    if (queryAssignment.ToArray()[i].assignName.Equals(asgname))
                    {
                        assAdded = true;
                    }
                }

                if (!assAdded)
                {
                    Assignment assToAdd = new Assignment();
                    assToAdd.Name        = asgname;
                    assToAdd.DueDateTime = asgdue;
                    assToAdd.Contents    = asgcontents;
                    assToAdd.Points      = asgpoints;
                    assToAdd.Category    = queryCatagory.ToArray()[0].catID;

                    db.Assignment.Add(assToAdd);
                    db.SaveChanges();

                    string grade = "";

                    for (int i = 0; i < queryStudents.Count(); i++)
                    {
                        //calculate grade and submit to enroll
                        grade = CalculateGrade(queryCatagory.ToArray()[0].classID, queryStudents.ToArray()[i].UId);
                        var queryEnroll =
                            from e in db.Enrolled
                            where e.ClassId == queryAssignment.ToArray()[0].classID && e.UId == queryStudents.ToArray()[i].UId
                            select e;

                        Enrolled enroll = queryEnroll.ToArray()[0];
                        enroll.Grade = grade;
                        db.SaveChanges();
                    }
                    return(Json(new { success = true }));
                }
                else
                {
                    return(Json(new { success = false }));
                }
            }
        }