private List <Lot> SelectLots(SortBy sortBy, List <Lot> Lots) { var lots = Lots.Where(i => i.IsAvailable && i.EndAt > DateTime.UtcNow); lots = sortBy switch { SortBy.Date => lots.OrderBy(i => i.EndAt), SortBy.DistinctDate => lots.OrderByDescending(i => i.EndAt), SortBy.Name => lots.OrderBy(i => i.Title), SortBy.DistinctName => lots.OrderByDescending(i => i.Title), SortBy.Goal => lots.OrderBy(i => i.MinPrice), SortBy.Funded => lots.OrderBy(i => i.Rates.OrderByDescending(c => c.CreatedAt).FirstOrDefault().Amount), _ => lots }; return(lots.ToList()); }
/// <summary> /// Fetch a list of items from synology for the specified page. /// Fetch related metadata for those items from the database. /// </summary> /// <param name="path"></param> /// <param name="page"></param> /// <param name="quantity"></param> /// <param name="sortBy"></param> /// <param name="sortDirection"></param> /// <param name="fileType"></param> /// <param name="onlyWritable"></param> /// <param name="additional"></param> /// <returns></returns> public async Task <PageModel <ItemModel> > ListAsync(string path, int page = 1, int quantity = 0, SortBy sortBy = SortBy.Name, SortDirection sortDirection = SortDirection.Ascending, string fileType = "all", bool onlyWritable = false, string[] additional = null) { if (page < 1) { throw new ArgumentException("Argument must be greater than 0", nameof(page)); } if (quantity < 0) { throw new ArgumentException("Argument must be greater than or equal to 0.", nameof(quantity)); } if (quantity == 0) { page = 1; } // Fetch items from synology. var sitems = await _fileStation.ListAsync(path ?? "/", page - 1, quantity, sortBy, sortDirection, fileType, onlyWritable, additional); // Fetch item metadata from database. var query = (from p in _context.Items.AsNoTracking() join i in _context.Items on p.Id equals i.ParentId where p.Path == path select i); query = sortBy switch { SortBy.Name => sortDirection == SortDirection.Ascending ? query.OrderBy(i => i.Name) : query.OrderByDescending(i => i.Name), SortBy.Created => sortDirection == SortDirection.Ascending ? query.OrderBy(i => i.CreatedOn) : query.OrderByDescending(i => i.CreatedOn), SortBy.Modified => sortDirection == SortDirection.Ascending ? query.OrderBy(i => i.UpdatedOn) : query.OrderByDescending(i => i.UpdatedOn), _ => query.OrderByDescending(i => i.CreatedOn) }; if (page > 1 && quantity > 0) { query = query.Skip((page - 1) & quantity).Take(quantity); } var items = query.ToArray(); // Convert to models based on whether we have metadata or not. var result = sitems.Data.Files.Select(si => { var item = items.FirstOrDefault(i => i.Path == si.Path); return(item == null ? new ItemModel(si) : new ItemModel(item)); }).OrderBy(i => i.SortOrder).OrderByDescending(i => i.PublishedOn).ThenByDescending(i => i.CreatedOn).ThenBy(i => i.Name); return(new PageModel <ItemModel>(page, sitems.Data.Total, result)); } #endregion }
private IQueryable <Lot> Order(SortBy sortBy, Expression <Func <Lot, bool> > expression = null) { var query = Context.Lots.Include(x => x.Rates).AsNoTracking().AsQueryable(); if (expression != null) { query = query.Where(expression); } query = sortBy switch { SortBy.Date => query.OrderBy(i => i.EndAt), SortBy.DistinctDate => query.OrderByDescending(i => i.EndAt), SortBy.Name => query.OrderBy(i => i.Title), SortBy.DistinctName => query.OrderByDescending(i => i.Title), SortBy.Goal => query.OrderBy(i => i.MinPrice), SortBy.Funded => query.OrderBy(i => i.Rates.OrderByDescending(c => c.CreatedAt) .FirstOrDefault().Amount), _ => query }; return(query); }
public IQueryable <ComplaintAction> SearchComplaintActions( SortBy sort = SortBy.ActionDateDesc, DateTime?ActionDateFrom = null, DateTime?ActionDateTo = null, Guid?ActionType = null, string Investigator = null, DateTime?DateEnteredFrom = null, DateTime?DateEnteredTo = null, string EnteredBy = null, string Comments = null, SearchDeleteStatus?deleteStatus = null ) { var complaintActions = _context.ComplaintActions.AsNoTracking(); // Filters if (deleteStatus.HasValue) { if (deleteStatus.Value == SearchDeleteStatus.Deleted) { complaintActions = complaintActions.Where(e => e.Deleted); } // Do not filter if deleteStatus.Value == SearchDeleteStatus.All } else { complaintActions = complaintActions.Where(e => !e.Deleted); } if (ActionDateFrom.HasValue) { complaintActions = complaintActions.Where(e => ActionDateFrom.Value <= e.ActionDate); } if (ActionDateTo.HasValue) { complaintActions = complaintActions.Where(e => e.ActionDate.Date <= ActionDateTo.Value); } if (ActionType.HasValue) { complaintActions = complaintActions.Where(e => e.ActionType.Id == ActionType.Value); } if (!string.IsNullOrEmpty(Investigator)) { complaintActions = complaintActions.Where(e => e.Investigator.ToLower().Contains(Investigator.ToLower())); } if (DateEnteredFrom.HasValue) { complaintActions = complaintActions.Where(e => DateEnteredFrom.Value <= e.DateEntered); } if (DateEnteredTo.HasValue) { complaintActions = complaintActions.Where(e => e.DateEntered <= DateEnteredTo.Value); } if (!string.IsNullOrEmpty(EnteredBy)) { complaintActions = complaintActions.Where(e => e.EnteredById == EnteredBy); } if (!string.IsNullOrEmpty(Comments)) { complaintActions = complaintActions.Where(e => e.Comments.ToLower().Contains(Comments.ToLower())); } // Sort complaintActions = sort switch { SortBy.ActionDateAsc => complaintActions.OrderBy(e => e.ActionDate).ThenBy(e => e.ComplaintId), SortBy.ActionTypeAsc => complaintActions.OrderBy(e => e.ActionType.Name).ThenBy(e => e.ComplaintId), SortBy.ActionTypeDesc => complaintActions.OrderByDescending(e => e.ActionType.Name).ThenBy(e => e.ComplaintId), SortBy.ComplaintIdAsc => complaintActions.OrderBy(e => e.ComplaintId), SortBy.ComplaintIdDesc => complaintActions.OrderByDescending(e => e.ComplaintId), _ => complaintActions.OrderByDescending(e => e.ActionDate).ThenBy(e => e.ComplaintId), }; return(complaintActions .Include(e => e.ActionType) .Include(e => e.EnteredBy)); }
public IQueryable <Complaint> SearchComplaints( SortBy sort = SortBy.IdDesc, SearchComplaintStatus?complaintStatus = null, SearchDeleteStatus?deleteStatus = null, DateTime?DateReceivedFrom = null, DateTime?DateReceivedTo = null, string ReceivedById = null, DateTime?DateComplaintClosedFrom = null, DateTime?DateComplaintClosedTo = null, string CallerName = null, string CallerRepresents = null, string ComplaintNature = null, string ComplaintLocation = null, string ComplaintDirections = null, string ComplaintCity = null, int?ComplaintCountyId = null, Guid?ConcernId = null, string SourceFacilityId = null, string SourceFacilityName = null, string SourceContactName = null, string SourceStreet = null, string SourceCity = null, int?SourceStateId = null, string SourcePostalCode = null, Guid?Office = null, string Owner = null ) { var complaints = _context.Complaints.AsNoTracking(); // Filters if (complaintStatus.HasValue) { switch (complaintStatus.Value) { case SearchComplaintStatus.Closed: complaints = complaints.Where(e => e.Status == ComplaintStatus.Closed); break; case SearchComplaintStatus.New: complaints = complaints.Where(e => e.Status == ComplaintStatus.New); break; case SearchComplaintStatus.ReviewPending: complaints = complaints.Where(e => e.Status == ComplaintStatus.ReviewPending); break; case SearchComplaintStatus.UnderInvestigation: complaints = complaints.Where(e => e.Status == ComplaintStatus.UnderInvestigation); break; case SearchComplaintStatus.Open: complaints = complaints.Where(e => e.Status != ComplaintStatus.Closed); break; } } if (deleteStatus.HasValue) { if (deleteStatus.Value == SearchDeleteStatus.Deleted) { complaints = complaints.Where(e => e.Deleted); } // Do not filter if deleteStatus.Value == SearchDeleteStatus.All } else { complaints = complaints .Where(e => !e.Deleted); } if (DateReceivedFrom.HasValue) { complaints = complaints.Where(e => DateReceivedFrom.Value <= e.DateReceived); } if (DateReceivedTo.HasValue) { complaints = complaints.Where(e => e.DateReceived.Date <= DateReceivedTo.Value); } if (!string.IsNullOrEmpty(ReceivedById)) { complaints = complaints.Where(e => e.ReceivedById == ReceivedById); } if (DateComplaintClosedFrom.HasValue) { complaints = complaints.Where(e => e.DateComplaintClosed.HasValue && DateComplaintClosedFrom.Value <= e.DateComplaintClosed.Value); } if (DateComplaintClosedTo.HasValue) { complaints = complaints.Where(e => e.DateComplaintClosed.HasValue && e.DateComplaintClosed.Value.Date <= DateComplaintClosedTo.Value); } if (!string.IsNullOrEmpty(CallerName)) { complaints = complaints.Where(e => e.CallerName.ToLower().Contains(CallerName.ToLower())); } if (!string.IsNullOrEmpty(CallerRepresents)) { complaints = complaints.Where(e => e.CallerRepresents.ToLower().Contains(CallerRepresents.ToLower())); } if (!string.IsNullOrEmpty(ComplaintNature)) { complaints = complaints.Where(e => e.ComplaintNature.ToLower().Contains(ComplaintNature.ToLower())); } if (!string.IsNullOrEmpty(ComplaintLocation)) { complaints = complaints.Where(e => e.ComplaintLocation.ToLower().Contains(ComplaintLocation.ToLower())); } if (!string.IsNullOrEmpty(ComplaintDirections)) { complaints = complaints.Where(e => e.ComplaintDirections.ToLower().Contains(ComplaintDirections.ToLower())); } if (!string.IsNullOrEmpty(ComplaintCity)) { complaints = complaints.Where(e => e.ComplaintCity.ToLower().Contains(ComplaintCity.ToLower())); } if (ComplaintCountyId.HasValue) { complaints = complaints.Where(e => e.ComplaintCountyId.HasValue && e.ComplaintCountyId.Value == ComplaintCountyId.Value); } if (ConcernId.HasValue) { complaints = complaints .Where(e => (e.PrimaryConcernId.HasValue && e.PrimaryConcernId.Value == ConcernId.Value) || (e.SecondaryConcernId.HasValue && e.SecondaryConcernId.Value == ConcernId.Value)); } if (!string.IsNullOrEmpty(SourceFacilityId)) { complaints = complaints.Where(e => e.SourceFacilityId.ToLower().Contains(SourceFacilityId.ToLower())); } if (!string.IsNullOrEmpty(SourceFacilityName)) { complaints = complaints.Where(e => e.SourceFacilityName.ToLower().Contains(SourceFacilityName.ToLower())); } if (!string.IsNullOrEmpty(SourceContactName)) { complaints = complaints.Where(e => e.SourceContactName.ToLower().Contains(SourceContactName.ToLower())); } if (!string.IsNullOrEmpty(SourceStreet)) { complaints = complaints .Where(e => e.SourceStreet.ToLower().Contains(SourceStreet.ToLower()) || e.SourceStreet2.ToLower().Contains(SourceStreet.ToLower())); } if (!string.IsNullOrEmpty(SourceCity)) { complaints = complaints.Where(e => e.SourceCity.ToLower().Contains(SourceCity.ToLower())); } if (SourceStateId.HasValue) { complaints = complaints.Where(e => e.SourceStateId.HasValue && e.SourceStateId.Value == SourceStateId.Value); } if (!string.IsNullOrEmpty(SourcePostalCode)) { complaints = complaints.Where(e => e.SourcePostalCode.ToLower().Contains(SourcePostalCode.ToLower())); } if (Office.HasValue) { complaints = complaints.Where(e => e.CurrentOfficeId == Office.Value); } if (!string.IsNullOrEmpty(Owner)) { complaints = complaints.Where(e => e.CurrentOwnerId == Owner); } // Sort complaints = sort switch { SortBy.IdAsc => complaints.OrderBy(e => e.Id), SortBy.ReceivedDateAsc => complaints.OrderBy(e => e.DateReceived).ThenBy(e => e.Id), SortBy.ReceivedDateDesc => complaints.OrderByDescending(e => e.DateReceived).ThenBy(e => e.Id), SortBy.StatusAsc => complaints.OrderBy(e => (int)e.Status).ThenBy(e => e.Id), SortBy.StatusDesc => complaints.OrderByDescending(e => (int)e.Status).ThenBy(e => e.Id), _ => complaints.OrderByDescending(e => e.Id), }; return(complaints .Include(e => e.CurrentOffice) .Include(e => e.CurrentOwner) .Include(e => e.ReceivedBy) .Include(e => e.SourceState)); }