Added GetList & GetCount methods and cancellationtoken params to PageRepository

pull/6996/head
Ahmet 5 years ago
parent bf81197f50
commit fca49d7948

@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
@ -6,10 +8,19 @@ namespace Volo.CmsKit.Pages
{
public interface IPageRepository : IBasicRepository<Page, Guid>
{
Task<Page> GetByUrlAsync(string url);
Task<int> GetCountAsync(string filter = null, CancellationToken cancellationToken = default);
Task<Page> FindByUrlAsync(string url);
Task<List<Page>> GetListAsync(
string filter = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
string sorting = null,
CancellationToken cancellationToken = default);
Task<Page> GetByUrlAsync(string url, CancellationToken cancellationToken = default);
Task<bool> DoesExistAsync(string url);
Task<Page> FindByUrlAsync(string url, CancellationToken cancellationToken = default);
Task<bool> DoesExistAsync(string url, CancellationToken cancellationToken = default);
}
}

@ -1,4 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
@ -13,19 +17,44 @@ namespace Volo.CmsKit.Pages
{
}
public Task<Page> GetByUrlAsync(string url)
public virtual Task<int> GetCountAsync(string filter = null, CancellationToken cancellationToken = default)
{
return GetAsync(x => x.Url == url);
return DbSet.WhereIf(
!filter.IsNullOrWhiteSpace(),
x =>
x.Title.Contains(filter)
).CountAsync(GetCancellationToken(cancellationToken));
}
public Task<Page> FindByUrlAsync(string url)
public virtual Task<List<Page>> GetListAsync(
string filter = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
string sorting = null,
CancellationToken cancellationToken = default)
{
return FindAsync(x => x.Url == url);
return DbSet.WhereIf(
!filter.IsNullOrWhiteSpace(),
x =>
x.Title.Contains(filter))
.OrderBy(sorting ?? nameof(Page.Title))
.PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public Task<bool> DoesExistAsync(string url)
public virtual Task<Page> GetByUrlAsync(string url, CancellationToken cancellationToken = default)
{
return DbSet.AnyAsync(x => x.Url == url);
return GetAsync(x => x.Url == url, cancellationToken: GetCancellationToken(cancellationToken));
}
public virtual Task<Page> FindByUrlAsync(string url, CancellationToken cancellationToken = default)
{
return FindAsync(x => x.Url == url, cancellationToken: GetCancellationToken(cancellationToken));
}
public virtual Task<bool> DoesExistAsync(string url, CancellationToken cancellationToken = default)
{
return DbSet.AnyAsync(x => x.Url == url, GetCancellationToken(cancellationToken));
}
}
}

@ -1,5 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading;
using System.Threading.Tasks;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB;
@ -13,19 +18,48 @@ namespace Volo.CmsKit.MongoDB.Pages
{
}
public Task<Page> GetByUrlAsync(string url)
public virtual Task<int> GetCountAsync(string filter = null, CancellationToken cancellationToken = default)
{
return GetAsync(x => x.Url == url);
return GetMongoQueryable()
.WhereIf<Page, IMongoQueryable<Page>>(
!filter.IsNullOrWhiteSpace(),
u =>
u.Title.Contains(filter)
).CountAsync(GetCancellationToken(cancellationToken));
}
public Task<Page> FindByUrlAsync(string url)
public virtual Task<List<Page>> GetListAsync(
string filter = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
string sorting = null,
CancellationToken cancellationToken = default)
{
return FindAsync(x => x.Url == url);
return GetMongoQueryable()
.WhereIf<Page, IMongoQueryable<Page>>(
!filter.IsNullOrWhiteSpace(),
u =>
u.Title.Contains(filter)
)
.OrderBy(sorting ?? nameof(Page.Title))
.As<IMongoQueryable<Page>>()
.PageBy<Page, IMongoQueryable<Page>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual Task<Page> GetByUrlAsync(string url, CancellationToken cancellationToken = default)
{
return GetAsync(x => x.Url == url, cancellationToken: GetCancellationToken(cancellationToken));
}
public virtual Task<Page> FindByUrlAsync(string url, CancellationToken cancellationToken = default)
{
return FindAsync(x => x.Url == url, cancellationToken: GetCancellationToken(cancellationToken));
}
public Task<bool> DoesExistAsync(string url)
public virtual Task<bool> DoesExistAsync(string url, CancellationToken cancellationToken = default)
{
return GetMongoQueryable().AnyAsync(x => x.Url == url);
return GetMongoQueryable().AnyAsync(x => x.Url == url, GetCancellationToken(cancellationToken));
}
}
}
Loading…
Cancel
Save