private IQueryable <Sale> QuerySales(Filters.SaleFilterOptions options, PagingSettings paging = null) { var sales = Context.Sale .Include("OwnerUser") .Include("Tags") .Include("Tags.Tag") .Include("Person") .Where(q => !q.Deleted.HasValue); if (options != null) { if (options.Status.HasValue) { sales = sales.Where(c => c.Status == options.Status.Value); } if (options.Order == "desc") { sales = sales.OrderByDescending(x => x.CreatedDate); } if (options.Campaigns != null) { var ids = options.Campaigns.Select(c => ((Campaign)c).ID).ToList(); sales = sales.Where(l => l.CampaignID.HasValue && ids.Contains(l.CampaignID.Value)); } if (options.Tags != null) { var ids = options.Tags.Select(c => ((Tag)c).ID); sales = sales.Where(l => l.Tags.Where(t => ids.Contains(t.TagID)).Count() > 0); } if (!string.IsNullOrEmpty(options.SearchTerm)) { sales = sales.Where(x => (!string.IsNullOrEmpty(x.Person.FirstName) && x.Person.FirstName.Contains(options.SearchTerm)) || (!string.IsNullOrEmpty(x.Person.LastName) && x.Person.LastName.Contains(options.SearchTerm)) || (!string.IsNullOrEmpty(x.JobTitle) && x.JobTitle.Contains(options.SearchTerm))); } } if (paging != null) { sales = sales.Distinct().OrderByDescending(l => l.CreatedDate).ToPagedQueryable(paging); } return(sales); }
public decimal Sum(Filters.SaleFilterOptions options) { return(Repository.Sum(options)); }
public int Total(Filters.SaleFilterOptions options) { return(Repository.Total(options)); }
public List <Sale> GetAll(Filters.SaleFilterOptions options = null, PagingSettings paging = null) { return(Repository.GetAll(options, paging)); }
public List <Sale> GetAll(Filters.SaleFilterOptions options = null, PagingSettings paging = null) { var sales = QuerySales(options, paging); return(Load(sales.ToList())); }
public decimal Sum(Filters.SaleFilterOptions options) { return(QuerySales(options).Sum(s => (decimal?)s.Value) ?? 0); }
public int Total(Filters.SaleFilterOptions options) { return(QuerySales(options).Count()); }