Esempio n. 1
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).
        /// Does *not* automatically reject late submissions.
        /// </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 (Team36LMSContext db = new Team36LMSContext())
            {
                var query =
                    from c in db.Courses
                    join cl in db.Classes on c.CourseId equals cl.CourseId
                    where c.Subject == subject && c.Number == num && cl.Season == season && cl.Year == year

                    join e in db.Enrollment on uid equals e.UId
                    where e.ClassId == cl.ClassId

                    join ac in db.AssignmentCategories on e.ClassId equals ac.ClassId
                    where ac.Name == category

                    join assignment in db.Assignments on ac.Acid equals assignment.Acid
                    where assignment.Name == asgname

                    select assignment.Aid;

                var assignmentID = query.First();

                //System.Diagnostics.Debug.WriteLine(assignmentID);
                var query2 =
                    from s in db.Submission
                    where s.UId == uid && s.Aid == assignmentID
                    select s;

                if (query2.Count() != 0)
                {
                    //update
                    query2.First().Contents = contents;
                    query2.First().DateTime = DateTime.Now;

                    db.SaveChanges();

                    return(Json(new { success = true }));
                }

                Submission newS = new Submission();
                newS.UId      = uid;
                newS.DateTime = DateTime.Now;
                newS.Score    = 0;
                newS.Contents = contents;
                newS.Aid      = assignmentID;

                db.Submission.Add(newS);
                db.SaveChanges();

                return(Json(new { success = true }));
            }
        }
Esempio n. 2
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 (Team36LMSContext db = new Team36LMSContext())
            {
                var query = from s in db.Submission
                            join st in db.Students on s.UId equals st.UId
                            join a in db.Assignments on s.Aid equals a.Aid
                            where a.Name == asgname
                            join ac in db.AssignmentCategories on a.Acid equals ac.Acid
                            where ac.Name == category
                            join c in db.Classes on ac.ClassId equals c.ClassId
                            where c.Season == season && c.Year == year
                            join cou in db.Courses on c.CourseId equals cou.CourseId
                            where cou.Subject == subject && cou.Number == num
                            select new
                {
                    fname = st.FirstName,
                    lname = st.LastName,
                    uid   = st.UId,
                    time  = s.DateTime,
                    score = s == null ? null : (uint?)s.Score
                };

                db.SaveChanges();

                return(Json(query.ToArray()));
            }
        }
