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

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

            var acID = new String(stringChars);

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

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

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

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


                // update all students' grades for this class

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

                foreach (var x in findAllStudents)
                {
                    updateStudentGradeForClass(query.ToArray()[0], x);
                }
                return(Json(new { success = true }));
            }
        }
        /// <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)
        {
            // Get the class ID to be associated with this assignment category
            var classIDquery =
                from co in db.Courses // Courses to Classes
                join cl in db.Classes on co.CatalogId equals cl.Offering into join1

                // Get Class ID
                from j1 in join1
                where co.Department == subject &&
                co.Number == num &&
                j1.Season == season &&
                j1.Year == year
                select j1.ClassId;

            // Grab all the assignmentCategory IDs
            var categoryIDs =
                from cat in db.AssignmentCategories // Courses to Classes
                select cat.CategoryId;


            // Turn the user ID's into an ordered list of just numbers
            int[] categoryIDnums = categoryIDs.ToArray();
            Array.Sort(categoryIDnums);

            int newCategoryNumber = 0;

            // If there are no gaps in the uID numbers, use next sequential number
            if (categoryIDnums[categoryIDs.Count() - 1] == categoryIDnums.Count() - 1)
            {
                newCategoryNumber = categoryIDnums.Count();
            }
            // Otherwise find a gap in the numbers for which to create a new ID
            else
            {
                for (int i = 0; i < categoryIDnums.Count(); i++)
                {
                    if (i < categoryIDnums[i]) // Then we found a skipped ID number
                    {
                        newCategoryNumber = i;
                        break;
                    }
                }
            }


            // Set up the Category
            Models.LMSModels.AssignmentCategories assignCategory = new Models.LMSModels.AssignmentCategories();
            assignCategory.CategoryId = newCategoryNumber;
            assignCategory.Name       = category;
            assignCategory.Weight     = catweight;
            assignCategory.Class      = classIDquery.ToArray().First();

            // Insert the Category into the database
            db.AssignmentCategories.Add(assignCategory);
            try
            {
                db.SaveChanges();
                return(Json(new { success = true }));
            }
            catch // If inserting changes to database fails
            {
                return(Json(new { success = false }));
            }
        }