public core.PushNotificationSearchResult SearchNotifies(string userId, core.PushNotificationSearchCriteria criteria) { var query = _innerList.OrderByDescending(x => x.Created).Where(x => x.Creator == userId).AsQueryable(); if (criteria.Ids != null && criteria.Ids.Any()) { query = query.Where(x => criteria.Ids.Contains(x.Id)); } if (criteria.OnlyNew) { query = query.Where(x => x.IsNew); } if (criteria.StartDate != null) { query = query.Where(x => x.Created >= criteria.StartDate); } if (criteria.EndDate != null) { query = query.Where(x => x.Created <= criteria.EndDate); } if (criteria.OrderBy != null) { var parts = criteria.OrderBy.Split(':'); if (parts.Any()) { var fieldName = parts[0]; if (parts.Length > 1 && String.Equals(parts[1], "desc", StringComparison.InvariantCultureIgnoreCase)) { query = query.OrderByDescending(fieldName); } else { query = query.OrderBy(fieldName); } } } var retVal = new core.PushNotificationSearchResult { TotalCount = query.Count(), NewCount = query.Count(x => x.IsNew), NotifyEvents = query.Skip(criteria.Start).Take(criteria.Count).ToList() }; return(retVal); }
public core.PushNotificationSearchResult SearchNotifies(string userId, core.PushNotificationSearchCriteria criteria) { var query = _innerList.OrderByDescending(x => x.Created).Where(x => x.Creator == userId).AsQueryable(); if (criteria.Ids != null && criteria.Ids.Any()) { query = query.Where(x => criteria.Ids.Contains(x.Id)); } if (criteria.OnlyNew) { query = query.Where(x => x.IsNew); } if (criteria.StartDate != null) { query = query.Where(x => x.Created >= criteria.StartDate); } if (criteria.EndDate != null) { query = query.Where(x => x.Created <= criteria.EndDate); } if (criteria.OrderBy != null) { var parts = criteria.OrderBy.Split(':'); if (parts.Any()) { var fieldName = parts[0]; if (parts.Length > 1 && String.Equals(parts[1], "desc", StringComparison.InvariantCultureIgnoreCase)) { query = query.OrderByDescending(fieldName); } else { query = query.OrderBy(fieldName); } } } var retVal = new core.PushNotificationSearchResult { TotalCount = query.Count(), NewCount = query.Count(x => x.IsNew), NotifyEvents = query.Skip(criteria.Start).Take(criteria.Count).ToList() }; return retVal; }