public IActionResult StudentHome(User user) { StudentDataService studentDataService = new StudentDataService(dbContext); student = studentDataService.GetStudentByUsername(UserManager.GetUserName(User)); ViewData["Id"] = student.Id; StudentClassDataService studentClassDataService = new StudentClassDataService(dbContext); var classes = studentClassDataService.GetClassesByStudentId(student.Id); return(View(classes)); }
public IActionResult ViewAssignments(int classId) { AssignmentDataService assignmentDataService = new AssignmentDataService(dbContext); IEnumerable <Assignment> assignments = assignmentDataService.GetAssignmentsByClassId(classId).Reverse(); StudentDataService studentDataService = new StudentDataService(dbContext); student = studentDataService.GetStudentByUsername(UserManager.GetUserName(User)); ViewData.Add("StudentId", student.Id); return(View(assignments)); }
public async Task <IActionResult> LeaveClass(bool confirm, int classId) { StudentClassDataService studentClassDataService = new StudentClassDataService(dbContext); StudentDataService studentDataService = new StudentDataService(dbContext); ClassDataService classDataService = new ClassDataService(dbContext); student = studentDataService.GetStudentByUsername(UserManager.GetUserName(User)); Class c = classDataService.GetClassById(classId); studentClassDataService.RemoveStudentClass(student, c); await dbContext.SaveChangesAsync(); return(RedirectToAction("StudentHome", "Student")); }
public async Task <IActionResult> JoinClass(string ClassKey) { ClassDataService classDataService = new ClassDataService(dbContext); StudentDataService studentDataService = new StudentDataService(dbContext); student = studentDataService.GetStudentByUsername(UserManager.GetUserName(User)); Class c = classDataService.GetClassByKey(ClassKey); if (c != null) { StudentClassDataService studentClassDataService = new StudentClassDataService(dbContext); bool inClass = studentClassDataService.InClass(student, c); if (!inClass) { studentClassDataService.AddStudentClass(student, c); await dbContext.SaveChangesAsync(); } } return(RedirectToAction("StudentHome", "Student")); }