/// <summary> /// Helper for configuring a database with no assignment categories /// </summary> /// <returns></returns> private Team55LMSContext MakeDatabaseWithOneAssignmentCategory() { var optionsBuilder = new DbContextOptionsBuilder <Team55LMSContext>(); optionsBuilder.UseInMemoryDatabase("one_assignment_category").UseApplicationServiceProvider(NewServiceProvider()); Team55LMSContext db = new Team55LMSContext(optionsBuilder.Options); Courses course = new Courses { CourseId = 5, CourseNumber = 3200, Name = "Scientific Computing", SubjectAbbr = "CS" }; Classes scientificComputing = new Classes { CourseId = 2, Location = "WEB L103", Semester = "Spring 2021", Professor = "u0000009", Start = TimeSpan.Parse("8:05:00"), End = TimeSpan.Parse("09:10:00"), }; Enrolled enr = new Enrolled { ClassId = scientificComputing.ClassId, Grade = "--", UId = "u0000001", }; AssignmentCategories category = new AssignmentCategories { ClassId = scientificComputing.ClassId, Name = "Assignments", Weight = 60, }; db.Courses.Add(course); db.Classes.Add(scientificComputing); db.Enrolled.Add(enr); db.AssignmentCategories.Add(category); db.SaveChanges(); return(db); }
public void PopulateStudentAverages() { List <int?> averages = new List <int?>(); //Iterate through all enrolled students, keep index for grades math for (int studentsIndex = 0; studentsIndex < EnrolledStudents.Count; studentsIndex++) { double studentAverage = 0; int weightTotal = 0; int gradesWithWeightTotal = 0; for (int assignmentsIndex = 0; assignmentsIndex < ClassAssignments.Count; assignmentsIndex++) { Grade gradeToAccess = StudentGrades[assignmentsIndex + (studentsIndex * ClassAssignments.Count)]; if (gradeToAccess.GradeValue == "") { continue; } int gradeWeight = AssignmentCategories.Find(c => c.CategoryId == ClassAssignments[assignmentsIndex].CategoryId).CategoryWeight; weightTotal += gradeWeight; if (gradeToAccess.GradeValue != "M" && gradeToAccess.GradeValue != "m") { gradesWithWeightTotal += Int32.Parse(gradeToAccess.GradeValue) * gradeWeight; } } studentAverage += (double)gradesWithWeightTotal / weightTotal; studentAverage = Math.Round(studentAverage, MidpointRounding.AwayFromZero); int studentAverageInt = (int)studentAverage; if (studentAverageInt < 0) { averages.Add(null); } else { averages.Add(studentAverageInt); } } StudentAverages = averages; }
/// <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) { string semester = season + ' ' + year; var query = from crs in db.Courses where crs.Department == subject && crs.Number == num join cls in db.Classes on crs.CatalogId equals cls.CatalogId select new { classID = cls.ClassId }; if (query.Any()) { uint clsID = query.First().classID; var catagoryQuery = from cl in db.Classes where cl.ClassId == clsID join asmts in db.AssignmentCategories on cl.ClassId equals asmts.ClassId into joined from jnd in joined where jnd.Name == category select jnd; if (!catagoryQuery.Any()) { AssignmentCategories assignmentCatgories = new AssignmentCategories { Name = category, Weight = (byte)catweight, ClassId = clsID }; db.AssignmentCategories.Add(assignmentCatgories); try { db.SaveChanges(); return(Json(new { success = true })); } catch (Exception e) { Console.WriteLine(e.Message); } } } return(Json(new { success = false })); }
/// <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 query = from cou in db.Courses where cou.Department == subject && cou.Num == num.ToString() join cl in db.Classes on cou.CatalogId equals cl.CatalogId where cl.Semester == season + year.ToString() join ac in db.AssignmentCategories on cl.ClassId equals ac.ClassId where ac.Name == category select ac; if (query.ToList().Count > 0) { return(Json(new { success = false })); } AssignmentCategories acn = new AssignmentCategories(); /* * var query2 = * from cou in db.Courses * where cou.Department == subject && cou.Num == num.ToString() * join cl in db.Classes on cou.CatalogId equals cl.CatalogId * into couJoinCl * from coucl in couJoinCl * where coucl.Semester == season + ' ' + year.ToString() * select coucl.ClassId; */ var query2 = from cou in db.Courses where cou.Department == subject && cou.Num == num.ToString() join cl in db.Classes on cou.CatalogId equals cl.CatalogId where cl.Semester == season + year.ToString() select cl.ClassId; System.Diagnostics.Debug.WriteLine(subject); System.Diagnostics.Debug.WriteLine(num); acn.Weight = Convert.ToUInt32(catweight); acn.Name = category; acn.ClassId = query2.First(); db.AssignmentCategories.Add(acn); db.SaveChanges(); 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) { using (db) { // return assignments in all categories var query = from co in db.Courses where co.DeptAbbreviation == subject && co.Number == num join cl in db.Classes on co.CourseId equals cl.CourseId where cl.Season == season && cl.Year == year select cl; var query2 = from q in query join a in db.AssignmentCategories on q.ClassId equals a.ClassId where a.Name == category select a; if (query2.Any()) { return(Json(new { success = false })); } else { //New assignment category AssignmentCategories ac = new AssignmentCategories(); try { ac.ClassId = query.First().ClassId; ac.GradingWeight = (uint)catweight; ac.Name = category; db.AssignmentCategories.Add(ac); db.SaveChanges(); return(Json(new { success = true })); } catch (Exception) { return(Json(new { success = false })); } } return(Json(new { success = false })); } }
/// <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) { //Check if the Assignment Category exists var query = from courses in db.Courses join classes in db.Classes on courses.CId equals classes.CId join assignmentCat in db.AssignmentCategories on classes.ClassId equals assignmentCat.ClassId where courses.Listing == subject && courses.Number == num && classes.Semester.Contains(season + year) && assignmentCat.Name == category select new { temp = assignmentCat.ClassId }; if (query.Count() == 0) { var anotherQuery = from courses in db.Courses join classes in db.Classes on courses.CId equals classes.CId where courses.Listing == subject && courses.Number == num && classes.Semester.Contains(season + year) select new { classes.ClassId }; uint classID = anotherQuery.First().ClassId; AssignmentCategories newAssignCat = new AssignmentCategories { Name = category, ClassId = classID, GradeWeight = (uint)catweight }; db.AssignmentCategories.Add(newAssignCat); db.SaveChanges(); return(Json(new { success = true })); } else { return(Json(new { success = false })); } }
/// <summary> /// Helper for verifying if a newly created assignment category /// already exists for the class /// </summary> /// <param name="category"></param> /// <returns></returns> private bool AssignmentCategoryExists(AssignmentCategories category, uint classID) { var allCategories = from cla in db.Classes join cat in db.AssignmentCategories on cla.ClassId equals cat.ClassId into categories from ca in categories.DefaultIfEmpty() where ca.Name == category.Name where cla.ClassId == classID select ca; foreach (AssignmentCategories c in allCategories) { if (c.Name.ToLower() == category.Name.ToLower()) { return(true); } } return(false); }
/// <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) //works { if (catweight.GetType() != typeof(int) || catweight < 0) { return(Json(new { success = false })); } using (Team9LMSContext db = new Team9LMSContext()) { var classIDQuery = from cid in (from c in db.Courses where c.Subject == subject && c.Num == num select new { CatalogId = c.CatalogId }) join cl in db.Classes on cid.CatalogId equals cl.CatalogId where cl.Semester == year.ToString() + season select new { classID = cl.ClassId }; if (classIDQuery.Count() == 0) { return(Json(new { success = false })); } foreach (var cq in classIDQuery) { var ClassID = Convert.ToInt32(cq.classID); AssignmentCategories newAC = new AssignmentCategories(); newAC.ClassId = (uint)ClassID; newAC.Name = category; newAC.Weight = (uint)catweight; db.AssignmentCategories.Add(newAC); } try { db.SaveChanges(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("CreateAssignmentCategoryCreateAssignmentCategory"); } } 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) { if (category == null || category.Length <= 0 || catweight <= 0) { return(Json(new { success = false })); } var Category = from ac in db.AssignmentCategories where ac.Class.Course.Department.Subject == subject && ac.Class.Course.Number == num && ac.Class.Semester == season && ac.Class.Year == year && ac.Name == category select ac; // false if an assignment category with the same name already exists in the same class. if (Category.Count() > 0) { return(Json(new { success = false })); } else { var Class = from _class in db.Classes where _class.Course.Department.Subject == subject && _class.Course.Number == num && _class.Semester == season && _class.Year == year select _class; AssignmentCategories ac = new AssignmentCategories { Weight = (ushort)catweight, Name = category, ClassId = Class.First().ClassId }; db.AssignmentCategories.Add(ac); db.SaveChanges(); return(Json(new { success = true })); } }
public void GetAssignmentContentsTrivialSuccess() { var db = Utils.MakeMockDatabase(); var controller = MakeController(db); uint cid = ProfessorControllerTests.AddCourseAndClass(db); AssignmentCategories assCat = new AssignmentCategories { AcId = 1002, Name = "Quizzes", GradingWeight = 50, CId = cid }; db.AssignmentCategories.Add(assCat); string assignmentContents = "Just leave your head wide open " + "My love comes in doses" + "So if you're nervous you shouldn't be " + "I'll take away your panic"; Assignments newAssignment = new Assignments { AId = 999, AcId = 1002, Name = "Bonus Quiz", MaxPointValue = 102, DueDate = DateTime.Now, Content = assignmentContents, }; db.Assignments.Add(newAssignment); db.SaveChanges(); var contentResult = controller.GetAssignmentContents("CS", 3550, "Spring", 2019, "Quizzes", "Bonus Quiz") as ContentResult; Assert.Equal(assignmentContents, contentResult.Content); }
/// <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) { Boolean categoryCreated = false; using (Team31LMSContext db = new Team31LMSContext()) { AssignmentCategories newCategories = new AssignmentCategories { Name = category, Weight = (ushort)catweight, Class = (from co in db.Courses join c in db.Classes on co.Id equals c.OfferingOf where co.Subject == subject && co.Crn == num && c.SemesterSeason == season && c.SemesterYear == year select c.Id).First() }; db.AssignmentCategories.Add(newCategories); int result = db.SaveChanges(); categoryCreated = (result == 1); } return(Json(new { success = categoryCreated })); }
/// <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) { bool result; try { var query = from cl in db.Classes join co in db.Courses on cl.CourseId equals co.CourseId where cl.Season == season && cl.Year == year && co.Number == num && co.Subject == subject select new { cl.ClassId }; // Create a new assignment category object. AssignmentCategories assignmentCategory = new AssignmentCategories { Name = category, Weight = (uint)catweight, ClassId = query.FirstOrDefault().ClassId }; db.AssignmentCategories.Add(assignmentCategory); db.SaveChanges(); result = true; } catch (Microsoft.EntityFrameworkCore.DbUpdateException e) { result = false; } return(Json(new { success = result })); }
/// <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 query = from course in db.Courses join classOffering in db.Classes on course.CatalogId equals classOffering.CatalogId where course.Listing == subject && course.Number == num.ToString() && classOffering.SemesterSeason == season && classOffering.SemesterYear == year select classOffering; var firstClass = query.FirstOrDefault(); if (firstClass == null) { return(Json(new { success = false })); } // check if this class already has a category with that name foreach (var assCat in firstClass.AssignmentCategories) { if (assCat.Name == category) { return(Json(new { success = false })); } } AssignmentCategories newAC = new AssignmentCategories() { Name = category, GradingWeight = (uint)catweight, CId = firstClass.CId }; db.AssignmentCategories.Add(newAC); int rowsAffected = db.SaveChanges(); return(Json(new { success = rowsAffected > 0 })); }
public static void AddAssignmentAndCategory(uint cid, Team41LMSContext db) { AssignmentCategories assCat = new AssignmentCategories { AcId = 1002, Name = "Quizzes", GradingWeight = 50, CId = cid }; db.AssignmentCategories.Add(assCat); Assignments newAssignment = new Assignments { AId = 999, AcId = 1002, Name = "Bonus Quiz", MaxPointValue = 102, DueDate = DateTime.Now, Content = "oanklaks fl lja", }; db.Assignments.Add(newAssignment); db.SaveChanges(); }
/// <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 query = from cr in db.Courses join c in db.Classes on new { A = cr.CatalogId, B = cr.Listing, C = (int)cr.Number, D = season, E = year } equals new { A = c.CategoryId, B = subject, C = num, D = (string)splitSem(c.Semester, 0), E = (int)splitSem(c.Semester, 1) } into joined from j in joined select j; if (query.SingleOrDefault() == null) { return(Json(new { success = false })); } AssignmentCategories a = new AssignmentCategories(); a.ClassId = (from q in query select q.ClassId).FirstOrDefault(); a.Name = category; a.Weight = (byte)catweight; db.AssignmentCategories.Add(a); db.SaveChanges(); return(Json(new { success = true })); }
public void GetAssignmentsInCategoryMultipleSubmissions() { var db = Utils.MakeMockDatabase(); var controller = MakeController(db); uint cid = AddCourseAndClass(db); int numSubmissions = 10; for (int i = 0; i < numSubmissions; i++) { string uid = "" + i; Students newStudent = new Students { UId = uid, Major = "CS", FirstName = "Brian" + i, LastName = "Landes" + i, Dob = DateTime.Now, }; db.Students.Add(newStudent); Enroll(uid, cid, db); } AssignmentCategories assCat = new AssignmentCategories { AcId = 1002, Name = "Quizzes", GradingWeight = 50, CId = cid }; db.AssignmentCategories.Add(assCat); Assignments newAssignment = new Assignments { AId = 1999, AcId = 1002, Name = "Bonus Quiz", MaxPointValue = 102, DueDate = DateTime.Now, Content = "oanklaks fl lja", }; db.Assignments.Add(newAssignment); for (int i = 0; i < numSubmissions; i++) { Submissions newSubmission = new Submissions { UId = "" + i, AId = 1999, Content = "This is some serious content", Time = DateTime.Now, Score = 78, }; db.Submissions.Add(newSubmission); } db.SaveChanges(); var jsonResult = controller.GetAssignmentsInCategory("CS", 3550, "Spring", 2019, "Quizzes") as JsonResult; Utils.AssertJsonResultIsArrayOfLength(jsonResult, 1); var oneAssignment = Utils.JsonResultValueAtIndex(jsonResult, 0); Assert.True(Utils.HasField(oneAssignment, "aname")); Assert.True(Utils.HasField(oneAssignment, "cname")); Assert.True(Utils.HasField(oneAssignment, "due")); Assert.True(Utils.HasField(oneAssignment, "submissions")); Assert.Equal(numSubmissions, Utils.GetValue <int>(oneAssignment, "submissions")); }
/// <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) { using (db) { int acid = 1; int cID = 0; AssignmentCategories asc = new AssignmentCategories(); var query = (from p in db.AssignmentCategories orderby p.AcId descending select p.AcId).Take(1); if (query.ToArray().Count() != 0) { acid = query.ToArray()[0] + 1; } var query2 = from c in db.Courses where c.Subject == subject && c.Number == num.ToString() join c2 in db.Classes on c.CatalogId equals c2.CatalogId where c2.Semester == (season + year.ToString()) select c2.CId; if (query2.ToArray().Count() != 0) { cID = query2.ToArray()[0]; } asc.AcId = acid; asc.CId = cID; var query3 = from p in db.AssignmentCategories where p.CId == cID select p.Name; foreach (String n in query3.ToArray()) { if (n == category) { System.Diagnostics.Debug.WriteLine("----------"); System.Diagnostics.Debug.WriteLine(n); System.Diagnostics.Debug.WriteLine("----------"); return(Json(new { success = false })); } } asc.Name = category; asc.Weight = Convert.ToSByte(catweight); try { db.Add(asc); db.SaveChanges(); return(Json(new { success = true })); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("----------"); System.Diagnostics.Debug.WriteLine(e.Message); System.Diagnostics.Debug.WriteLine("----------"); return(Json(new { success = false })); } } }
public void GradeSubmissionUpdateGradeTwoAssignmentsA() { var db = Utils.MakeMockDatabase(); var controller = MakeController(db); string uid = StudentControllerTests.AddOneStudent(db); uint cid = AddCourseAndClass(db); Enroll(uid, cid, db); AssignmentCategories assCat = new AssignmentCategories { AcId = 1002, Name = "Quizzes", GradingWeight = 100, CId = cid }; db.AssignmentCategories.Add(assCat); { Assignments newAssignment = new Assignments { AId = 999, AcId = 1002, Name = "Bonus Quiz", MaxPointValue = 100, DueDate = DateTime.Now, Content = "oanklaks fl lja", }; db.Assignments.Add(newAssignment); Submissions newSubmission = new Submissions { UId = uid, AId = 999, Content = "This is some serious content", Time = DateTime.Now, Score = 78, }; db.Submissions.Add(newSubmission); } db.SaveChanges(); AssertGradeEquals(uid, "--", db); var jsonResult = controller.GradeSubmission("CS", 3550, "Spring", 2019, "Quizzes", "Bonus Quiz", uid, 100) as JsonResult; Assert.True(Utils.ResultSuccessValue(jsonResult)); AssertGradeEquals(uid, "A", db); { Assignments newAssignment = new Assignments { AId = 9991, AcId = 1002, Name = "Bonus Quiz 2", MaxPointValue = 100, DueDate = DateTime.Now, Content = "oanklaks fl lja", }; db.Assignments.Add(newAssignment); Submissions newSubmission = new Submissions { UId = uid, AId = 9991, Content = "This is some serious content", Time = DateTime.Now, Score = 78, }; db.Submissions.Add(newSubmission); } db.SaveChanges(); jsonResult = controller.GradeSubmission("CS", 3550, "Spring", 2019, "Quizzes", "Bonus Quiz 2", uid, 70) as JsonResult; Assert.True(Utils.ResultSuccessValue(jsonResult)); AssertGradeEquals(uid, "B", db); }
public void GetAssignmentsNoCategory2() { var db = Utils.MakeMockDatabase(); var controller = MakeController(db); string uid = StudentControllerTests.AddOneStudent(db); uint cid = AddCourseAndClass(db); Enroll(uid, cid, db); int numAssCats = 10; for (int i = 0; i < numAssCats; i++) { AssignmentCategories assCat = new AssignmentCategories { AcId = 1002 + (uint)i, Name = "Quizzes" + i, GradingWeight = 50, CId = cid }; db.AssignmentCategories.Add(assCat); Assignments newAssignment = new Assignments { AId = 999 + (uint)i, AcId = 1002 + (uint)i, Name = "Bonus Quiz", MaxPointValue = 102, DueDate = DateTime.Now, Content = "oanklaks fl lja", }; db.Assignments.Add(newAssignment); Submissions newSubmission = new Submissions { UId = uid, AId = 999 + (uint)i, Content = "This is some serious content", Time = DateTime.Now, Score = 78, }; db.Submissions.Add(newSubmission); } db.SaveChanges(); var jsonResult = controller.GetAssignmentsInCategory("CS", 3550, "Spring", 2019, null) as JsonResult; Utils.AssertJsonResultIsArrayOfLength(jsonResult, numAssCats); for (int i = 0; i < numAssCats; i++) { var oneAssignment = Utils.JsonResultValueAtIndex(jsonResult, i); Assert.True(Utils.HasField(oneAssignment, "aname")); Assert.True(Utils.HasField(oneAssignment, "cname")); Assert.True(Utils.HasField(oneAssignment, "due")); Assert.True(Utils.HasField(oneAssignment, "submissions")); var numSubmissions = Utils.GetValue <int>(oneAssignment, "submissions"); Assert.Equal(1, numSubmissions); } }
/// <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) { // TODO: Implement string semester = season + year.ToString(); //check if category already exists var check = from oc in db.AssignmentCategories where oc.Name == category && oc.ClassNavigation.Semester == semester && oc.ClassNavigation.Course.Number == num && oc.ClassNavigation.Course.Abbr == subject select oc.CatId; if (check.ToArray().Count() > 0) { return(Json(new { success = false })); } var catID = from ac in db.AssignmentCategories orderby ac.CatId descending select ac.CatId; var classID = from c in db.Classes where c.Semester == semester && c.Course.Number == num && c.Course.Abbr == subject select c.ClassId; var catID_enum = catID.GetEnumerator(); catID_enum.MoveNext(); AssignmentCategories new_cat = new AssignmentCategories(); new_cat.CatId = catID_enum.Current + 1; new_cat.Name = category; new_cat.Weight = (UInt32)catweight; new_cat.Class = classID.SingleOrDefault(); db.AssignmentCategories.Add(new_cat); /* * try * { * db.SaveChanges(); * } * catch * { * return Json(new { success = false }); * } * var class_roster = * (from e in db.Enrolled * where e.ClassNavigation.Course.Number == num * && e.ClassNavigation.Course.Abbr == subject * && e.ClassNavigation.Semester == semester * select e); * * foreach (var item in class_roster) * { * item.Grade = ReCalculateClassGradeForStudent(subject, num, season, year, category, item.UId); * } */ try { db.SaveChanges(); return(Json(new { success = true })); } catch { return(Json(new { success = false })); } }
public void SubmitAssignmentTextResubmission() { var db = Utils.MakeMockDatabase(); var controller = MakeController(db); string uid = AddOneStudent(db); Courses newCourse = new Courses { CatalogId = "12345", Listing = "CS", Name = "Algorithms", Number = "3550" }; db.Courses.Add(newCourse); Classes newClass = new Classes { CId = 101, CatalogId = "12345", SemesterYear = 2019, SemesterSeason = "Spring", Location = "On the moon", StartTime = new TimeSpan(), EndTime = new TimeSpan() }; db.Classes.Add(newClass); Enrolled newEnrolled = new Enrolled { UId = uid, CId = 101, Grade = "--" }; db.Enrolled.Add(newEnrolled); AssignmentCategories assCat = new AssignmentCategories { AcId = 1002, Name = "Quizzes", GradingWeight = 50, CId = 101 }; db.AssignmentCategories.Add(assCat); Assignments newAssignment = new Assignments { AId = 999, AcId = 1002, Name = "Bonus Quiz", MaxPointValue = 102, DueDate = DateTime.Now, Content = "oanklaks fl lja", }; db.Assignments.Add(newAssignment); Submissions newSubmission = new Submissions { UId = uid, AId = 999, Content = "This is some serious content", Time = DateTime.Now, Score = 78, }; db.Submissions.Add(newSubmission); db.SaveChanges(); var jsonResults = controller.SubmitAssignmentText("CS", 3550, "Spring", 2019, "Quizzes", "Bonus Quiz", uid, "Vikings would make boats from the bones of their enemies.") as JsonResult; Assert.True(Utils.ResultSuccessValue(jsonResults)); var submissions = new List <Submissions>(db.Submissions); var submission = submissions[0]; Assert.Equal((uint)78, submission.Score); Assert.Equal(uid, submission.UId); Assert.Equal("Vikings would make boats from the bones of their enemies.", submission.Content); }
/// <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 (Team6LMSContext db = new Team6LMSContext()) { try { var query0 = from b in db.Courses where b.Subject.Equals(subject) && b.Num.Equals(num) join i in db.Classes on b.CId equals i.CId into inv from j1 in inv.DefaultIfEmpty() where j1.Year == year && j1.Season.Equals(season) join i2 in db.AssignmentCategories on j1.ClsId equals i2.ClsId into inv2 from j2 in inv2.DefaultIfEmpty() where j2.Name.Equals(category) select j2; var query2 = from b in db.Courses where b.Subject.Equals(subject) && b.Num.Equals(num) join i in db.Classes on b.CId equals i.CId into inv from j1 in inv.DefaultIfEmpty() where j1.Year == year && j1.Season.Equals(season) select j1.ClsId; int[] clsIDtmp = query2.ToArray(); if (query0.Any()) { return(Json(new { success = false })); } else { var query = from a in db.AssignmentCategories select a.AcId; bool cond = true; string s = string.Empty; while (true) { var random = new Random(); s = ""; for (int i = 0; i < 3; i++) { s = String.Concat(s, random.Next(10).ToString()); } foreach (int U in query) { if (U.ToString().Equals(s)) { cond = false; } } if (cond) { break; } } AssignmentCategories newAC = new AssignmentCategories(); newAC.AcId = Int32.Parse(s); newAC.ClsId = clsIDtmp[0]; newAC.Name = category; newAC.Weight = (uint)catweight; db.AssignmentCategories.Add(newAC); db.SaveChanges(); return(Json(new { success = true })); } } catch (Exception) { return(Json(new { success = false })); } } }
public void GetAssignmentsInClassWithSubmission() { var db = Utils.MakeMockDatabase(); var controller = MakeController(db); string uid = AddOneStudent(db); Courses newCourse = new Courses { CatalogId = "12345", Listing = "CS", Name = "Algorithms", Number = "3550" }; db.Courses.Add(newCourse); Classes newClass = new Classes { CId = 101, CatalogId = "12345", SemesterYear = 2019, SemesterSeason = "Spring", Location = "On the moon", StartTime = new TimeSpan(), EndTime = new TimeSpan() }; db.Classes.Add(newClass); AssignmentCategories assCat = new AssignmentCategories { AcId = 1002, Name = "Quizzes", GradingWeight = 50, CId = 101 }; db.AssignmentCategories.Add(assCat); Assignments newAssignment = new Assignments { AId = 999, AcId = 1002, Name = "Bonus Quiz", MaxPointValue = 102, DueDate = DateTime.Now, Content = "oanklaks fl lja", }; db.Assignments.Add(newAssignment); Submissions newSubmission = new Submissions { UId = uid, AId = 999, Content = "This is some serious content", Time = DateTime.Now, Score = 78, }; db.Submissions.Add(newSubmission); db.SaveChanges(); var jsonResults = controller.GetAssignmentsInClass("CS", 3550, "Spring", 2019, uid) as JsonResult; dynamic resultValues = jsonResults.Value; Assert.Single(resultValues); var firstResult = resultValues[0]; uint score = Utils.GetValue <uint>(firstResult, "score"); Assert.Equal((uint)78, score); }