public void Get_Leases_Filter(LeaseFilter filter, int expectedCount) { // Arrange var helper = new TestHelper(); var user = PrincipalHelper.CreateForPermission(Permissions.LeaseView); var elease = EntityHelper.CreateLease(456, lFileNo: "123", tenantLastName: "tenant", addTenant: true); elease.Id = 1; elease.OrigExpiryDate = new DateTime(2000, 1, 1); elease.OrigStartDate = new DateTime(2000, 1, 1); var context = helper.CreatePimsContext(user, true); context.AddAndSaveChanges(elease); var service = helper.CreateRepository <LeaseRepository>(user); // Act var result = service.GetPage(filter); // Assert Assert.NotNull(result); Assert.IsAssignableFrom <Paged <Entity.PimsLease> >(result); Assert.Equal(expectedCount, result.Items.Count); }
public List <LeaseModel> GetLeaList(DataProvider dp, LeaseFilter filter, out int total, bool IsPage = true) { var list = from lea in dp.PM_Lease.Where(m => !m.IsDel) join dic in dp.System_DicItem.Where(m => !m.IsDel) on lea.LeaseType equals dic.Id select new LeaseModel() { Id = lea.Id, IsEnabled = lea.IsEnabled, LeaseName = lea.LeaseName, LeaseType = lea.LeaseType, LeaseTypeDesc = dic.ItemDesc, Sort = lea.Sort, CreateTime = lea.CreateTime }; if (filter.LeaseName.IsNotNullOrWhiteSpace()) { list = list.Where(m => m.LeaseName.Contains(filter.LeaseName)); } if (filter.LeaseType.IsNotNullAndCountGtZero()) { list = list.Where(m => filter.LeaseType.Contains(m.LeaseType)); } list = list.OrderBy(m => m.Sort).ThenByDescending(m => m.CreateTime); total = list.Count(); if (IsPage) { return(list.Skip(filter.Skip).Take(filter.PageSize).ToList()); } else { return(list.ToList()); } }
public List <LeaseModel> GetLeaList(LeaseFilter filter, out int total, bool isPage = true) { using (DataProvider dp = new DataProvider()) { var list = data.GetLeaList(dp, filter, out total, isPage); return(Mapper.Map <List <LeaseModel> >(list)); } }
/// <summary> /// Get an array of leases within the specified filters. /// Note that the 'leaseFilter' will control the 'page' and 'quantity'. /// </summary> /// <param name="filter"></param> /// <returns></returns> public IEnumerable <PimsLease> Get(LeaseFilter filter, bool loadPayments = false) { this.User.ThrowIfNotAuthorized(Permissions.LeaseView); filter.ThrowIfNull(nameof(filter)); if (!filter.IsValid()) { throw new ArgumentException("Argument must have a valid filter", nameof(filter)); } var query = this.Context.GenerateLeaseQuery(filter, loadPayments); var leases = query.OrderBy(l => l.LeaseId).ToArray(); return(leases); }
/// <summary> /// Get a page with an array of leases within the specified filters. /// Note that the 'leaseFilter' will control the 'page' and 'quantity'. /// </summary> /// <param name="filter"></param> /// <returns></returns> public Paged <PimsLease> GetPage(LeaseFilter filter) { this.User.ThrowIfNotAuthorized(Permissions.LeaseView); filter.ThrowIfNull(nameof(filter)); if (!filter.IsValid()) { throw new ArgumentException("Argument must have a valid filter", nameof(filter)); } var skip = (filter.Page - 1) * filter.Quantity; var query = this.Context.GenerateLeaseQuery(filter); var items = query .OrderBy(l => l.LeaseId) .Skip(skip) .Take(filter.Quantity) .ToArray(); return(new Paged <PimsLease>(items, filter.Page, filter.Quantity, query.Count())); }
public ActionResult GetLeaList(LeaseFilter filter) { var data = business.GetLeaList(filter, out int total); return(Json(new TableDataModel(total, data))); }