Example #1
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)
        {
            using (Team94LMSContext db = new Team94LMSContext())
            {
                try
                {
                    var classID =
                        from t1 in db.Courses
                        where t1.Department == subject && t1.Number == num
                        join t2 in db.Classes
                        on t1.CourseId equals t2.Course
                        where t2.Semester == season && t2.Year == (uint)year
                        select t2.ClassId;

                    AssignmentCatagories newCat = new AssignmentCatagories();
                    newCat.Class  = classID.Single();
                    newCat.Name   = category;
                    newCat.Weight = (uint)catweight;

                    db.AssignmentCatagories.Add(newCat);
                    db.SaveChanges();
                    return(Json(new { success = true }));
                }
                catch (DbUpdateException e)
                {
                    Debug.WriteLine(e.Message);
                    Debug.WriteLine(e.InnerException.Message);
                    return(Json(new { success = false }));
                }
            }
        }
Example #2
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 uID = getNewUID();

            using (Team94LMSContext db = new Team94LMSContext())
            {
                if (role == "Administrator")
                {
                    Admins newUser = new Admins();
                    newUser.UId       = uID;
                    newUser.FirstName = fName;
                    newUser.LastName  = lName;
                    newUser.Dob       = DOB;
                    db.Admins.Add(newUser);
                    db.SaveChanges();
                }
                else if (role == "Professor")
                {
                    Professors newUser = new Professors();
                    newUser.UId        = uID;
                    newUser.FirstName  = fName;
                    newUser.LastName   = lName;
                    newUser.Dob        = DOB;
                    newUser.Department = SubjectAbbrev;
                    db.Professors.Add(newUser);
                    db.SaveChanges();
                }
                else
                {
                    Students newUser = new Students();
                    newUser.UId       = uID;
                    newUser.FirstName = fName;
                    newUser.LastName  = lName;
                    newUser.Dob       = DOB;
                    newUser.Major     = SubjectAbbrev;
                    db.Students.Add(newUser);
                    db.SaveChanges();
                }
            }

            return(uID);
        }
        /// <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)
        {
            using (Team94LMSContext db = new Team94LMSContext())
            {
                var timeConflict =
                    from b in db.Classes
                    where ((start > b.Start && start < b.End) || (end > b.Start && end < b.End)) &&
                    location == b.Loc && season == b.Semester && (uint)year == b.Year
                    select b;

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

                var course =
                    from b in db.Courses
                    where (b.Department == subject && b.Number == number)
                    select b.CourseId;

                var courseConflict =
                    from x in db.Classes
                    where course.Contains(x.Course) && season == x.Semester && year == x.Year
                    select x;

                if (courseConflict.Count() != 0)
                {
                    return(Json(new { success = false }));
                }
                try
                {
                    Classes c = new Classes();
                    c.Course   = course.Single();
                    c.Semester = season;
                    c.Year     = (uint)year;
                    c.Start    = start;
                    c.End      = end;
                    c.Loc      = location;
                    c.Prof     = instructor;
                    db.Classes.Add(c);
                    db.SaveChanges();
                } catch (DbUpdateException)
                {
                    return(Json(new { success = false }));
                }

                return(Json(new { success = true }));
            }
        }
 /// <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)
 {
     using (Team94LMSContext db = new Team94LMSContext())
     {
         try
         {
             Courses c = new Courses();
             c.Department = subject;
             c.Number     = (uint)number;
             c.Name       = name;
             db.Courses.Add(c);
             db.SaveChanges();
         } catch (DbUpdateException)
         {
             return(Json(new { success = false }));
         }
         return(Json(new { success = true }));
     }
 }
Example #5
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 (Team94LMSContext db = new Team94LMSContext())
            {
                try
                {
                    var assignSub =
                        from t1 in db.Courses
                        where t1.Department == subject && t1.Number == num
                        join t2 in db.Classes
                        on t1.CourseId equals t2.Course
                        where t2.Semester == season && t2.Year == (uint)year
                        join t3 in db.AssignmentCatagories
                        on t2.ClassId equals t3.Class
                        join t4 in db.Assignments
                        on t3.CataId equals t4.Catagory
                        where t3.Name == category && t4.Name == asgname
                        join t5 in db.Submissions
                        on t4.AssignId equals t5.Assignment
                        where t5.Student == uid
                        select t5.Assignment;

                    var submission =
                        from sub in db.Submissions
                        where sub.Student == uid && sub.Assignment == assignSub.Single()
                        select sub;

                    foreach (Submissions sub in submission)
                    {
                        sub.Score = (uint)score;
                    }

                    db.SaveChanges();
                    return(Json(new { success = true }));
                }
                catch (DbUpdateException e)
                {
                    Debug.WriteLine(e.Message);
                    Debug.WriteLine(e.InnerException.Message);
                    return(Json(new { success = false }));
                }
            }
        }
Example #6
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)
        {
            using (Team94LMSContext db = new Team94LMSContext())
            {
                try
                {
                    var catIDs =
                        from t1 in db.Courses
                        where t1.Department == subject && t1.Number == num
                        join t2 in db.Classes
                        on t1.CourseId equals t2.Course
                        where t2.Semester == season && t2.Year == (uint)year
                        join t3 in db.AssignmentCatagories
                        on t2.ClassId equals t3.Class
                        join t4 in db.Assignments
                        on t3.CataId equals t4.Catagory
                        where t3.Name == category
                        select t4.Catagory;


                    Assignments newAsign = new Assignments();
                    newAsign.Points   = (uint)asgpoints;
                    newAsign.Due      = asgdue;
                    newAsign.Content  = asgcontents;
                    newAsign.Catagory = catIDs.Single();
                    newAsign.Name     = asgname;

                    db.Assignments.Add(newAsign);
                    db.SaveChanges();
                    return(Json(new { success = true }));
                }
                catch (DbUpdateException e)
                {
                    Debug.WriteLine(e.Message);
                    Debug.WriteLine(e.InnerException.Message);
                    return(Json(new { success = false }));
                }
            }
        }