/// <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 submission. /// Returns the empty string ("") if there is no 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 in the category</param> /// <param name="uid">The uid of the student who submitted it</param> /// <returns>The submission text</returns> public IActionResult GetSubmissionText(string subject, int num, string season, int year, string category, string asgname, string uid) //works { //sub, num --> catalogID // catalogID, year, season --> ClassID // classID, category --> acID // acID, name -- > aID // aID,uID -- GetSubmissonText using (Team9LMSContext db = new Team9LMSContext()) { var conQuery = from aid in (from acID in (from ci in (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 }) join ac in db.AssignmentCategories on ci.classID equals ac.ClassId where ac.Name == category select new { acID = ac.AcId }) join asg in db.Assignments on acID.acID equals asg.AcId where asg.Name == asgname select new { asg.AId }) join s in db.Submission on new { aID = aid.AId, uid } equals new { aID = s.AId, uid = s.UId } into aJoinS from aS in aJoinS.DefaultIfEmpty() select new { content = aS == null ? "" : aS.Contents }; var content = conQuery.First().content.ToString(); return(Content(content)); } }
/// <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) // works { //sub, num --> catalogID // catalogID, year, season --> ClassID // classID, category --> acID // acID, name -- > contents using (Team9LMSContext db = new Team9LMSContext()) { var conQuery = from acID in (from ci in (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 }) join ac in db.AssignmentCategories on ci.classID equals ac.ClassId where ac.Name == category select new { acID = ac.AcId }) join asg in db.Assignments on acID.acID equals asg.AcId where asg.Name == asgname select new { asg.Contents }; var content = conQuery.First().Contents.ToString(); return(Content(content)); } }
/// <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) //works { JsonResult json = null; using (Team9LMSContext db = new Team9LMSContext()) { var subQuery = from s in (from aid in (from acID in (from ci in (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 }) join ac in db.AssignmentCategories on ci.classID equals ac.ClassId where ac.Name == category select new { acID = ac.AcId }) join asg in db.Assignments on acID.acID equals asg.AcId where asg.Name == asgname select new { asg.AId }) join s in db.Submission on aid.AId equals s.AId select s) join u in db.Users on s.UId equals u.UId into sJoinU from sU in sJoinU select new { fname = sU.FirstName, lname = sU.LastName, uid = s.UId, time = s.Time, score = s.Score }; json = Json(subQuery.ToArray()); } return(json); }
/*******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) //works { // uid --> classID, grade // classID --> catalog ID, semester,( semester --> year, season) // catalogID --> subject, number, name JsonResult json = null; using (Team9LMSContext db = new Team9LMSContext()) { var myClassesQuery = from cla1 in (from cl in (from e in db.Enrolled where e.UId == uid select new { grade = e.Grade ?? "--", classID = e.ClassId, }) join cla in db.Classes on cl.classID equals cla.ClassId select new { catalogID = cla.CatalogId, season = cla.Semester.ToString().Substring(4), year = cla.Semester.ToString().Substring(0, 4), cl.grade }) join cou in db.Courses on cla1.catalogID equals cou.CatalogId select new { subject = cou.Subject, number = cou.Num, name = cou.Name, cla1.season, cla1.year, cla1.grade }; json = Json(myClassesQuery.ToArray()); } return(json); }
/*******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 = ""; using (Team9LMSContext db = new Team9LMSContext()) { Users newUser = new Users { FirstName = fName, LastName = lName, Dob = DOB }; db.Users.Add(newUser); db.SaveChanges(); var query = from u in db.Users where u.FirstName == fName && u.LastName == lName select new { uID = u.UId }; foreach (var q in query) { string[] sList = Convert.ToString(q.uID).Split(" "); uID = sList[0]; } if (role == "Administrator") { Administrators newAd = new Administrators { UId = uID }; db.Administrators.Add(newAd); db.SaveChanges(); } if (role == "Professor") { Professors newPro = new Professors { UId = uID, Subject = SubjectAbbrev }; db.Professors.Add(newPro); db.SaveChanges(); } if (role == "Student") { Students newStu = new Students { UId = uID, Subject = SubjectAbbrev }; db.Students.Add(newStu); db.SaveChanges(); } } return(uID); }
/*******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) //works { //subject , num -- > catalogID //catalogID , season, year --> classID // classID -- all uid // all information JsonResult json = null; using (Team9LMSContext db = new Team9LMSContext()) { var sicQuery = from uid in (from ci in (from cid in (from c in db.Courses where c.Subject == subject && c.Num == num select new { c.CatalogId }) join cl in db.Classes on cid.CatalogId equals cl.CatalogId where cl.Semester == year.ToString() + season select new { classID = cl.ClassId }) join e in db.Enrolled on ci.classID equals e.ClassId select new { uid = e.UId, grade = e.Grade }) join u in db.Users on uid.uid equals u.UId select new { fname = u.FirstName, lname = u.LastName, dob = u.Dob, uid = u.UId, uid.grade }; json = Json(sicQuery.ToArray()); } return(json); }
/// <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) //works { JsonResult json = null; using (Team9LMSContext db = new Team9LMSContext()) { var myClassesQuery = from cl in (from c in db.Classes where c.UId == uid select new { season = c.Semester.Substring(4), year = c.Semester.Substring(0, 4), catelogID = c.CatalogId }) join co in db.Courses on cl.catelogID equals co.CatalogId select new { subject = co.Subject, number = co.Num, name = co.Name, cl.season, cl.year }; json = Json(myClassesQuery.ToArray()); } return(json); }
/// <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, true otherwise.</returns> public IActionResult CreateCourse(string subject, int number, string name) //works { if (number > 9999 || number < 0) { return(Json(new { success = false })); } if (name.Length > 100) { return(Json(new { success = false })); } using (Team9LMSContext db = new Team9LMSContext()) { //check to void duplicate (sub, num) var query = from c in db.Courses where c.Subject == subject && c.Num == (uint)number select c; if (query.Count() > 0) { return(Json(new { success = false })); } //add new entry to db Courses newCourse = new Courses { Name = name, Num = (uint)number, Subject = subject }; db.Courses.Add(newCourse); db.SaveChanges(); } return(Json(new { success = true })); }
/// <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) //works { //sub, num --> catalogID //CatalogID , season, year --> classID // classID --> acID // acID --> aIDs // aIDs , uid --> all score earned JsonResult json = null; using (Team9LMSContext db = new Team9LMSContext()) { var asgICQuery = from asg in (from acID in (from ci in (from cid in (from c in db.Courses where c.Subject == subject && c.Num == num select new { c.CatalogId }) join cl in db.Classes on cid.CatalogId equals cl.CatalogId where cl.Semester == year.ToString() + season select new { classID = cl.ClassId }) join ac in db.AssignmentCategories on ci.classID equals ac.ClassId select new { acID = ac.AcId, cname = ac.Name }) join ass in db.Assignments on acID.acID equals ass.AcId select new { aname = ass.Name, acID.cname, due = ass.Due, aID = ass.AId }) join s in db.Submission on new { asg.aID, uID = uid } equals new { aID = s.AId, uID = s.UId } into aJoinS from aS in aJoinS.DefaultIfEmpty() select new { asg.aname, asg.cname, asg.due, score = aS == null ? (uint?)null : aS.Score }; json = Json(asgICQuery.ToArray()); } return(json); }
/// <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, true otherwise.</returns> public IActionResult Enroll(string subject, int num, string season, int year, string uid) //works { //sub , num --> catalogID // catalogID, season, year --> classid // classid, uied -- add to Enroll var flag = 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 }; Enrolled newEn = new Enrolled(); newEn.UId = uid; newEn.ClassId = (uint)Convert.ToInt32(classIDQuery.First().classID); db.Enrolled.Add(newEn); db.SaveChanges(); flag = true; } return(Json(new { success = flag })); }
/// <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) //works { JsonResult json = null; using (Team9LMSContext db = new Team9LMSContext()) { var catalogIDQuery = from c in db.Courses where c.Subject == subject && c.Num == number select new { c.CatalogId }; uint catalogID = 0; foreach (var cq in catalogIDQuery) { catalogID = cq.CatalogId; } var classQuery = from c in db.Classes join u in db.Users on c.UId equals u.UId where c.CatalogId == catalogID select new { season = c.Semester.Substring(4), year = c.Semester.Substring(0, 4), location = c.Location, start = c.StartTime, end = c.EndTime, fname = u.FirstName, lname = u.LastName }; json = Json(classQuery.ToArray()); } return(json); }
/// <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). /// </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) { //sub, num --> catalogID // catalogID, year, season --> ClassID // classID, category --> acID // acID, asgname -- > aID // aID, uID, Constents --> add to submission using (Team9LMSContext db = new Team9LMSContext()) { var aIDQuery = from acID in (from ci in (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 }) join ac in db.AssignmentCategories on ci.classID equals ac.ClassId where ac.Name == category select new { acID = ac.AcId }) join asg in db.Assignments on acID.acID equals asg.AcId where asg.Name == asgname select new { asg.AId, asg.Points }; uint aID = aIDQuery.First().AId; var subQuery = from s in db.Submission where s.AId == aID && s.UId == uid select s; if (subQuery.Count() > 0) { subQuery.First().Time = DateTime.Now; subQuery.First().Contents = contents; try { db.Update(subQuery.First()); db.SaveChanges(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); } } else { Submission newSub = new Submission(); newSub.AId = aID; newSub.UId = uid; newSub.Time = DateTime.Now; newSub.Contents = contents; //newSub.Score = 0; db.Submission.Add(newSub); 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</returns> public IActionResult CreateAssignment(string subject, int num, string season, int year, string category, string asgname, int asgpoints, DateTime asgdue, string asgcontents) // works { //subject, num -- catalogId //catalogID, semester -- > classID //class ID , Name - ACID // asgname, asgcontenst, asgpoint, asgdue, acid --- add new assignment using (Team9LMSContext db = new Team9LMSContext()) { var acIDQuery = from ci in (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 }) join ac in db.AssignmentCategories on ci.classID equals ac.ClassId where ac.Name == category select new { acID = ac.AcId, ci.classID }; uint acID = (uint)Convert.ToInt32(acIDQuery.First().acID); //check to void duiplicate (name , acID ) var duplicateCheckQuery = from asg in db.Assignments where asg.Name == asgname && asg.AcId == acID select asg; if (duplicateCheckQuery.Count() > 0) { return(Json(new { success = false })); } if (asgpoints < 0) { return(Json(new { success = false })); } //add new entry to db Assignments newAS = new Assignments(); newAS.AcId = acID; newAS.Name = asgname; newAS.Contents = asgcontents; newAS.Points = (uint)asgpoints; newAS.Due = asgdue; db.Assignments.Add(newAS); try { db.SaveChanges(); } catch (Exception e) { return(Json(new { success = false })); } //updata all students's grades. uint classID = (uint)Convert.ToInt32(acIDQuery.First().classID); GPA.ClassGradeUpdate(classID); } return(Json(new { success = true })); }
public uint NumSub(uint aID) { using (Team9LMSContext db = new Team9LMSContext()) { var subQuery = from s in db.Submission where s.AId == aID select s; return((uint)subQuery.Count()); } }
public static uint numAssignments(uint acID) { using (Team9LMSContext db = new Team9LMSContext()) { var asgQuery = from asg in db.Assignments where asg.AcId == acID select asg; return((uint)asgQuery.Count()); } }
/// <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() //works { // TODO: Do not return this hard-coded array. JsonResult json = null; using (Team9LMSContext db = new Team9LMSContext()) { var query = from d in db.Departments select new { name = d.DepartmentName, subject = d.Subject }; json = Json(query.ToArray()); } return(json); }
/*******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) //works { JsonResult json = null; using (Team9LMSContext db = new Team9LMSContext()) { var query = from c in db.Courses where c.Subject == subject select new { name = c.Name, number = c.Num }; json = Json(query.ToArray()); } return(json); }
/// <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) //works { uint classID = 0; using (Team9LMSContext db = new Team9LMSContext()) { var subQuery = from aid in (from acID in (from ci in (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 }) join ac in db.AssignmentCategories on ci.classID equals ac.ClassId where ac.Name == category select new { acID = ac.AcId }) join asg in db.Assignments on acID.acID equals asg.AcId where asg.Name == asgname select new { asg.AId, asg.Points }) join s in db.Submission on aid.AId equals s.AId where s.UId == uid select new { s, aid.Points }; uint points = (uint)subQuery.First().Points; if (score < 0 || score > points) { return(Json(new { success = false })); } subQuery.First().s.Score = (uint)score; db.Update(subQuery.First().s); db.SaveChanges(); //update student's letter grade. 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 }; classID = (uint)Convert.ToInt32(classIDQuery.First().classID); GPA.GradeUpdate(uid, classID); } return(Json(new { success = true })); }
/// <summary> /// Returns a JSON array of all the professors working in a given department. /// Each object in the array should have the following fields: /// "lname" - The professor's last name /// "fname" - The professor's first name /// "uid" - The professor's uid /// </summary> /// <param name="subject">The department subject abbreviation</param> /// <returns>The JSON result</returns> // jrm didnot be verified. public IActionResult GetProfessors(string subject) //works { JsonResult json = null; using (Team9LMSContext db = new Team9LMSContext()) { var query = from p in db.Professors join u in db.Users on new { uID = p.UId, sub = p.Subject } equals new { uID = u.UId, sub = subject } select new { uid = p.UId, fname = u.FirstName, lname = u.LastName }; json = Json(query.ToArray()); } return(json); }
/// <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) // works { using (Team9LMSContext db = new Team9LMSContext()) { var aQuery = from a in db.Administrators join u in db.Users on a.UId equals u.UId where a.UId == uid select new { fname = u.FirstName, lname = u.LastName, uid = a.UId, }; if (aQuery.Count() > 0) { return(Json(aQuery.First())); } var pQuery = from p in (from p in db.Professors join d in db.Departments on p.Subject equals d.Subject where p.UId == uid select new { UId = uid, dName = d.DepartmentName }) join u in db.Users on p.UId equals u.UId select new { fname = u.FirstName, lname = u.LastName, uid = p.UId, department = p.dName }; if (pQuery.Count() > 0) { return(Json(pQuery.First())); } var sQuery = from p in (from s in db.Students join d in db.Departments on s.Subject equals d.Subject where s.UId == uid select new { UId = uid, dName = d.DepartmentName }) join u in db.Users on p.UId equals u.UId select new { fname = u.FirstName, lname = u.LastName, uid = p.UId, department = p.dName }; if (sQuery.Count() > 0) { return(Json(sQuery.First())); } } return(Json(new { success = false })); }
/// <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, /// true otherwise.</returns> public IActionResult CreateClass(string subject, int number, string season, int year, DateTime start, DateTime end, string location, string instructor) //works { using (Team9LMSContext db = new Team9LMSContext()) { var catalogIDQuery = from c in db.Courses where c.Subject == subject && c.Num == number select new { c.CatalogId }; uint catalogID = 0; foreach (var cq in catalogIDQuery) { catalogID = cq.CatalogId; } // To void Location and time overlay or duplicate class in same semester TimeSpan nStart = DT2TimeSpan(start); TimeSpan nEnd = DT2TimeSpan(end); var locationTimeQuery = from c in db.Classes where (c.CatalogId == catalogID && c.Semester == year.ToString() + season) || ((c.Location == location && ((c.StartTime <= nStart && c.EndTime >= nEnd) || (c.StartTime >= nStart && c.StartTime <= nEnd) || (c.EndTime >= nStart && c.EndTime <= nEnd))) && (c.Semester == year.ToString() + season)) select c; if (locationTimeQuery.Count() > 0) { return(Json(new { success = false })); } Classes newClass = new Classes { Semester = Convert.ToString(year) + season, CatalogId = catalogID, Location = location, StartTime = DT2TimeSpan(start), EndTime = DT2TimeSpan(end), UId = instructor }; db.Classes.Add(newClass); try { db.SaveChanges(); } catch (Exception) { return(Json(new { success = false })); } } 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() //works { JsonResult json = null; using (Team9LMSContext db = new Team9LMSContext()) { var departments_query = from d in db.Departments select new { subject = d.Subject, dname = d.DepartmentName, courses = from c in db.Courses where c.Subject == d.Subject select new { number = c.Num, cname = c.Name } }; json = Json(departments_query.ToArray()); } return(json); }
/// <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 })); }
public static void ClassGradeUpdate(uint classID) { List <string> uids = new List <string>(); using (Team9LMSContext db = new Team9LMSContext()) { //Get all student's uid of this class var uidQuery = from e in db.Enrolled where e.ClassId == classID select new { uid = e.UId }; foreach (var uq in uidQuery) { uids.Add(uq.uid); } } //update each student's grade foreach (string uid in uids) { GradeUpdate(uid, classID); } }
/// <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) //works { // subject , num -- CourseID // Course Id, seson , year -- Class ID // ClassID --> cate name ,weigt JsonResult json = null; using (Team9LMSContext db = new Team9LMSContext()) { var classIDQuery = from ci in (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 }) join ac in db.AssignmentCategories on ci.classID equals ac.ClassId select new { name = ac.Name, weight = ac.Weight }; json = Json(classIDQuery.ToArray()); } return(json); }
/// <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 is not enrolled in any classes, 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) { var finalGPA = 0.0; using (Team9LMSContext db = new Team9LMSContext()) { var gradeQuery = from e in db.Enrolled where e.UId == uid select new { e.Grade }; List <string> grades = new List <string>(); foreach (var g in gradeQuery) { if (g.Grade != "--") { grades.Add(g.Grade); } } finalGPA = GPA.GPACalculation(grades); } return(Json(new { gpa = finalGPA })); }
public static void GradeUpdate(string uid, uint classID) { Dictionary <uint, uint> acIDAndWeight = new Dictionary <uint, uint>(); Dictionary <uint, uint> acIDAndTotalPoints = new Dictionary <uint, uint>(); Dictionary <uint, uint> acIDAndTotalScores = new Dictionary <uint, uint>(); Dictionary <uint, uint> acIDAndTotalAsgs = new Dictionary <uint, uint>(); List <uint> acIDs = new List <uint>(); uint totalWeight = 0; using (Team9LMSContext db = new Team9LMSContext()) { //Get all categories of this class var awQuery = from ac in db.AssignmentCategories where ac.ClassId == classID select new { ac.AcId, ac.Weight }; foreach (var aw in awQuery) { acIDAndWeight.Add(aw.AcId, (uint)aw.Weight); acIDAndTotalPoints.Add(aw.AcId, 0); acIDAndTotalScores.Add(aw.AcId, 0); acIDs.Add(aw.AcId); } //Get all score of each assignment in each assignment category var asgsQuery = from asg1 in (from acID in (from ac in db.AssignmentCategories where ac.ClassId == classID select new { ac.AcId }) join asg in db.Assignments on acID.AcId equals asg.AcId select new { asg.AId, asg.Points, asg.AcId }) join s in db.Submission on asg1.AId equals s.AId where s.UId == uid select new { s, points = asg1.Points, acID = asg1.AcId }; foreach (var a1 in asgsQuery) { uint acID = (uint)a1.acID; uint score = (uint?)a1.s.Score ?? 0; acIDAndTotalScores[acID] += score; } //Get all point of each assignment var pointsQuery = from acID in (from ac in db.AssignmentCategories where ac.ClassId == classID select new { ac.AcId }) join asg in db.Assignments on acID.AcId equals asg.AcId select new { asg.AId, points = asg.Points, acID = asg.AcId }; foreach (var pq in pointsQuery) { uint acID = (uint)pq.acID; uint points = (uint)pq.points; acIDAndTotalPoints[acID] += points; } //Get number of assignments for each assignment category var asgNumQuery = from ac in db.AssignmentCategories where ac.ClassId == classID select new { acID = ac.AcId, numAsg = numAssignments(ac.AcId) }; foreach (var aNQ in asgNumQuery) { acIDAndTotalAsgs.Add(aNQ.acID, aNQ.numAsg); } //calculation of total weight and scalefactor for (int i = 0; i < acIDs.Count(); i++) { var tempAcID = acIDs[i]; if (acIDAndTotalAsgs[tempAcID] != 0) { totalWeight += acIDAndWeight[tempAcID]; } } double scaleFactor = 100.00 / totalWeight; //Calculation for final score for this class double finalScore = 0.0; for (int i = 0; i < acIDs.Count(); i++) { var tempAcID = acIDs[i]; if (acIDAndTotalPoints[tempAcID] != 0) // denominator should not be zero --- mean no assigments in this category or this assignment will not be counted. { double tempScore = (double)acIDAndTotalScores[tempAcID] / acIDAndTotalPoints[tempAcID] * acIDAndWeight[tempAcID] * scaleFactor; finalScore += tempScore; } } //convert score to letter grade List <int> percentage = new List <int> { 93, 90, 87, 83, 80, 77, 73, 70, 67, 63, 60, 0 }; List <string> letters = new List <string> { "A", "A-", "B+", "B", "B-", "C+", "C", "C-", "D+", "D", "D-", "E" }; int index = indexOfLetters(percentage, finalScore); string letterGrade = letters[index]; //update letter grade to DB var gradeQuery = from e in db.Enrolled where e.ClassId == classID && e.UId == uid select e; gradeQuery.First().Grade = letterGrade; db.Update(gradeQuery.First()); db.SaveChanges(); } }
/* * 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(Team9LMSContext ctx) { db = ctx; }
/// <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) { // sub, num -- catalog ID // season year, catalogID -- classID // classID, category -- acID // all class with acID if (category == null) { using (Team9LMSContext db = new Team9LMSContext()) { var asQuery = from acID in (from ci in (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 }) join ac in db.AssignmentCategories on ci.classID equals ac.ClassId select new { acID = ac.AcId, Name = ac.Name }) join ass in db.Assignments on acID.acID equals ass.AcId select new { aname = ass.Name, cname = acID.Name, due = ass.Due, submissions = NumSub(ass.AId) }; return(Json(asQuery.ToArray())); } } JsonResult json = null; using (Team9LMSContext db = new Team9LMSContext()) { var asQuery = from acID in (from ci in (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 }) join ac in db.AssignmentCategories on ci.classID equals ac.ClassId where ac.Name == category select new { acID = ac.AcId, Name = ac.Name }) join ass in db.Assignments on acID.acID equals ass.AcId select new { aname = ass.Name, cname = acID.Name, due = ass.Due, submissions = NumSub(ass.AId) }; json = Json(asQuery.ToArray()); } return(json); }
public CommonController() { db = new Team9LMSContext(); }