public async Task <UserListResponse> getUsersAsync(ListDTO listDTO) { try { UserListResponse userListResponse = new UserListResponse(); userListResponse.Users = new List <UserRow>(); var lst = Context.Users.Select(a => new UserRow { Id = a.Id, UserName = a.UserName, Email = a.Email }).AsQueryable(); if (listDTO.Filter != null && listDTO.Filter != string.Empty) { lst = new LinqSearch().ApplyFilter(lst, listDTO.Filter); } userListResponse.LstCount = await lst.CountAsync(); userListResponse.Users = await lst.Skip((listDTO.PageNum - 1) *listDTO.PageSize).Take(listDTO.PageSize).ToListAsync(); userListResponse.ToSuccess <UserListResponse>(); return(userListResponse); } catch (Exception ex) { throw new Exception(ex.Message); } }
public void BubbleSortListNameAscTest() { ISearch sut = new LinqSearch(); var values = new List <BucketListItem>(); values.Add(new BucketListItem() { Name = "ZBucketListItem" }); values.Add(new BucketListItem() { Name = "yBucketListItem" }); values.Add(new BucketListItem() { Name = "ABucketListItem" }); values.Add(new BucketListItem() { Name = "tBucketListItem" }); var searchResults = sut.Search(values, "yBucketListItem"); Assert.IsNotNull(searchResults); Assert.AreEqual(1, searchResults.Count); Assert.AreEqual("yBucketListItem", searchResults[0].Name); }
public async Task <ClaimsResponse> GetClaimListByPaging(ListDTO listDTO) { ClaimsResponse claimsResponse = new ClaimsResponse(); var lst = (from a in Context.Set <Claims>() select new ClaimsRow() { Id = a.Id, ActionName = a.ActionName, ActionTitleEn = a.ActionTitleEn, ActionTitleFr = a.ActionTitleFr, ControlleEnTitile = a.ControlleEnTitile, ControlleFaTitile = a.ControlleFaTitile, ControllerEntityID = a.ControllerEntityID, ControllerName = a.ControllerName }).AsQueryable(); if (listDTO.Filter != null && listDTO.Filter.Trim().Length != 0) { lst = new LinqSearch().ApplyFilter(lst, listDTO.Filter); } if (listDTO.IsRequestCount) { claimsResponse.LstCount = await lst.CountAsync(); } else { claimsResponse.Claims = await lst.Skip((listDTO.PageNum - 1) *listDTO.PageSize).Take(listDTO.PageSize).ToListAsync(); } return(claimsResponse); }
public void TestSearchWithWrongCriteria() { // Search by Genre and Company.(string genre, string year, string company, string rating, string price) SearchCriteria criteria = new SearchCriteria("Openn world", "20188", "RockStarr", "", ""); ISearch search = new LinqSearch(); List <Game> games = search.Search(criteria); Assert.AreEqual(null, games?[0]?.Genre); Assert.AreEqual(null, games?[0]?.Year); Assert.AreEqual(null, games?[0]?.Company); Assert.AreEqual(null, games?[0]?.Rating); Assert.AreEqual(null, games?[0]?.Price); }
public void LinqSearch_ReturnStationAndValidCharacters_CallWithoutPerformingSearch_ThrowsInvalidOperationException() { Mock <IStationReader> stationListStub = new Mock <IStationReader>(); stationListStub.Setup(s => s.Read()).Returns(AllStations); stationListStub.Setup(s => s.AllStations).Returns(AllStations); Mock <ISearchString> searchStringStub = new Mock <ISearchString>(); searchStringStub.Setup(x => x.Validate()).Returns(true); searchStringStub.SetupGet(x => x.IsValid).Returns(true); searchStringStub.SetupGet(x => x.Value).Returns("DART"); var searchStation = new LinqSearch(stationListStub.Object, searchStringStub.Object); Assert.ThrowsException <InvalidOperationException>(() => searchStation.ReturnStationAndValidCharacters()); }
public void TestSearchWithCriteria() { // Search by Genre and Company.(string genre, string year, string company, string rating, string price) SearchCriteria criteria = new SearchCriteria("Open world", "2018", "RockStar", "", ""); string expectedGenre = "Open world"; string expectedYear = "2018"; string expectedCompany = "RockStar"; string expectedRating = "9.8/10"; string expectedPrice = "120$"; ISearch search = new LinqSearch(); List <Game> games = search.Search(criteria); Assert.AreEqual(expectedGenre, games[0].Genre); Assert.AreEqual(expectedYear, games[0].Year); Assert.AreEqual(expectedCompany, games[0].Company); Assert.AreEqual(expectedRating, games[0].Rating); Assert.AreEqual(expectedPrice, games[0].Price); }
public void LinqSearch_UserInputsDART_Dartford_And_Dartmouth_Is_Returned() { Mock <IStationReader> stationListStub = new Mock <IStationReader>(); stationListStub.Setup(s => s.Read()).Returns(AllStations); stationListStub.Setup(s => s.AllStations).Returns(AllStations); Mock <ISearchString> searchStringStub = new Mock <ISearchString>(); searchStringStub.Setup(x => x.Validate()).Returns(true); searchStringStub.SetupGet(x => x.IsValid).Returns(true); searchStringStub.SetupGet(x => x.Value).Returns("DART"); var linqSearch = new LinqSearch(stationListStub.Object, searchStringStub.Object); linqSearch.Search(); var result = linqSearch.ReturnStationAndValidCharacters(); var expectedStations = new List <string> { "DARTFORD", "DARTMOUTH" }; CollectionAssert.AreEqual(result.Item1, expectedStations); }
public static void Main() { LinqSort.DemoLinqSort(); LinqSearch.DemoWhere(); }
public async Task <PrescriptionActivityListResponse> GetPrescriptionActivityListByPaging(ListDTO listDTO) { PrescriptionActivityListResponse prescriptionActivityListResponse = new PrescriptionActivityListResponse(); var lst = (from a in Context.Set <PrescriptionBarcodeDetailes>() join b in Context.Set <PrescriptionBarcode>() on a.PrescriptionBarcodeId equals b.Id join p in Context.Set <Prescription>() on b.PrescriptionId equals p.Id join s in Context.Set <PrescriptionBarcodeDetailesType>() on a.PrescriptionBarcodeDetailesTypesId equals s.Id join y in Context.Set <PrescriptionBarcodeStatus>() on b.PrescriptionBarcodeStatusId equals y.Id select new PrescriptionActivityRow { Status = a.Status, StatusMessage = a.StatusMessage, BatchCode = a.BatchCode, EnglishName = a.EnglishName, Expiration = a.Expiration, Irc = a.Irc, PersianName = a.PersianName, Price = a.Price, ProductType = a.ProductType, TrackingCode = a.TrackingCode, UnitConsumed = a.UnitConsumed, Manufacturing = a.Manufacturing, GenericCode = a.GenericCode, ProductTypeId = a.ProductTypeId, BarcodeUid = a.BarcodeUid, PrescriptionBarcodeId = a.PrescriptionBarcodeId, PrescriptionId = b.PrescriptionId, CreatedDate = a.CreatedDate, UpdatedDate = a.UpdatedDate, PrescriptionBarcodeDetailesTypesId = a.PrescriptionBarcodeDetailesTypesId, PrescriptionBarcodeStatusId = b.PrescriptionBarcodeStatusId, PrescriptionBarcodeDetailesTypesName = s.Name, PrescriptionBarcodeStatusName = y.Name, PatientGivenName = p.PatientGivenName, PatientSurname = p.PatientSurname, PatientNationalCode = p.PatientNationalCode, PhysicianGivenName = p.PhysicianGivenName, PhysicianSurname = p.PhysicianSurName, MedicalCouncilNumber = p.MedicalCouncilNumber, PharmacyGln = p.PharmacyGln, BasicInsurance = p.BasicInsurance, ComplementaryInsurance = p.ComplementaryInsurance, Uid = a.Uid, Amount = b.Amount, OutPrescriptionId = p.OutPrescriptionId }).AsQueryable(); if (listDTO.Filter != null && listDTO.Filter != string.Empty) { lst = new LinqSearch().ApplyFilter(lst, listDTO.Filter); } prescriptionActivityListResponse.LstCount = await lst.CountAsync(); prescriptionActivityListResponse.LstPrescriptionActivityRow = await lst.Skip((listDTO.PageNum - 1) *listDTO.PageSize).Take(listDTO.PageSize).ToListAsync(); return(prescriptionActivityListResponse); }