/// <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())); } }
/// <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 })); } }
/// <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 })); } }
/// <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 })); } }
/// <summary> /// Returns a JSON array with all the assignments in an assignment category for a class. /// If the "category" parameter is null, return all assignments in the class. /// Each object in the array should have the following fields: /// "aname" - The assignment name /// "cname" - The assignment category name. /// "due" - The due DateTime /// "submissions" - The number of submissions to the assignment /// </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, /// or null to return assignments from all categories</param> /// <returns>The JSON array</returns> public IActionResult GetAssignmentsInCategory(string subject, int num, string season, int year, string category) { using (Team36LMSContext db = new Team36LMSContext()) { if (category != null) { var query = from c in db.Courses where c.Subject == subject && c.Number == num join cl in db.Classes on c.CourseId equals cl.CourseId where cl.Season == season && cl.Year == year join ac in db.AssignmentCategories on cl.ClassId equals ac.ClassId where ac.Name == category join a in db.Assignments on ac.Acid equals a.Acid select new { aname = a.Name, cname = ac.Name, due = a.Due, submissions = (from s in db.Submission where a.Aid == s.Aid select s).Count() }; return(Json(query.ToArray())); } else { var query = from c in db.Courses where c.Subject == subject && c.Number == num join cl in db.Classes on c.CourseId equals cl.CourseId where cl.Season == season && cl.Year == year join ac in db.AssignmentCategories on cl.ClassId equals ac.ClassId join a in db.Assignments on ac.Acid equals a.Acid select new { aname = a.Name, cname = ac.Name, due = a.Due, submissions = (from s in db.Submission where a.Aid == s.Aid select s).Count() }; return(Json(query.ToArray())); } } }
/// <summary> /// Gets information about a user as a single JSON object. /// The object should have the following fields: /// "fname": the user's first name /// "lname": the user's last name /// "uid": the user's uid /// "department": (professors and students only) the name (such as "Computer Science") of the department for the user. /// If the user is a Professor, this is the department they work in. /// If the user is a Student, this is the department they major in. /// If the user is an Administrator, this field is not present in the returned JSON /// </summary> /// <param name="uid">The ID of the user</param> /// <returns> /// The user JSON object /// or an object containing {success: false} if the user doesn't exist /// </returns> public IActionResult GetUser(string uid) { using (Team36LMSContext db = new Team36LMSContext()) { var query1 = from s in db.Students where uid == s.UId join d in db.Departments on s.Major equals d.Subject select new { fname = s.FirstName, lname = s.LastName, uid = s.UId, department = d.Name }; var query2 = from p in db.Professors where uid == p.UId join d in db.Departments on p.Subject equals d.Subject select new { fname = p.FirstName, lname = p.LastName, uid = p.UId, department = d.Name }; var query3 = from a in db.Administrators where uid == a.UId select new { fname = a.FirstName, lname = a.LastName, uid = a.UId, }; if (query1.Count() != 0) { return(Json(query1.ToArray()[0])); } else if (query2.Count() != 0) { return(Json(query2.ToArray()[0])); } else if (query3.Count() != 0) { return(Json(query3.ToArray()[0])); } return(Json(new { success = false })); } }
/// <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 })); } }
/// <summary> /// Retreive a JSON array of all departments from the database. /// Each object in the array should have a field called "name" and "subject", /// where "name" is the department name and "subject" is the subject abbreviation. /// </summary> /// <returns>The JSON array</returns> public IActionResult GetDepartments() { // TODO: Do not return this hard-coded array. using (Team36LMSContext db = new Team36LMSContext()) { var query = from t in db.Departments select new { name = t.Name, subject = t.Subject }; return(Json(query.ToArray())); } }
/*******Begin code to modify********/ /// <summary> /// Returns a JSON array of all the courses in the given department. /// Each object in the array should have the following fields: /// "number" - The course number (as in 5530) /// "name" - The course name (as in "Database Systems") /// </summary> /// <param name="subject">The department subject abbreviation (as in "CS")</param> /// <returns>The JSON result</returns> public IActionResult GetCourses(string subject) { using (Team36LMSContext db = new Team36LMSContext()) { var query = from c in db.Courses where c.Subject == subject select new { number = c.Number, name = c.Name }; return(Json(query.ToArray())); } }
/// <summary> /// Returns a JSON array of the assignment categories for a certain class. /// Each object in the array should have the folling fields: /// "name" - The category name /// "weight" - The category weight /// </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> /// <returns>The JSON array</returns> public IActionResult GetAssignmentCategories(string subject, int num, string season, int year) { using (Team36LMSContext db = new Team36LMSContext()) { var query = from c in db.Courses where c.Subject == subject && c.Number == num join cl in db.Classes on c.CourseId equals cl.CourseId where cl.Season == season && cl.Year == year join ac in db.AssignmentCategories on cl.ClassId equals ac.ClassId select new { name = ac.Name, weight = ac.GradingWeight }; return(Json(query.ToArray())); } }
/// <summary> /// This method does NOT return JSON. It returns plain text (containing html). /// Use "return Content(...)" to return plain text. /// Returns the contents of an assignment. /// </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 in the category</param> /// <returns>The assignment contents</returns> public IActionResult GetAssignmentContents(string subject, int num, string season, int year, string category, string asgname) { using (Team36LMSContext db = new Team36LMSContext()) { var query = from c in db.Courses where c.Subject == subject && c.Number == num join cl in db.Classes on c.CourseId equals cl.CourseId where cl.Season == season && cl.Year == year join ac in db.AssignmentCategories on cl.ClassId equals ac.ClassId where ac.Name == category join a in db.Assignments on ac.Acid equals a.Acid where a.Name == asgname select a.Contents; //System.Diagnostics.Debug.WriteLine("content is: " + query.FirstOrDefault()); return(Content(query.FirstOrDefault())); } }
/// <summary> /// Returns a JSON array of the classes taught by the specified professor /// Each object in the array should have the following fields: /// "subject" - The subject abbreviation of the class (such as "CS") /// "number" - The course number (such as 5530) /// "name" - The course name /// "season" - The season part of the semester in which the class is taught /// "year" - The year part of the semester in which the class is taught /// </summary> /// <param name="uid">The professor's uid</param> /// <returns>The JSON array</returns> public IActionResult GetMyClasses(string uid) { using (Team36LMSContext db = new Team36LMSContext()) { var query = from c in db.Classes where c.UId == uid join k in db.Courses on c.CourseId equals k.CourseId select new { subject = k.Subject, number = k.Number, name = k.Name, season = c.Season, year = c.Year }; return(Json(query.ToArray())); } }
/// <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 })); } }
/// <summary> /// Returns a JSON array representing the course catalog. /// Each object in the array should have the following fields: /// "subject": The subject abbreviation, (e.g. "CS") /// "dname": The department name, as in "Computer Science" /// "courses": An array of JSON objects representing the courses in the department. /// Each field in this inner-array should have the following fields: /// "number": The course number (e.g. 5530) /// "cname": The course name (e.g. "Database Systems") /// </summary> /// <returns>The JSON array</returns> public IActionResult GetCatalog() { using (Team36LMSContext db = new Team36LMSContext()) { var query = from t in db.Departments join c in db.Courses on t.Subject equals c.Subject select new { dname = t.Name, subject = t.Subject, courses = from c2 in db.Courses where t.Subject == c2.Subject select new { number = c2.Number, cname = c2.Name } }; return(Json(query.ToArray())); } }
/// <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 })); } }
/// <summary> /// Returns a JSON array of all class offerings of a specific course. /// Each object in the array should have the following fields: /// "season": the season part of the semester, such as "Fall" /// "year": the year part of the semester /// "location": the location of the class /// "start": the start time in format "hh:mm:ss" /// "end": the end time in format "hh:mm:ss" /// "fname": the first name of the professor /// "lname": the last name of the professor /// </summary> /// <param name="subject">The subject abbreviation, as in "CS"</param> /// <param name="number">The course number, as in 5530</param> /// <returns>The JSON array</returns> public IActionResult GetClassOfferings(string subject, int number) { using (Team36LMSContext db = new Team36LMSContext()) { var query = from t in db.Courses where subject == t.Subject && number == t.Number join c in db.Classes on t.CourseId equals c.CourseId join p in db.Professors on c.UId equals p.UId select new { season = c.Season, year = c.Year, location = c.Location, start = c.Start, end = c.End, fname = p.FirstName, lname = p.LastName }; return(Json(query.ToArray())); } }
/*******Begin code to modify********/ /// <summary> /// Returns a JSON array of the classes the given student is enrolled in. /// Each object in the array should have the following fields: /// "subject" - The subject abbreviation of the class (such as "CS") /// "number" - The course number (such as 5530) /// "name" - The course name /// "season" - The season part of the semester /// "year" - The year part of the semester /// "grade" - The grade earned in the class, or "--" if one hasn't been assigned /// </summary> /// <param name="uid">The uid of the student</param> /// <returns>The JSON array</returns> public IActionResult GetMyClasses(string uid) { using (Team36LMSContext db = new Team36LMSContext()) { var query = from s in db.Students join e in db.Enrollment on s.UId equals e.UId join cl in db.Classes on e.ClassId equals cl.ClassId join c in db.Courses on cl.CourseId equals c.CourseId where s.UId == uid select new { subject = c.Subject, number = c.Number, name = c.Name, season = cl.Season, year = cl.Year, grade = e == null ? "--" : e.Grade }; return(Json(query.ToArray())); } }
/*******Begin code to modify********/ /// <summary> /// Returns a JSON array of all the students in a class. /// Each object in the array should have the following fields: /// "fname" - first name /// "lname" - last name /// "uid" - user ID /// "dob" - date of birth /// "grade" - the student's grade in this 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> /// <returns>The JSON array</returns> public IActionResult GetStudentsInClass(string subject, int num, string season, int year) { using (Team36LMSContext db = new Team36LMSContext()) { var query = from c in db.Courses where subject == c.Subject && num == c.Number join cl in db.Classes on c.CourseId equals cl.CourseId where season == cl.Season && year == cl.Year join e in db.Enrollment on cl.ClassId equals e.ClassId join s in db.Students on e.UId equals s.UId select new { fname = s.FirstName, lname = s.LastName, uid = s.UId, dob = s.Dob, grade = e == null ? "--" : e.Grade }; return(Json(query.ToArray())); } }
/// <summary> /// Calculates a student's GPA /// A student's GPA is determined by the grade-point representation of the average grade in all their classes. /// Assume all classes are 4 credit hours. /// If a student does not have a grade in a class ("--"), that class is not counted in the average. /// If a student does not have any grades, they have a GPA of 0.0. /// Otherwise, the point-value of a letter grade is determined by the table on this page: /// https://advising.utah.edu/academic-standards/gpa-calculator-new.php /// </summary> /// <param name="uid">The uid of the student</param> /// <returns>A JSON object containing a single field called "gpa" with the number value</returns> public IActionResult GetGPA(string uid) { using (Team36LMSContext db = new Team36LMSContext()) { double GPA = 0.0; double Grades = 0.0; int count = 0; var query = from e in db.Enrollment where e.UId == uid select e.Grade; foreach (string g in query) { if (g == "A") { Grades += 4.0; count++; } else if (g == "A-") { Grades += 3.7; count++; } else if (g == "B+") { Grades += 3.3; count++; } else if (g == "B") { Grades += 3.0; count++; } else if (g == "B-") { Grades += 2.7; count++; } else if (g == "C+") { Grades += 2.3; count++; } else if (g == "C") { Grades += 2.0; count++; } else if (g == "C-") { Grades += 1.7; count++; } else if (g == "D+") { Grades += 1.3; count++; } else if (g == "D") { Grades += 1.0; count++; } else if (g == "D-") { Grades += 0.7; count++; } else if (g == "F") { Grades += 0.0; count++; } } if (count != 0) { GPA = Grades / count; } //System.Diagnostics.Debug.WriteLine("GPA is: "+GPA); return(Json(new { gpa = GPA })); } //return Json(new { gpa = 0.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 })); } }
public CommonController() { db = new Team36LMSContext(); }
/// <summary> /// Returns a JSON array of all the assignments in the given class that the given student is enrolled in. /// Each object in the array should have the following fields: /// "aname" - The assignment name /// "cname" - The category name that the assignment belongs to /// "due" - The due Date/Time /// "score" - The score earned by the student, or null if the student has not submitted to this assignment. /// </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="uid"></param> /// <returns>The JSON array</returns> public IActionResult GetAssignmentsInClass(string subject, int num, string season, int year, string uid) { using (Team36LMSContext db = new Team36LMSContext()) { bool flag = true; var check = 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 cl.ClassId equals ac.ClassId join assignment in db.Assignments on ac.Acid equals assignment.Acid join s in db.Submission on assignment.Aid equals s.Aid select new { score = s == null ? null : (uint?)s.Score }; if (check.ToArray().FirstOrDefault() == null) { flag = false; } ; //System.Diagnostics.Debug.WriteLine("Check :" + check.ToArray().FirstOrDefault() + "hhh" + flag); if (flag) { 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 join assignment in db.Assignments on ac.Acid equals assignment.Acid join s in db.Submission on assignment.Aid equals s.Aid select new { aname = assignment.Name, cname = ac.Name, due = assignment.Due, score = s == null ? null : (uint?)s.Score }; return(Json(query.ToArray())); } else { 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 join assignment in db.Assignments on ac.Acid equals assignment.Acid select new { aname = assignment.Name, cname = ac.Name, due = assignment.Due }; return(Json(query.ToArray())); } } }
/*******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; } }
/* * WARNING: This is the quick and easy way to make the controller * use a different LibraryContext - good enough for our purposes. * The "right" way is through Dependency Injection via the constructor * (look this up if interested). */ // TODO: Uncomment and change 'X' after you have scaffoled public void UseLMSContext(Team36LMSContext ctx) { db = ctx; }