Esempio n. 3
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 (Team36LMSContext db = new Team36LMSContext())
            {
                var query = from s in db.Submission
                            where s.UId == uid
                            join a in db.Assignments on s.Aid equals a.Aid
                            where a.Name == asgname
                            join ac in db.AssignmentCategories on a.Acid equals ac.Acid
                            where ac.Name == category
                            join c in db.Classes on ac.ClassId equals c.ClassId
                            where c.Season == season && c.Year == year
                            join cou in db.Courses on c.CourseId equals cou.CourseId
                            where cou.Subject == subject && cou.Number == num
                            select s;

                foreach (var s in query)
                {
                    s.Score = (uint)score;
                }

                var query2 = from s in db.Submission
                             where s.UId == uid
                             join a in db.Assignments on s.Aid equals a.Aid
                             join ac in db.AssignmentCategories on a.Acid equals ac.Acid
                             select new
                {
                    score  = s.Score,
                    weight = ac.GradingWeight
                };

                double newOverallGrade = 0;
                foreach (var i in query2)
                {
                    double w      = i.weight;
                    double weight = w / 100.0;
                    double s      = i.score;
                    newOverallGrade += (s * weight);
                }

                var query3 = from e in db.Enrollment
                             where e.UId == uid
                             select e;

                foreach (var i in query3)
                {
                    i.Grade = newOverallGrade.ToString();
                }

                db.SaveChanges();

                return(Json(new { success = true }));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a new assignment for the given class and category.
        /// </summary>
        /// <param name="subject">The course subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
        /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
        /// <param name="category">The name of the assignment category in the class</param>
        /// <param name="asgname">The new assignment name</param>
        /// <param name="asgpoints">The max point value for the new assignment</param>
        /// <param name="asgdue">The due DateTime for the new assignment</param>
        /// <param name="asgcontents">The contents of the new assignment</param>
        /// <returns>A JSON object containing success = true/false,
        /// false if an assignment with the same name already exists in the same assignment category.</returns>
        public IActionResult CreateAssignment(string subject, int num, string season, int year, string category, string asgname, int asgpoints, DateTime asgdue, string asgcontents)
        {
            int newAssignmentID = 1;

            using (Team36LMSContext db = new Team36LMSContext())
            {
                var query = (from a in db.Assignments
                             where a.Name == asgname
                             join ac in db.AssignmentCategories on a.Acid equals ac.Acid
                             select a).FirstOrDefault();
                if (query != null)
                {
                    return(Json(new { success = false }));
                }


                var query2 = (from ac in db.AssignmentCategories
                              where ac.Name == category
                              join c in db.Classes on ac.ClassId equals c.ClassId
                              where c.Year == year && c.Season == season
                              join cou in db.Courses on c.CourseId equals cou.CourseId
                              where cou.Number == num && cou.Subject == subject
                              select new
                {
                    assiCat = ac.Acid
                }).FirstOrDefault();

                var assignmentIDs = (from a in db.Assignments
                                     select a.Aid);
                List <int> list = new List <int>();
                foreach (int a in assignmentIDs)
                {
                    list.Add(a);
                }

                if (list.Count() > 0)
                {
                    newAssignmentID = list.Max() + 1;
                }

                Assignments assignment = new Assignments();
                assignment.Name          = asgname;
                assignment.Contents      = asgcontents;
                assignment.Due           = asgdue;
                assignment.MaxPointValue = (uint)asgpoints;
                assignment.Aid           = newAssignmentID;
                assignment.Acid          = query2.assiCat;

                db.Assignments.Add(assignment);
                db.SaveChanges();

                return(Json(new { success = true }));
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a new assignment category for the specified 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>
        /// <param name="category">The new category name</param>
        /// <param name="catweight">The new category weight</param>
        /// <returns>A JSON object containing {success = true/false},
        ///	false if an assignment category with the same name already exists in the same class.</returns>
        public IActionResult CreateAssignmentCategory(string subject, int num, string season, int year, string category, int catweight)
        {
            int newAssignmentCatID = 1;

            using (Team36LMSContext db = new Team36LMSContext())
            {
                var query = (from ac in db.AssignmentCategories
                             where ac.Name == category
                             join c in db.Classes on ac.ClassId equals c.ClassId
                             select ac).FirstOrDefault();
                if (query != null)
                {
                    return(Json(new { success = false }));
                }


                var query2 = (from c in db.Classes
                              where c.Year == year && c.Season == season
                              join cou in db.Courses on c.CourseId equals cou.CourseId
                              where cou.Number == num && cou.Subject == subject
                              select new
                {
                    assiClassID = c.ClassId
                }).FirstOrDefault();

                var assignmentCatIDs = (from ac in db.AssignmentCategories
                                        select ac.Acid);
                List <int> list = new List <int>();
                foreach (int ac in assignmentCatIDs)
                {
                    list.Add(ac);
                }

                if (list.Count() > 0)
                {
                    newAssignmentCatID = list.Max() + 1;
                }

                AssignmentCategories assiCat = new AssignmentCategories();
                assiCat.Acid          = (uint)newAssignmentCatID;
                assiCat.Name          = category;
                assiCat.GradingWeight = (uint)catweight;
                assiCat.ClassId       = query2.assiClassID;

                db.AssignmentCategories.Add(assiCat);
                db.SaveChanges();

                return(Json(new { success = true }));
            }
        }
Esempio n. 6
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.</returns>
        public IActionResult CreateCourse(string subject, int number, string name)
        {
            int newCourseID = 1;

            using (Team36LMSContext db = new Team36LMSContext())
            {
                var query = (from c in db.Courses
                             where c.Subject == subject &&
                             c.Number == number
                             select c).FirstOrDefault();

                if (query != null)
                {
                    return(Json(new { success = false }));
                }


                var courses = (from c in db.Courses
                               select c.CourseId);
                List <int> list = new List <int>();
                foreach (int courseID in courses)
                {
                    list.Add(courseID);
                }

                if (list.Count() > 0)
                {
                    newCourseID = list.Max() + 1;
                }

                Courses newCourse = new Courses();
                newCourse.Subject  = subject;
                newCourse.Number   = (uint)number;
                newCourse.Name     = name;
                newCourse.CourseId = (uint)newCourseID;
                db.Courses.Add(newCourse);
                db.SaveChanges();

                return(Json(new { success = true }));
            }
        }
Esempio n. 7
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 (Team36LMSContext db = new Team36LMSContext())
            {
                var query =
                    from c in db.Courses
                    join cl in db.Classes on c.CourseId equals cl.CourseId
                    where c.Subject == subject && c.Number == num && cl.Season == season && cl.Year == year

                    select cl.ClassId;

                if (query.Count() == 0)
                {
                    return(Json(new { success = false }));
                }
                uint classID = (uint)query.FirstOrDefault();
                System.Diagnostics.Debug.WriteLine("hwewew: " + classID);

                var currClass = (from e in db.Enrollment
                                 where e.UId == uid
                                 select e.ClassId);
                foreach (uint cid in currClass)
                {
                    if (cid == classID)
                    {
                        return(Json(new { success = false }));
                    }
                }

                Enrollment newE = new Enrollment();
                newE.UId     = uid;
                newE.ClassId = classID;
                newE.Grade   = "--";

                db.Enrollment.Add(newE);
                db.SaveChanges();

                return(Json(new { success = true }));
            }
        }
Esempio n. 8
0
        /*******Begin code to modify********/

        /// <summary>
        /// Create a new user of the LMS with the specified information.
        /// Assigns the user a unique uID consisting of a 'u' followed by 7 digits.
        /// </summary>
        /// <param name="fName">First Name</param>
        /// <param name="lName">Last Name</param>
        /// <param name="DOB">Date of Birth</param>
        /// <param name="SubjectAbbrev">The department the user belongs to (professors and students only)</param>
        /// <param name="SubjectAbbrev">The user's role: one of "Administrator", "Professor", "Student"</param> 
        /// <returns>A unique uID that is not be used by anyone else</returns>
        public string CreateNewUser(string fName, string lName, DateTime DOB, string SubjectAbbrev, string role)
        {
            using (Team36LMSContext db = new Team36LMSContext())
            {
                var studentIDS = (from s in db.Students
                                  select s.UId);
                var professorIDS = (from s in db.Professors
                                    select s.UId);
                var adminIDS = (from s in db.Administrators
                                select s.UId);
                List<int> list = new List<int>();

                foreach (string sID in studentIDS)
                {
                    Int32.TryParse(sID.Substring(1), out int result);
                    list.Add(result);
                }
                foreach (string pID in professorIDS)
                {
                    Int32.TryParse(pID.Substring(1), out int result);
                    list.Add(result);
                }
                foreach (string aID in adminIDS)
                {
                    Int32.TryParse(aID.Substring(1), out int result);
                    list.Add(result);
                }

                string newID = "u0000001";
                if (list.Count() > 0)
                {
                    newID = generateUniqueID(list);
                }


                if (role == "Student")
                {
                    Students newStudent = new Students();
                    newStudent.UId = newID;
                    newStudent.FirstName = fName;
                    newStudent.LastName = lName;
                    newStudent.Dob = DOB;
                    newStudent.Major = SubjectAbbrev;

                    db.Students.Add(newStudent);
                    db.SaveChanges();
                }

                if (role == "Professor")
                {
                    Professors newProfessor = new Professors();
                    newProfessor.UId = newID;
                    newProfessor.FirstName = fName;
                    newProfessor.LastName = lName;
                    newProfessor.Dob = DOB;
                    newProfessor.Subject = SubjectAbbrev;

                    db.Professors.Add(newProfessor);
                    db.SaveChanges();
                }

                if (role == "Administrator")
                {
                    Administrators newAdm = new Administrators();
                    newAdm.UId = newID;
                    newAdm.FirstName = fName;
                    newAdm.LastName = lName;
                    newAdm.Dob = DOB;


                    db.Administrators.Add(newAdm);
                    db.SaveChanges();
                }


                return newID;

            }
        }
Esempio n. 9
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.</returns>
        public IActionResult CreateClass(string subject, int number, string season, int year, DateTime start, DateTime end, string location, string instructor)
        {
            int newClassID = 1;

            using (Team36LMSContext db = new Team36LMSContext())
            {
                var query1 = (from c in db.Classes
                              join q in db.Courses on c.CourseId equals q.CourseId
                              where c.Season == season &&
                              c.Year == year &&
                              q.Subject == subject
                              select c).FirstOrDefault();

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

                var query2 = (from c in db.Classes
                              where c.Season == season &&
                              c.Year == year &&
                              c.Location == location &&
                              ((c.Start > start.TimeOfDay && c.Start < end.TimeOfDay) || (c.End > start.TimeOfDay && c.End < end.TimeOfDay) || (c.Start > start.TimeOfDay && c.End < end.TimeOfDay))
                              select c).FirstOrDefault();

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

                var classes = (from c in db.Classes
                               select c.ClassId);
                List <int> list = new List <int>();
                foreach (int classID in classes)
                {
                    list.Add(classID);
                }

                if (list.Count() > 0)
                {
                    newClassID = list.Max() + 1;
                }

                var courseID = (from c in db.Courses
                                where c.Subject == subject && c.Number == number
                                select c.CourseId).FirstOrDefault();


                Classes newClass = new Classes();
                newClass.Year     = (uint)year;
                newClass.Season   = season;
                newClass.Location = location;
                newClass.Start    = start.TimeOfDay;
                newClass.End      = end.TimeOfDay;
                newClass.CourseId = courseID;
                newClass.UId      = instructor;
                newClass.ClassId  = (uint)newClassID;
                db.Classes.Add(newClass);
                db.SaveChanges();


                return(Json(new { success = true }));
            }
        }