public ActionResult Add(DateTime start, DateTime end, string classcode) { Teacher t = UserBinding.getTeacher(User.Identity.GetUserId()); //TODO clean parameters if (t == null) { return(RedirectToAction("Index", "Home")); } if (ClassroomBinding.GetClassroomFromCode(classcode)?.classID != null) { ViewBag.ErrorMessage = "Error: please enter a unique class code."; return(View()); } var classroom = new Classroom { classID = ClassroomBinding.GenerateClassId(), semesterStart = start, semesterEnd = end, classCode = classcode, teacherID = t.TeacherID }; ClassroomBinding.SaveRoom(classroom); return(RedirectToAction("Index", "Home")); }
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 ActionResult Index(string classcode) { Teacher t = UserBinding.getTeacher(User.Identity.GetUserId()); Classroom cr = ClassroomBinding.GetClassroomFromCode(classcode); if (cr == null || t == null || classcode == null) { //TODO add viewbag error? return(RedirectToAction("Index", "Home")); } ClassroomIndexViewModel model = new ClassroomIndexViewModel(); model.Classroom = cr; model.Teacher = t; model.Students = cr.Student.ToList(); return(View(model)); }
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)); }
public ActionResult Index(string role, string fname, string lname) { if (role != null) { if (role == "Student") { var student = UserBinding.getStudent(User.Identity.GetUserId()); if (student != null) { student.studentFirst = fname; UserBinding.SaveStudent(student); } else { var newstudent = new Student { StudentID = UserBinding.GenerateStudentId(), studentFirst = fname, UserID = User.Identity.GetUserId(), studentUsername = User.Identity.GetUserName() }; UserBinding.SaveStudent(newstudent); } } else if (role == "Teacher") { var teacher = UserBinding.getTeacher(User.Identity.GetUserId()); if (teacher != null) { teacher.teacherFirst = fname; teacher.teacherLast = lname; UserBinding.SaveTeacher(teacher); } else { var newteacher = new Teacher { TeacherID = UserBinding.GenerateTeacherId(), teacherFirst = fname, teacherLast = lname, UserID = User.Identity.GetUserId(), teacherUsername = User.Identity.GetUserName() }; UserBinding.SaveTeacher(newteacher); } } else if (role == "Parent") { var parent = new Parent { parentID = UserBinding.GenerateParentId(), parentFirst = fname, UserID = User.Identity.GetUserId(), parentUsername = User.Identity.GetUserName() }; UserBinding.SaveParent(parent); } //get logged in user from browser context ApplicationUser user = UserManager.FindById(User.Identity.GetUserId()); user.ClassroomRole = role; UserManager.Update(user); } var vmodel = new IndexViewModel { userClassroomRole = role }; return(View(vmodel)); }