public ItemsCountModel <T> GetLinqedList <T>(IEnumerable <T> completeList, Func <T, bool> predicate, string filterByProperty, string filterByValue, string orderBy, SortOrder sortOrder, int skip, int take) { var result = new ItemsCountModel <T>(); // 1. Search based on the query var matchQueryList = predicate == null ? completeList : GetMatchQueryList(completeList, predicate); // 2. Filter var filteredList = String.IsNullOrWhiteSpace(filterByProperty) || String.IsNullOrWhiteSpace(filterByValue) ? matchQueryList : GetFilteredList(matchQueryList, filterByProperty, filterByValue); // 3. Set count result.Count = filteredList.Count(); // 4. Order/Sort var ordedList = String.IsNullOrWhiteSpace(orderBy) ? filteredList : GetSortedList(filteredList, orderBy, sortOrder); // 5. Skip var skipList = ordedList.Skip(skip); // 6. Take var takeList = take == int.MaxValue ? skipList : skipList.Take(take); result.Items = takeList; return(result); }
public ItemsCountModel GetItemsCount(int CustomerId, DateTime?fromReceiveDate, DateTime?toReceiveDate) { using (var db = new EntityContext()) { var totalItemReceive = _item.GetAll(db).Where(i => i.Customer.Id == CustomerId && i.ReceiveDate != null).ToList(); var totalItem = _item.GetAll(db).Where(i => i.Customer.Id == CustomerId && (i.Status.Id == 6 || i.Status.Id == 8)).ToList(); var totalSuccess = _item.GetAll(db).Where(i => i.Customer.Id == CustomerId && i.Status.Id == 6).ToList(); var totalFailture = _item.GetAll(db).Where(i => i.Customer.Id == CustomerId && i.Status.Id == 8).ToList(); if (fromReceiveDate != null) { totalItemReceive = totalItemReceive.Where(i => i.ReceiveDate >= fromReceiveDate).ToList(); totalItem = totalItem.Where(i => i.ReceiveDate >= fromReceiveDate).ToList(); totalSuccess = totalSuccess.Where(i => i.ReceiveDate >= fromReceiveDate).ToList(); totalFailture = totalFailture.Where(i => i.ReceiveDate >= fromReceiveDate).ToList(); } if (toReceiveDate != null) { totalItemReceive = totalItemReceive.Where(i => i.ReceiveDate <= toReceiveDate).ToList(); totalItem = totalItem.Where(i => i.ReceiveDate <= toReceiveDate).ToList(); totalSuccess = totalSuccess.Where(i => i.ReceiveDate <= toReceiveDate).ToList(); totalFailture = totalFailture.Where(i => i.ReceiveDate <= toReceiveDate).ToList(); } ItemsCountModel result = new ItemsCountModel { totalItemReceive = totalItemReceive.Count(), totalItem = totalItem.Count(), totalSuccess = totalSuccess.Count(), totalSendBack = totalFailture.Count() }; return(result); } }
public async Task GetTranscriptUnmatchedForCurrentSchool_should_return_ok_with_result() { // Arrange: var unmatchedTranscriptsBySchool = new List <TranscriptBaseModel> { new TranscriptBaseModel { TranscriptId = 1000000, StudentName = "FirstName, LastName", StudentNumber = "1234", DateOfBirth = "30/05/2000", ReceivedDateUtc = new DateTime() } }; _mockTranscriptRepository.Setup(tr => tr.GetTranscriptUnmatchedBySchoolIdAsync(It.IsAny <int>())).ReturnsAsync(unmatchedTranscriptsBySchool); var unmatchedTranscriptsBySchoolLinqed = new ItemsCountModel <TranscriptBaseModel> { Items = unmatchedTranscriptsBySchool, Count = 1 }; _mockLinqWrapperService.Setup(ls => ls.GetLinqedList( It.IsAny <IEnumerable <TranscriptBaseModel> >(), It.IsAny <Func <TranscriptBaseModel, bool> >(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SortOrder>(), It.IsAny <int>(), It.IsAny <int>() )).Returns(unmatchedTranscriptsBySchoolLinqed); var responseModel = unmatchedTranscriptsBySchool; _mockTranscriptService.Setup(ts => ts.GetTranscriptUnmatchedResponseModelAsync(It.IsAny <List <TranscriptBaseModel> >(), It.IsAny <int>())).ReturnsAsync(responseModel); // Act var actionResult = await CreateController().GetTranscriptUnmatchedForCurrentSchool(); //Assert var contentResult = new OkObjectResult(actionResult); Assert.AreEqual(StatusCodes.Status200OK, contentResult.StatusCode); var response = Result <ItemsCountModel <TranscriptBaseModel> >(actionResult); Assert.IsNotNull(response); var expected = new ItemsCountModel <TranscriptBaseModel> { Items = responseModel, Count = 1 }; CollectionAssert.AreEquivalent(expected.Items.ToList(), response.Items.ToList()); Assert.AreEqual(expected.Count, response.Count); }
public ItemsCountModel GetStatisticItemScanReturnCount(DateTime?fromDate, DateTime?toDate) { using (var db = new EntityContext()) { var items = _item.GetAll(db).Where(i => i.SendingDate >= fromDate && i.SendingDate <= toDate && (i.Status.Id == 8 || i.Status.Id == 9)).ToList(); double all = items.Count(); double success = items.Where(i => (i.Status.Id == 8) && i.SentDate != null).Count(); ItemsCountModel result = new ItemsCountModel { totalItem = all, totalSuccess = success, totalItemReceive = 0, totalSendBack = 0 }; return(result); } }
public async Task <IActionResult> GetTranscriptUnmatchedForCurrentSchool(string query = "", string filterByProperty = "", string filterByValue = "", string orderBy = "receivedDateUtc", SortOrder sortOrder = SortOrder.ASC, int skip = 0, int take = int.MaxValue) { // @TODO: Check if the current user is an educator and has permission to view Transcripts => THERE IS ALREADY A CHECK IN FE, THIS IS NECESSARY ONLY TO PROTECT THE API FROM PEOPLE USING SOFTWARE LIKE POSTMAN // @TODO: The max number of records per school is 1k so It seems reasonable to assume the 1k records will fit in memory // and do all the manipulation (query, filter, sorting, skip, take) with LINQ (this will be cheaper and faster) instead of SQL. // Cache the list in Redis and make sure we update the cache when a new transcript is imported or deleted var educatorId = GetClaim <int>(CcClaimType.EducatorId); var currentSchool = await _institutionRepository.GetDefaultInstitutionByEducatorIdAsync(educatorId); var transcriptUnmatchedCompleteList = await _transcriptRepository.GetTranscriptUnmatchedBySchoolIdAsync(currentSchool.Id); var transcriptUnmatchedSearchPredicate = _transcriptService.GetTranscriptUnmatchedSearchPredicate(query); var transcriptUnmatchedLinqedList = _linqWrapperService.GetLinqedList(transcriptUnmatchedCompleteList, transcriptUnmatchedSearchPredicate, filterByProperty, filterByValue, orderBy, sortOrder, skip, take); var result = new ItemsCountModel <TranscriptBaseModel> { Items = await _transcriptService.GetTranscriptUnmatchedResponseModelAsync(transcriptUnmatchedLinqedList.Items, currentSchool.Id), Count = transcriptUnmatchedLinqedList.Count }; return(Ok(result)); }
public async Task GetTranscriptRequestProgressForCurrentSchool_should_return_ok_with_result() { // Arrange: var currentSchool = new InstitutionModel { Id = 1234, InstitutionName = "Institution Name", InstitutionType = InstitutionTypeEnum.School }; _mockInstitutionRepository.Setup(ir => ir.GetDefaultInstitutionByEducatorIdAsync(It.IsAny <int>())).ReturnsAsync(currentSchool); var requestsProgressBySchool = new List <TranscriptRequestProgressViewModel> { new TranscriptRequestProgressViewModel { Id = 1234, InunId = "1234", ReceivingInstitutionCode = 1234, UserAccountId = 1234, AvatarFileName = "avatar.jpg", SchoolCountryType = CountryType.US, StudentName = "FirstName, LastName", DateOfBirth = new DateTime(2000, 5, 23), GradeId = 11, GradeKey = "GRADE_11", StudentId = "1234", TranscriptRequestId = 12, ReceivingInstitutionName = "Institution Name", ReceivingInstitutionCity = "City", ReceivingInstitutionStateCode = "SC", RequestedDate = new DateTime(), TranscriptStatus = TranscriptRequestStatus.Submitted, TranscriptStatusKey = "SUBMITTED", TranscriptStatusDate = new DateTime() } }; _mockTranscriptRequestRepository.Setup(rr => rr.GetTranscriptRequestProgressBySchoolIdAsync(It.IsAny <int>())).ReturnsAsync(requestsProgressBySchool); var requestsProgressBySchoolLinqed = new ItemsCountModel <TranscriptRequestProgressViewModel> { Items = requestsProgressBySchool, Count = 1 }; _mockLinqWrapperService.Setup(ls => ls.GetLinqedList( It.IsAny <IEnumerable <TranscriptRequestProgressViewModel> >(), It.IsAny <Func <TranscriptRequestProgressViewModel, bool> >(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SortOrder>(), It.IsAny <int>(), It.IsAny <int>() )).Returns(requestsProgressBySchoolLinqed); var responseModel = new List <TranscriptRequestProgressResponseModel> { new TranscriptRequestProgressResponseModel { Id = 1234, AvatarUrl = "http://www.avatar.com/avatar.jpg", StudentName = "FirstName, LastName", DateOfBirth = new DateTime(2000, 5, 23), GradeId = 11, GradeKey = "GRADE_11", StudentId = "1234", TranscriptRequestId = 12, InunId = "1234", ReceivingInstitutionCode = 1234, ReceivingInstitutionName = "Institution Name", ReceivingInstitutionCity = "City", ReceivingInstitutionStateCode = "SC", RequestedDate = new DateTime(), TranscriptStatus = TranscriptRequestStatus.Submitted, TranscriptStatusKey = "SUBMITTED", TranscriptStatusDate = new DateTime() } }; _mockTranscriptRequestService.Setup(rs => rs.GetTranscriptRequestProgressResponseModelAsync(It.IsAny <List <TranscriptRequestProgressViewModel> >(), It.IsAny <int>())).ReturnsAsync(responseModel); // Act var actionResult = await CreateController().GetTranscriptRequestProgressForCurrentSchool(); //Assert var contentResult = new OkObjectResult(actionResult); Assert.AreEqual(StatusCodes.Status200OK, contentResult.StatusCode); var response = Result <ItemsCountModel <TranscriptRequestProgressResponseModel> >(actionResult); Assert.IsNotNull(response); var expected = new ItemsCountModel <TranscriptRequestProgressResponseModel> { Items = responseModel, Count = 1 }; CollectionAssert.AreEquivalent(expected.Items.ToList(), response.Items.ToList()); Assert.AreEqual(expected.Count, response.Count); }
public async Task GetStudentTranscriptForCurrentSchool_should_return_ok_with_result() { // Arrange: var studentTranscriptsBySchool = new List <StudentTranscriptViewModel> { new StudentTranscriptViewModel { Id = 1234, UserAccountId = 1234, AvatarFileName = "avatar.jpg", SchoolCountryType = CountryType.US, StudentName = "FirstName, LastName", DateOfBirth = new DateTime(2000, 5, 23), GradeId = 11, GradeKey = "GRADE_11", StudentId = "1234", TranscriptId = 1000000, ReceivedDateUtc = new DateTime() } }; _mockTranscriptRepository.Setup(tr => tr.GetStudentTranscriptBySchoolIdAsync(It.IsAny <int>())).ReturnsAsync(studentTranscriptsBySchool); var studentTranscriptsBySchoolLinqed = new ItemsCountModel <StudentTranscriptViewModel> { Items = studentTranscriptsBySchool, Count = 1 }; _mockLinqWrapperService.Setup(ls => ls.GetLinqedList( It.IsAny <IEnumerable <StudentTranscriptViewModel> >(), It.IsAny <Func <StudentTranscriptViewModel, bool> >(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SortOrder>(), It.IsAny <int>(), It.IsAny <int>() )).Returns(studentTranscriptsBySchoolLinqed); var responseModel = new List <StudentTranscriptResponseModel> { new StudentTranscriptResponseModel { Id = 1234, AvatarUrl = "http://www.avatar.com/avatar.jpg", StudentName = "FirstName, LastName", DateOfBirth = new DateTime(2000, 5, 23), GradeId = 11, GradeKey = "GRADE_11", StudentId = "1234", TranscriptId = 1000000, ReceivedDateUtc = new DateTime() } }; _mockTranscriptService.Setup(ts => ts.GetStudentTranscriptResponseModelAsync(It.IsAny <List <StudentTranscriptViewModel> >())).ReturnsAsync(responseModel); // Act var actionResult = await CreateController().GetStudentTranscriptForCurrentSchool(); //Assert var contentResult = new OkObjectResult(actionResult); Assert.AreEqual(StatusCodes.Status200OK, contentResult.StatusCode); var response = Result <ItemsCountModel <StudentTranscriptResponseModel> >(actionResult); Assert.IsNotNull(response); var expected = new ItemsCountModel <StudentTranscriptResponseModel> { Items = responseModel, Count = 1 }; CollectionAssert.AreEquivalent(expected.Items.ToList(), response.Items.ToList()); Assert.AreEqual(expected.Count, response.Count); }