Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Authorization;
  6. using Microsoft.AspNetCore.Mvc;
  7. using LMS.Models.LMSModels;
  8.  
  9. namespace LMS.Controllers
  10. {
  11. [Authorize(Roles = "Professor")]
  12. public class ProfessorController : CommonController
  13. {
  14. public IActionResult Index()
  15. {
  16. return View();
  17. }
  18.  
  19. public IActionResult Students(string subject, string num, string season, string year)
  20. {
  21. ViewData["subject"] = subject;
  22. ViewData["num"] = num;
  23. ViewData["season"] = season;
  24. ViewData["year"] = year;
  25. return View();
  26. }
  27.  
  28. public IActionResult Class(string subject, string num, string season, string year)
  29. {
  30. ViewData["subject"] = subject;
  31. ViewData["num"] = num;
  32. ViewData["season"] = season;
  33. ViewData["year"] = year;
  34. return View();
  35. }
  36.  
  37. public IActionResult Categories(string subject, string num, string season, string year)
  38. {
  39. ViewData["subject"] = subject;
  40. ViewData["num"] = num;
  41. ViewData["season"] = season;
  42. ViewData["year"] = year;
  43. return View();
  44. }
  45.  
  46. public IActionResult CatAssignments(string subject, string num, string season, string year, string cat)
  47. {
  48. ViewData["subject"] = subject;
  49. ViewData["num"] = num;
  50. ViewData["season"] = season;
  51. ViewData["year"] = year;
  52. ViewData["cat"] = cat;
  53. return View();
  54. }
  55.  
  56. public IActionResult Assignment(string subject, string num, string season, string year, string cat, string aname)
  57. {
  58. ViewData["subject"] = subject;
  59. ViewData["num"] = num;
  60. ViewData["season"] = season;
  61. ViewData["year"] = year;
  62. ViewData["cat"] = cat;
  63. ViewData["aname"] = aname;
  64. return View();
  65. }
  66.  
  67. public IActionResult Submissions(string subject, string num, string season, string year, string cat, string aname)
  68. {
  69. ViewData["subject"] = subject;
  70. ViewData["num"] = num;
  71. ViewData["season"] = season;
  72. ViewData["year"] = year;
  73. ViewData["cat"] = cat;
  74. ViewData["aname"] = aname;
  75. return View();
  76. }
  77.  
  78. public IActionResult Grade(string subject, string num, string season, string year, string cat, string aname, string uid)
  79. {
  80. ViewData["subject"] = subject;
  81. ViewData["num"] = num;
  82. ViewData["season"] = season;
  83. ViewData["year"] = year;
  84. ViewData["cat"] = cat;
  85. ViewData["aname"] = aname;
  86. ViewData["uid"] = uid;
  87. return View();
  88. }
  89.  
  90. /*******Begin code to modify********/
  91.  
  92.  
  93. /// <summary>
  94. /// Returns a JSON array of all the students in a class.
  95. /// Each object in the array should have the following fields:
  96. /// "fname" - first name
  97. /// "lname" - last name
  98. /// "uid" - user ID
  99. /// "dob" - date of birth
  100. /// "grade" - the student's grade in this class
  101. /// </summary>
  102. /// <param name="subject">The course subject abbreviation</param>
  103. /// <param name="num">The course number</param>
  104. /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
  105. /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
  106. /// <returns>The JSON array</returns>
  107. public IActionResult GetStudentsInClass(string subject, int num, string season, int year)
  108. {
  109. using (Team83LMSContext db = new Team83LMSContext())
  110. {
  111. string semester = season + year.ToString();
  112.  
  113. var query0 = from c in db.Courses
  114. where c.OfferedBy == subject && c.Number == num
  115. select new
  116. {
  117. cid = c.CatalogId
  118. };
  119. var query = from c in db.Classes
  120. where c.Semester == semester && query0.ToArray()[0].cid==c.CatalogId
  121. select new
  122. {
  123. id = c.Id
  124. };
  125. var query2 = from e in db.Enrolls
  126. join s in db.Students on e.Uid equals s.UId
  127. where e.Id == query.ToArray()[0].id
  128. select new
  129. {
  130. fname = s.FirstName,
  131. lname = s.LastName,
  132. uid = s.UId,
  133. dob = s.Dob,
  134. grade = e.Grade
  135. };
  136. return Json(query2.ToArray());
  137. }
  138.  
  139. }
  140.  
  141.  
  142.  
  143. /// <summary>
  144. /// Returns a JSON array with all the assignments in an assignment category for a class.
  145. /// If the "category" parameter is null, return all assignments in the class.
  146. /// Each object in the array should have the following fields:
  147. /// "aname" - The assignment name
  148. /// "cname" - The assignment category name.
  149. /// "due" - The due DateTime
  150. /// "submissions" - The number of submissions to the assignment
  151. /// </summary>
  152. /// <param name="subject">The course subject abbreviation</param>
  153. /// <param name="num">The course number</param>
  154. /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
  155. /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
  156. /// <param name="category">The name of the assignment category in the class,
  157. /// or null to return assignments from all categories</param>
  158. /// <returns>The JSON array</returns>
  159. public IActionResult GetAssignmentsInCategory(string subject, int num, string season, int year, string category)
  160. {
  161. using (Team83LMSContext db = new Team83LMSContext())
  162. {
  163. string semester = season + year.ToString();
  164.  
  165. var query0 = from c in db.Courses
  166. where c.OfferedBy == subject && c.Number == num
  167. select new
  168. {
  169. cid = c.CatalogId
  170. };
  171. var query = from c in db.Classes
  172. where c.Semester == semester && query0.ToArray()[0].cid == c.CatalogId
  173. select new
  174. {
  175. id = c.Id
  176. };
  177. var query2 = from acat in db.AssignmentCategories
  178. join a in db.Assignments on
  179. acat.CatId equals a.CatId
  180. where acat.Id == query.ToArray()[0].id
  181. select new
  182. {
  183. aname = a.Name,
  184. cname = acat.Name,
  185. due = a.Due,
  186. submissons = (from ass in db.Assignments
  187. join s in db.Submissions on ass.AId equals s.AId
  188. where ass.AId == a.AId
  189. select new { sub = s.Time }).Count()
  190. };
  191. return Json(query2.ToArray());
  192. }
  193. }
  194.  
  195.  
  196. /// <summary>
  197. /// Returns a JSON array of the assignment categories for a certain class.
  198. /// Each object in the array should have the folling fields:
  199. /// "name" - The category name
  200. /// "weight" - The category weight
  201. /// </summary>
  202. /// <param name="subject">The course subject abbreviation</param>
  203. /// <param name="num">The course number</param>
  204. /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
  205. /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
  206. /// <param name="category">The name of the assignment category in the class</param>
  207. /// <returns>The JSON array</returns>
  208. public IActionResult GetAssignmentCategories(string subject, int num, string season, int year)
  209. {
  210. using (Team83LMSContext db = new Team83LMSContext())
  211. {
  212. string semester = season + year.ToString();
  213.  
  214. var query0 = from c in db.Courses
  215. where c.OfferedBy == subject && c.Number == num
  216. select new
  217. {
  218. cid = c.CatalogId
  219. };
  220. var query = from c in db.Classes
  221. where c.Semester == semester && query0.ToArray()[0].cid == c.CatalogId
  222. select new
  223. {
  224. id = c.Id
  225. };
  226. var query2 = from acat in db.AssignmentCategories
  227.  
  228. where acat.Id == query.ToArray()[0].id
  229. select new
  230. {
  231. name=acat.Name,
  232. weight=acat.Weight
  233. };
  234. return Json(query2.ToArray());
  235. }
  236.  
  237. }
  238.  
  239. /// <summary>
  240. /// Creates a new assignment category for the specified class.
  241. /// If a category of the given class with the given name already exists, return success = false.
  242. /// </summary>
  243. /// <param name="subject">The course subject abbreviation</param>
  244. /// <param name="num">The course number</param>
  245. /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
  246. /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
  247. /// <param name="category">The new category name</param>
  248. /// <param name="catweight">The new category weight</param>
  249. /// <returns>A JSON object containing {success = true/false} </returns>
  250. public IActionResult CreateAssignmentCategory(string subject, int num, string season, int year, string category, int catweight)
  251. {
  252. using (Team83LMSContext db = new Team83LMSContext())
  253. {
  254. AssignmentCategories asscat = new AssignmentCategories();
  255. asscat.Name = category;
  256. asscat.Weight = catweight;
  257. string semester = season + year.ToString();
  258. var query = from cl in db.Classes
  259. join c in db.Courses on cl.CatalogId equals c.CatalogId
  260. where cl.Semester == semester
  261. && c.OfferedBy == subject && c.Number == num
  262. select new
  263. {
  264. classid = cl.Id
  265. };
  266. asscat.Id = query.ToArray()[0].classid;
  267. var acatnames = from acat in db.AssignmentCategories
  268. join cl in db.Classes on acat.Id equals cl.Id
  269. where cl.Id == asscat.Id
  270. select new
  271. {
  272. name = acat.Name
  273. };
  274. for (int x=0; x<acatnames.Count();x++)
  275. {
  276. if (acatnames.ToArray()[x].name==category)
  277. {
  278. return Json(new { success = false });
  279. }
  280.  
  281. }
  282. var catid = (from acat in db.AssignmentCategories select acat.CatId).OrderByDescending(x => x);
  283. int tempid = catid.ToArray()[0] + 1;
  284. asscat.CatId = tempid;
  285. db.AssignmentCategories.Add(asscat);
  286. try
  287. {
  288. db.SaveChanges();
  289. return Json(new { success = true });
  290. }
  291. catch
  292. {
  293. return Json(new { success = false });
  294. }
  295.  
  296. }
  297. }
  298.  
  299. /// <summary>
  300. /// Creates a new assignment for the given class and category.
  301. /// </summary>
  302. /// <param name="subject">The course subject abbreviation</param>
  303. /// <param name="num">The course number</param>
  304. /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
  305. /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
  306. /// <param name="category">The name of the assignment category in the class</param>
  307. /// <param name="asgname">The new assignment name</param>
  308. /// <param name="asgpoints">The max point value for the new assignment</param>
  309. /// <param name="asgdue">The due DateTime for the new assignment</param>
  310. /// <param name="asgcontents">The contents of the new assignment</param>
  311. /// <returns>A JSON object containing success = true/false</returns>
  312. public IActionResult CreateAssignment(string subject, int num, string season, int year, string category, string asgname, int asgpoints, DateTime asgdue, string asgcontents)
  313. {
  314.  
  315. return Json(new { success = false });
  316. }
  317.  
  318.  
  319. /// <summary>
  320. /// Gets a JSON array of all the submissions to a certain assignment.
  321. /// Each object in the array should have the following fields:
  322. /// "fname" - first name
  323. /// "lname" - last name
  324. /// "uid" - user ID
  325. /// "time" - DateTime of the submission
  326. /// "score" - The score given to the submission
  327. ///
  328. /// </summary>
  329. /// <param name="subject">The course subject abbreviation</param>
  330. /// <param name="num">The course number</param>
  331. /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
  332. /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
  333. /// <param name="category">The name of the assignment category in the class</param>
  334. /// <param name="asgname">The name of the assignment</param>
  335. /// <returns>The JSON array</returns>
  336. public IActionResult GetSubmissionsToAssignment(string subject, int num, string season, int year, string category, string asgname)
  337. {
  338.  
  339. return Json(null);
  340. }
  341.  
  342.  
  343. /// <summary>
  344. /// Set the score of an assignment submission
  345. /// </summary>
  346. /// <param name="subject">The course subject abbreviation</param>
  347. /// <param name="num">The course number</param>
  348. /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
  349. /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
  350. /// <param name="category">The name of the assignment category in the class</param>
  351. /// <param name="asgname">The name of the assignment</param>
  352. /// <param name="uid">The uid of the student who's submission is being graded</param>
  353. /// <param name="score">The new score for the submission</param>
  354. /// <returns>A JSON object containing success = true/false</returns>
  355. public IActionResult GradeSubmission(string subject, int num, string season, int year, string category, string asgname, string uid, int score)
  356. {
  357.  
  358. return Json(new { success = true });
  359. }
  360.  
  361.  
  362. /// <summary>
  363. /// Returns a JSON array of the classes taught by the specified professor
  364. /// Each object in the array should have the following fields:
  365. /// "subject" - The subject abbreviation of the class (such as "CS")
  366. /// "number" - The course number (such as 5530)
  367. /// "name" - The course name
  368. /// "season" - The season part of the semester in which the class is taught
  369. /// "year" - The year part of the semester in which the class is taught
  370. /// </summary>
  371. /// <param name="uid">The professor's uid</param>
  372. /// <returns>The JSON array</returns>
  373. public IActionResult GetMyClasses(string uid)
  374. {
  375. using (Team83LMSContext db = new Team83LMSContext())
  376. {
  377.  
  378. var query = from c in db.Classes
  379. where c.Professor == uid
  380. select new
  381. {
  382.  
  383.  
  384. subject = (from co in db.Courses
  385. where co.CatalogId == c.CatalogId
  386. select new { name = co.OfferedBy }).ToArray()[0].name,
  387. number = (from co in db.Courses
  388. where co.CatalogId == c.CatalogId
  389. select new { number = co.Number }).ToArray()[0].number,
  390. name = (from co in db.Courses
  391. where co.CatalogId == c.CatalogId
  392. select new { name = co.Name }).ToArray()[0].name,
  393. season = c.Semester.Substring(0, c.Semester.Length - 4),
  394. year = int.Parse(c.Semester.Substring(c.Semester.Length - 4, 4))
  395.  
  396.  
  397.  
  398. };
  399.  
  400.  
  401. return Json(query.ToArray());
  402. }
  403. }
  404.  
  405.  
  406. /*******End code to modify********/
  407.  
  408. }
  409. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement