/// <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) { try { uint classId = (from d in db.Departments join co in db.Courses on d.Subject equals co.Subject join c in db.Classes on co.CourseId equals c.CourseId where d.Subject == subject && co.Num == num.ToString() && c.Season == season && c.Year == year select c.ClassId).First(); AssignmentCat newCat = new AssignmentCat() { Name = category, ClassId = classId, Weight = (uint)catweight }; db.AssignmentCat.Add(newCat); db.SaveChanges(); } catch { return(Json(new { success = false })); } return(Json(new { success = true })); }
/// <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) { try { int classId = 0; var query = from clas in db.Class join course in db.Course on clas.CourseId equals course.CourseId where course.AbrvNavigation.Abrv == subject where clas.SemesterSeason == season where clas.SemesterYear == year select new { id = clas.ClassId }; foreach (var q in query) { classId = (int)q.id; } AssignmentCat c = new AssignmentCat(); c.CatName = category; c.GradeWeight = (uint)catweight; c.ClassId = classId; db.AssignmentCat.Add(c); db.SaveChanges(); return(Json(new { success = true })); } catch (Exception) { return(Json(new { success = false })); } }