public PaginationDataList <AdminDto> SearchAdminPaination( int?pageIndex, int?userType, string userName, int?singletonPageCount = null) { userName = Guard.EnsureParam(userName); var type = userType ?? 0; if (type > 2 || type < 1) { type = 0; } var query = _adminRepository.GetAll() .Where(a => a.UserName.Contains(userName)) .OrderByDescending(x => x.Id); if (type != 0) { query = _adminRepository .GetAll() .Where(a => a.UserName.Contains(userName) && a.UserType == (UserType)type) .OrderByDescending(x => x.Id); } PaginationDataList <Admin> list = query.ToPagination(pageIndex, singletonPageCount); return(ObjectMapper.Map <PaginationDataList <AdminDto> >(list)); }
public void GetInstitutionAllClasses_Return_Empty_If_Institution_Not_Exists() { PaginationDataList <ClassInfoOut> result = _classAppService.GetInstitutionAllClasses(-1, 1); result.CurrentPage.ShouldBe(0); result.ListData.Count.ShouldBe(0); result.TotalPages.ShouldBe(0); }
public PaginationDataList <AdminDto> GetAllInstitutionAdmin( int?pageIndex, int institutionId, int?singletonPageCount = null) { PaginationDataList <Admin> list = _adminRepository.GetAll() .Where(x => x.InstitutionId == institutionId && x.InstitutionId.HasValue) .OrderByDescending(x => x.Id) .ToPagination(pageIndex, singletonPageCount); return(ObjectMapper.Map <PaginationDataList <AdminDto> >(list)); }
private void Fill(int?setId, int setStatus, IQueryable <Admin> teacherList, PaginationDataList <AdminDto> paginaList) { var studentQueryable = teacherList.SelectMany(e => e.Classes.SelectMany(x => x.Students)); foreach (var teacher in teacherList) { var dto = ObjectMapper.Map <AdminDto>(teacher); dto.Password = null; teacher.Classes.ForEach(e => { dto.StudentCount = dto.StudentCount + studentQueryable.Count(x => x.ClassId == e.Id); dto.ClassName.Add(e.Name); }); if (setId.HasValue && setId.Value != 0) { if (HasTeacherAllocation(teacher, setId.Value)) { continue; } } if (setStatus != 0) { if (isFilteredBySetStatus(teacher, setStatus)) { continue; } } if (teacher.TeacherAllocations.Count == 0) { dto.SetName.Add(HintInfo.UnAllocated); } else { foreach (var teacherAllocation in teacher.TeacherAllocations) { var set = SetRepository.Single(e => e.Id == teacherAllocation.SetId); var count = StudentAllocationRepository.Count(e => e.TeacherAllocationId == teacherAllocation.Id); dto.SetName.Add(set.SetName + "----" + count + "/" + teacherAllocation.Credit); } } paginaList.ListData.Add(dto); } }
public void GetInstitutionAllClasses_Return_10_Data() { Institution institution = InitFakeEntity.GetFakeInstitution(); for (var i = 0; i < 10; i++) { ClassInfo classInfo = new ClassInfo { Name = "Class2", ReminderInterva = 180, DateCreated = DateTime.Now }; institution.ClassInfos.Add(classInfo); } var institution2 = UsingDbContext(ctx => ctx.Institution.Add(institution)); PaginationDataList <ClassInfoOut> result = _classAppService.GetInstitutionAllClasses(institution2.Id, 1); result.CurrentPage.ShouldBe(1); result.ListData.Count.ShouldBe(10); result.TotalPages.ShouldBe(1); }
public PaginationDataList <AdminDto> SearchTeacherPaination(int?pageSize, int?pageRows, string teacherName, int?classId, int?setId, int setStatus, Guid userId) { teacherName = Guard.EnsureParam(teacherName); var teacherList = _adminRepository.GetAllIncluding(e => e.Classes, e => e.TeacherAllocations) .Where(e => e.UserName.Contains(teacherName) && e.UserType == UserType.Teacher && e.UserId != userId); if (classId.HasValue && classId.Value != 0) { teacherList = FilterTeacherByClassId(teacherList, classId.Value); } if (teacherList.Count() == 0) { return new PaginationDataList <AdminDto>() { CurrentPage = 0, ListData = new List <AdminDto>(), TotalPages = 0 } } ; PaginationDataList <AdminDto> paginaList = new PaginationDataList <AdminDto> { CurrentPage = pageSize ?? 0 }; Fill(setId, setStatus, teacherList, paginaList); if (paginaList.ListData.Count == 0) { return new PaginationDataList <AdminDto>() { CurrentPage = 0, ListData = new List <AdminDto>(), TotalPages = 0 } } ; paginaList.ListData = paginaList.ListData.Skip((pageSize.Value - 1) * pageRows.Value).Take(pageRows.Value).ToList(); paginaList.TotalPages = (int)Math.Ceiling(paginaList.ListData.Count * 1.0 / pageRows.Value); return(paginaList); }
public void GetAll_Should_Should_Return_Correct_Number_Of_Records() { var institution = UsingDbContext(ctx => ctx.Institution.Add(InitFakeEntity.GetFakeInstitution())); var adminEntity = InitFakeEntity.GetFakeAdmin(); adminEntity.InstitutionId = institution.Id; var admin = UsingDbContext(ctx => ctx.Admin.Add(adminEntity)); for (int i = 0; i < 10; i++) { Order order = InitFakeEntity.GetFakeOrder(); order.UserId = admin.UserId; order.OrderRef += i; UsingDbContext(ctx => ctx.Order.Add(order)); } PaginationDataList <OrderDto> list = _orderAppService.GetAll(1, null); list.CurrentPage.ShouldBe(1); list.ListData.Count.ShouldBe(10); list.TotalPages.ShouldBe(1); }