public async Task <long> CountItemsAsync(string siteId, CountItemFilters itemFilters) { var getItem = new CountItems() { CountItemFilters = itemFilters, SiteId = siteId }; var key = JsonConvert.SerializeObject(getItem); var result = await _cacheRepository.UseCacheAsync <long?>(key, "ItemRepository.CountItems", siteId, async() => { var builder = Builders <Item> .Filter; var filter = builder.Eq(p => p.SiteId, siteId); if (!string.IsNullOrEmpty(itemFilters.ParentId)) { filter = filter & builder.Eq(p => p.ParentId, itemFilters.ParentId); } if (!string.IsNullOrEmpty(itemFilters.Module)) { filter = filter & builder.Eq(p => p.Module, itemFilters.Module); } else if (string.IsNullOrEmpty(itemFilters.ParentId)) { filter = filter & builder.Eq(p => p.ParentId, itemFilters.ParentId); } if (itemFilters.Tags != null && itemFilters.Tags.Count > 0) { filter = filter & builder.AnyIn("Tags", itemFilters.Tags.ToArray()); } if (!string.IsNullOrEmpty(itemFilters.PropertyName)) { filter = filter & builder.Eq(p => p.PropertyName, itemFilters.PropertyName); } if (itemFilters.IsTemporary.HasValue) { filter = filter & builder.Eq(p => p.IsTemporary, itemFilters.IsTemporary.Value); } if (itemFilters.States != null && itemFilters.States.Count > 0) { var builderState = builder.Exists(p => p.State, false); foreach (var itemFiltersState in itemFilters.States) { builderState = builderState | builder.Eq(p => p.State, itemFiltersState); } filter = filter & builderState; } if (itemFilters.IndexLte.HasValue) { filter = filter & builder.Lte(p => p.Index, itemFilters.IndexLte.Value); } if (itemFilters.IndexGte.HasValue) { filter = filter & builder.Gte(p => p.Index, itemFilters.IndexGte.Value); } if (itemFilters.IndexLt.HasValue) { filter = filter & builder.Lt(p => p.Index, itemFilters.IndexLt.Value); } if (itemFilters.IndexGt.HasValue) { filter = filter & builder.Gt(p => p.Index, itemFilters.IndexGt.Value); } var cursor = _collection.Find(filter); return(await cursor.CountAsync()); }); return(result.HasValue ? result.Value: 0); }
public Task <long> CountItemsAsync(string siteId, CountItemFilters itemFilters) { throw new NotImplementedException(); }