Ejemplo 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>());
        }
Ejemplo n.º 2
0
        public async Task GetStudentIdsByParentUniqueIdTest()
        {
            OneTimeSetUp();
            await _parentsRepositoryMock.Object.AddAsync(NewParentCreate());

            var parent   = _parentsRepositoryMock.Object.All().FirstOrDefault(p => p.UniqueId == ParentUniqueId);
            var actual   = _parentsService.GetStudentIdsByParentUniqueId(ParentUniqueId);
            int expected = 1;

            expected.Should().Be(actual.Count);
        }