Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using LMS.Models.LMSModels;
- namespace LMS.Controllers
- {
- [Authorize(Roles = "Professor")]
- public class ProfessorController : CommonController
- {
- public IActionResult Index()
- {
- return View();
- }
- public IActionResult Students(string subject, string num, string season, string year)
- {
- ViewData["subject"] = subject;
- ViewData["num"] = num;
- ViewData["season"] = season;
- ViewData["year"] = year;
- return View();
- }
- public IActionResult Class(string subject, string num, string season, string year)
- {
- ViewData["subject"] = subject;
- ViewData["num"] = num;
- ViewData["season"] = season;
- ViewData["year"] = year;
- return View();
- }
- public IActionResult Categories(string subject, string num, string season, string year)
- {
- ViewData["subject"] = subject;
- ViewData["num"] = num;
- ViewData["season"] = season;
- ViewData["year"] = year;
- return View();
- }
- public IActionResult CatAssignments(string subject, string num, string season, string year, string cat)
- {
- ViewData["subject"] = subject;
- ViewData["num"] = num;
- ViewData["season"] = season;
- ViewData["year"] = year;
- ViewData["cat"] = cat;
- return View();
- }
- public IActionResult Assignment(string subject, string num, string season, string year, string cat, string aname)
- {
- ViewData["subject"] = subject;
- ViewData["num"] = num;
- ViewData["season"] = season;
- ViewData["year"] = year;
- ViewData["cat"] = cat;
- ViewData["aname"] = aname;
- return View();
- }
- public IActionResult Submissions(string subject, string num, string season, string year, string cat, string aname)
- {
- ViewData["subject"] = subject;
- ViewData["num"] = num;
- ViewData["season"] = season;
- ViewData["year"] = year;
- ViewData["cat"] = cat;
- ViewData["aname"] = aname;
- return View();
- }
- public IActionResult Grade(string subject, string num, string season, string year, string cat, string aname, string uid)
- {
- ViewData["subject"] = subject;
- ViewData["num"] = num;
- ViewData["season"] = season;
- ViewData["year"] = year;
- ViewData["cat"] = cat;
- ViewData["aname"] = aname;
- ViewData["uid"] = uid;
- return View();
- }
- /*******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 (Team83LMSContext db = new Team83LMSContext())
- {
- string semester = season + year.ToString();
- var query0 = from c in db.Courses
- where c.OfferedBy == subject && c.Number == num
- select new
- {
- cid = c.CatalogId
- };
- var query = from c in db.Classes
- where c.Semester == semester && query0.ToArray()[0].cid==c.CatalogId
- select new
- {
- id = c.Id
- };
- var query2 = from e in db.Enrolls
- join s in db.Students on e.Uid equals s.UId
- where e.Id == query.ToArray()[0].id
- select new
- {
- fname = s.FirstName,
- lname = s.LastName,
- uid = s.UId,
- dob = s.Dob,
- grade = e.Grade
- };
- return Json(query2.ToArray());
- }
- }
- /// <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 (Team83LMSContext db = new Team83LMSContext())
- {
- string semester = season + year.ToString();
- var query0 = from c in db.Courses
- where c.OfferedBy == subject && c.Number == num
- select new
- {
- cid = c.CatalogId
- };
- var query = from c in db.Classes
- where c.Semester == semester && query0.ToArray()[0].cid == c.CatalogId
- select new
- {
- id = c.Id
- };
- var query2 = from acat in db.AssignmentCategories
- join a in db.Assignments on
- acat.CatId equals a.CatId
- where acat.Id == query.ToArray()[0].id
- select new
- {
- aname = a.Name,
- cname = acat.Name,
- due = a.Due,
- submissons = (from ass in db.Assignments
- join s in db.Submissions on ass.AId equals s.AId
- where ass.AId == a.AId
- select new { sub = s.Time }).Count()
- };
- return Json(query2.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 (Team83LMSContext db = new Team83LMSContext())
- {
- string semester = season + year.ToString();
- var query0 = from c in db.Courses
- where c.OfferedBy == subject && c.Number == num
- select new
- {
- cid = c.CatalogId
- };
- var query = from c in db.Classes
- where c.Semester == semester && query0.ToArray()[0].cid == c.CatalogId
- select new
- {
- id = c.Id
- };
- var query2 = from acat in db.AssignmentCategories
- where acat.Id == query.ToArray()[0].id
- select new
- {
- name=acat.Name,
- weight=acat.Weight
- };
- return Json(query2.ToArray());
- }
- }
- /// <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 (Team83LMSContext db = new Team83LMSContext())
- {
- AssignmentCategories asscat = new AssignmentCategories();
- asscat.Name = category;
- asscat.Weight = catweight;
- string semester = season + year.ToString();
- var query = from cl in db.Classes
- join c in db.Courses on cl.CatalogId equals c.CatalogId
- where cl.Semester == semester
- && c.OfferedBy == subject && c.Number == num
- select new
- {
- classid = cl.Id
- };
- asscat.Id = query.ToArray()[0].classid;
- var acatnames = from acat in db.AssignmentCategories
- join cl in db.Classes on acat.Id equals cl.Id
- where cl.Id == asscat.Id
- select new
- {
- name = acat.Name
- };
- for (int x=0; x<acatnames.Count();x++)
- {
- if (acatnames.ToArray()[x].name==category)
- {
- return Json(new { success = false });
- }
- }
- var catid = (from acat in db.AssignmentCategories select acat.CatId).OrderByDescending(x => x);
- int tempid = catid.ToArray()[0] + 1;
- asscat.CatId = tempid;
- db.AssignmentCategories.Add(asscat);
- try
- {
- db.SaveChanges();
- return Json(new { success = true });
- }
- catch
- {
- return Json(new { success = false });
- }
- }
- }
- /// <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)
- {
- return Json(new { success = false });
- }
- /// <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)
- {
- return Json(null);
- }
- /// <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)
- {
- return Json(new { success = true });
- }
- /// <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 (Team83LMSContext db = new Team83LMSContext())
- {
- var query = from c in db.Classes
- where c.Professor == uid
- select new
- {
- subject = (from co in db.Courses
- where co.CatalogId == c.CatalogId
- select new { name = co.OfferedBy }).ToArray()[0].name,
- number = (from co in db.Courses
- where co.CatalogId == c.CatalogId
- select new { number = co.Number }).ToArray()[0].number,
- name = (from co in db.Courses
- where co.CatalogId == c.CatalogId
- select new { name = co.Name }).ToArray()[0].name,
- season = c.Semester.Substring(0, c.Semester.Length - 4),
- year = int.Parse(c.Semester.Substring(c.Semester.Length - 4, 4))
- };
- return Json(query.ToArray());
- }
- }
- /*******End code to modify********/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement