public ActionResult Index() { if (Request.IsAuthenticated) { var AspNetUser = UserManager.FindById(User.Identity.GetUserId()); IndexViewModel model = new IndexViewModel { userClassroomRole = AspNetUser.ClassroomRole }; if (AspNetUser.ClassroomRole == "Student") { Student studentUser = UserBinding.getStudent(AspNetUser.Id); if (studentUser == null) { return(View(new IndexViewModel())); } model.userfname = studentUser.studentFirst; if (studentUser.classID == null) { model.userClassrooms = null; return(View(model)); } model.userClassrooms = new List <Classroom>(); model.userClassrooms.Add(ClassroomBinding.GetClassroomFromID(studentUser.classID)); } else if (AspNetUser.ClassroomRole == "Parent") { Parent parentUser = UserBinding.getParent(AspNetUser.Id); model.userfname = parentUser.parentFirst; } else if (AspNetUser.ClassroomRole == "Teacher") { Teacher teacherUser = UserBinding.getTeacher(AspNetUser.Id); if (teacherUser == null) { //TODO add log? return(View(new IndexViewModel())); } model.userfname = teacherUser.teacherFirst; model.userlname = teacherUser.teacherLast; model.userClassrooms = UserBinding.getTeacherClassrooms(teacherUser.TeacherID); } return(View(model)); } return(View()); }
public async Task <ActionResult> Index(ManageMessageId?message) { ViewBag.StatusMessage = message == ManageMessageId.Error ? "An error has occurred." : ""; var AspNetUser = UserManager.FindById(User.Identity.GetUserId()); var model = new IndexViewModel { userClassroomRole = AspNetUser.ClassroomRole }; if (AspNetUser.ClassroomRole == "Student") { Student studentUser = UserBinding.getStudent(AspNetUser.Id); if (studentUser == null) { studentUser = new Student(); } model.userfname = studentUser.studentFirst; } else if (AspNetUser.ClassroomRole == "Parent") { Parent parentUser = UserBinding.getParent(AspNetUser.Id); //TODO null check model.userfname = parentUser.parentFirst; } else if (AspNetUser.ClassroomRole == "Teacher") { Teacher teacherUser = UserBinding.getTeacher(AspNetUser.Id); if (teacherUser == null) { //TODO add log? return(View(new IndexViewModel())); } else { model.userfname = teacherUser.teacherFirst; model.userlname = teacherUser.teacherLast; } } return(View(model)); }