public PaginatedList <Person> GetPaginatedPersons(PersonQuery query) { var res = GetPersons(query); return(new PaginatedList <Person>(res.Persons, query.Start / query.Count, query.Count, res.SourceCount)); }
public Person GetPerson(PersonQuery personQuery) { return(GetPersons(personQuery).Persons.First()); }
public PersonQueryResult GetPersons(PersonQuery query) { query.CallerId = Context.PersonId; query.CallerRoleId = Context.Role.Id; var persons = PersonStorage.GetData().Select(x => x.Value); if (query.PersonId.HasValue) { persons = persons.Where(x => x.Id == query.PersonId); } if (query.RoleId.HasValue) { persons = persons.Where(x => x.RoleRef == query.RoleId); } if (!string.IsNullOrWhiteSpace(query.StartFrom)) { persons = persons.Where(x => String.Compare(x.LastName, query.StartFrom, true, CultureInfo.InvariantCulture) >= 0); } if (query.TeacherId.HasValue) { var classPersons = ((DemoClassService)ServiceLocator.ClassService).GetClassPersons(); var classes = classPersons.Select(x => ServiceLocator.ClassService.GetById(x.ClassRef)).ToList(); var clsIds = classes.Where(x => x.PrimaryTeacherRef == query.TeacherId).Select(x => x.Id).ToList(); var personIds = classPersons.Where(x => clsIds.Contains(x.ClassRef)).Select(x => x.PersonRef).ToList(); persons = persons.Where(x => personIds.Contains(x.Id)); } if (query.ClassId.HasValue) { if (query.RoleId.HasValue) { if (query.RoleId == CoreRoles.TEACHER_ROLE.Id) { var teacherRef = ServiceLocator.ClassService.GetClassDetailsById(query.ClassId.Value).PrimaryTeacherRef; persons = persons.Where(x => x.Id == teacherRef); } if (query.RoleId == CoreRoles.STUDENT_ROLE.Id) { var personIds = ((DemoClassService)ServiceLocator.ClassService) .GetClassPersons(query.ClassId.Value).Select(x => x.PersonRef).ToList(); persons = persons.Where(x => personIds.Contains(x.Id)); } } } if (query.CallerRoleId == CoreRoles.STUDENT_ROLE.Id) { var studentGradeLevelId = ((DemoSchoolYearService)ServiceLocator.SchoolYearService).GetStudentGradeLevel(query.CallerId.Value); persons = persons.Where(x => x.Id == query.CallerId || (x.RoleRef == CoreRoles.TEACHER_ROLE.Id || x.RoleRef == CoreRoles.DISTRICT_ADMIN_ROLE.Id) || (x.RoleRef == CoreRoles.STUDENT_ROLE.Id && ((DemoSchoolYearService)ServiceLocator.SchoolYearService).GradeLevelExists(studentGradeLevelId, x.Id))); } if (query.CallerRoleId == CoreRoles.CHECKIN_ROLE.Id) { persons = persons.Where(x => x.Id == query.CallerId || x.RoleRef == CoreRoles.STUDENT_ROLE.Id); } if (!string.IsNullOrEmpty(query.Filter)) { var filter = query.Filter.ToLowerInvariant(); persons = persons.Where(x => x.FullName().ToLowerInvariant().Contains(filter)); } if (query.RoleIds != null) { persons = persons.Where(x => query.RoleIds.Contains(x.RoleRef)); } persons = persons.Skip(query.Start).Take(query.Count).ToList(); persons = query.SortType == SortTypeEnum.ByFirstName ? persons.OrderBy(x => x.FirstName) : persons.OrderBy(x => x.LastName); var enumerable = persons as IList <Person> ?? persons.ToList(); return(new PersonQueryResult { Persons = enumerable.ToList(), Query = query, SourceCount = enumerable.Count }); }