Exemple #1
0
        public void GetIdByUniqueId_WithExistingTeacher_ShouldReturnCorrectId()
        {
            _teachersRepositoryMock.Setup(t => t.All())
            .Returns(new List <Teacher>
            {
                new Teacher
                {
                    Id       = TestTeacherDBId,
                    UniqueId = TestTeacherUniqueID
                }
            }.AsQueryable());

            var teacherId = _teachersService.GetIdByUniqueId(TestTeacherUniqueID);

            teacherId.Should().Be(TestTeacherDBId);
        }
Exemple #2
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>());
        }