Exemplo n.º 1
0
        private async Task <IEnumerable <ClassViewModel> > GetClassesBasedOnUserRoleAsync()
        {
            if (User.IsInRole(GlobalConstants.TeacherRoleName))
            {
                var user = await _userManager.GetUserAsync(User);

                var teacherId = _teachersService.GetIdByUniqueId(user.UniqueGradebookId);
                if (teacherId == null)
                {
                    return(null); // RedirectToAction("Error", "Home"); // Maybe add reasonable message?
                }

                return(_classesService.GetAllByTeacherId <ClassViewModel>(teacherId.Value));
            }

            if (User.IsInRole(GlobalConstants.StudentRoleName))
            {
                var user = await _userManager.GetUserAsync(User);

                var studentId = _studentsService.GetIdByUniqueId(user.UniqueGradebookId);
                if (studentId == null)
                {
                    return(null);  // RedirectToAction("Error", "Home"); // Maybe add reasonable message?
                }

                return(_classesService.GetAllByStudentId <ClassViewModel>(studentId.Value));
            }

            if (User.IsInRole(GlobalConstants.ParentRoleName))
            {
                var user = await _userManager.GetUserAsync(User);

                var studentIds = _parentsService.GetStudentIdsByParentUniqueId(user.UniqueGradebookId);
                if (!studentIds.Any())
                {
                    return(null);  // RedirectToAction("Error", "Home"); // Maybe add reasonable message?
                }

                return(_classesService.GetAllByMultipleStudentIds <ClassViewModel>(studentIds));
            }

            if (User.IsInRole(GlobalConstants.PrincipalRoleName))
            {
                var user = await _userManager.GetUserAsync(User);

                var schoolIds = _schoolsServices.GetAllByUserId <SchoolViewModel>(user.UniqueGradebookId).Select(s => s.Id);
                if (!schoolIds.Any())
                {
                    return(null);  // RedirectToAction("Error", "Home"); // Maybe add reasonable message?
                }

                return(_classesService.GetAllBySchoolId <ClassViewModel>(schoolIds.FirstOrDefault()));
            }

            return(_classesService.GetAll <ClassViewModel>());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index()
        {
            var viewModel = new IndexViewModel();

            if (_signInManager.IsSignedIn(User))
            {
                var user = await _userManager.GetUserAsync(User);

                viewModel.Username = user?.UserName;
                var isAdmin = await IsCurrentUserAdmin();

                if (isAdmin)
                {
                    viewModel.Schools = _schoolsServices.GetAll <SchoolViewModel>();
                }
                else
                {
                    viewModel.Schools = _schoolsServices.GetAllByUserId <SchoolViewModel>(user?.UniqueGradebookId);
                }
            }

            return(View(viewModel));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> AddClassToSubject()
        {
            var user = await _userManager.GetUserAsync(User);

            var isAdmin = await IsAdmin();

            var schoolIds        = _schoolsServices.GetAllByUserId <SchoolViewModel>(user?.UniqueGradebookId, isAdmin).Select(s => s.Id);
            var classesInSchool  = _classesService.GetAllByMultipleSchoolIds <ClassViewModel>(schoolIds.ToList());
            var subjectsInSchool = _subjectsService.GetAllByMultipleSchoolIds <SubjectViewModel>(schoolIds.ToList());
            var inputModel       = new ClassSubjectCreateInputModel
            {
                Classes  = classesInSchool.Select(c => new SelectListItem($"{c.Year}{c.Letter} ({c.Teacher.SchoolName})", c.Id.ToString())).ToList(),
                Subjects = subjectsInSchool.Select(s => new SelectListItem($"{s.Name} ({s.TeacherSchoolName})({s.TeacherFullName})", s.Id.ToString())).ToList(),
            };

            return(View(inputModel));
        }