Browse Source

Update Blog repository

pull/7851/head
Ahmet 6 years ago
parent
commit
af25f90d82
  1. 6
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogManager.cs
  2. 2
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogRepository.cs
  3. 46
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogRepository.cs
  4. 56
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs

6
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogManager.cs

@ -1,8 +1,6 @@
using System; using System.Threading.Tasks;
using System.Threading.Tasks;
using JetBrains.Annotations; using JetBrains.Annotations;
using Volo.Abp.Domain.Services; using Volo.Abp.Domain.Services;
using Volo.Abp.MultiTenancy;
namespace Volo.CmsKit.Blogs namespace Volo.CmsKit.Blogs
{ {
@ -19,7 +17,7 @@ namespace Volo.CmsKit.Blogs
{ {
await CheckSlugAsync(slug); await CheckSlugAsync(slug);
return new Blog(GuidGenerator.Create(), name, slug, CurrentTenant.GetId()); return new Blog(GuidGenerator.Create(), name, slug, CurrentTenant.Id);
} }
public virtual async Task<Blog> UpdateAsync([NotNull] Blog blog, [NotNull] string name, [NotNull] string slug) public virtual async Task<Blog> UpdateAsync([NotNull] Blog blog, [NotNull] string name, [NotNull] string slug)

2
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogRepository.cs

@ -23,7 +23,7 @@ namespace Volo.CmsKit.Blogs
Task<Blog> GetBySlugAsync(string slug, CancellationToken cancellationToken = default); Task<Blog> GetBySlugAsync(string slug, CancellationToken cancellationToken = default);
Task<bool> ExistsAsync(Guid blogId, CancellationToken cancellationToken = default); Task<bool> ExistsAsync(Guid id, CancellationToken cancellationToken = default);
Task<bool> SlugExistsAsync(string slug, CancellationToken cancellationToken = default); Task<bool> SlugExistsAsync(string slug, CancellationToken cancellationToken = default);
} }

46
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogRepository.cs

@ -1,9 +1,11 @@
using Microsoft.EntityFrameworkCore; using System;
using System; using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates; using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations; using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
@ -17,15 +19,47 @@ namespace Volo.CmsKit.Blogs
{ {
} }
public virtual async Task<bool> ExistsAsync(Guid blogId, CancellationToken cancellationToken = default) public virtual async Task<bool> ExistsAsync(Guid id, CancellationToken cancellationToken = default)
{ {
return await (await GetQueryableAsync()).AnyAsync(x => x.Id == blogId, GetCancellationToken(cancellationToken)); return await (await GetQueryableAsync()).AnyAsync(x => x.Id == id, GetCancellationToken(cancellationToken));
} }
public virtual Task<Blog> GetBySlugAsync([NotNull]string slug, CancellationToken cancellationToken = default) public virtual async Task<bool> SlugExistsAsync(string slug, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync()).AnyAsync(x => x.Slug == slug, GetCancellationToken(cancellationToken));
}
public virtual async Task<List<Blog>> GetListAsync(
string filter = null,
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
CancellationToken cancellationToken = default)
{
var query = await GetListQueryAsync(filter);
return await query.OrderBy(sorting ?? "creationTime desc")
.PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default)
{
var query = await GetListQueryAsync(filter);
return await query.LongCountAsync(GetCancellationToken(cancellationToken));
}
public virtual Task<Blog> GetBySlugAsync([NotNull] string slug, CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(slug, nameof(slug)); Check.NotNullOrEmpty(slug, nameof(slug));
return GetAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken)); return GetAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken));
} }
protected virtual async Task<IQueryable<Blog>> GetListQueryAsync(string filter = null)
{
return (await GetDbSetAsync())
.WhereIf(!filter.IsNullOrWhiteSpace(), b => b.Name.Contains(filter));
}
} }
} }

56
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs

@ -1,8 +1,12 @@
using MongoDB.Driver.Core.Operations; using System;
using System; using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations; using JetBrains.Annotations;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB; using Volo.Abp.MongoDB;
@ -16,18 +20,54 @@ namespace Volo.CmsKit.MongoDB.Blogs
{ {
} }
public virtual async Task<bool> ExistsAsync(Guid blogId, CancellationToken cancellationToken = default) public virtual async Task<bool> ExistsAsync(Guid id, CancellationToken cancellationToken = default)
{ {
return await AsyncExecuter.AnyAsync( var token = GetCancellationToken(cancellationToken);
await GetQueryableAsync(), return await (await GetMongoQueryableAsync(token)).AnyAsync(x => x.Id == id, token);
x => x.Id == blogId,
cancellationToken);
} }
public virtual Task<Blog> GetBySlugAsync([NotNull]string slug, CancellationToken cancellationToken = default) public virtual async Task<bool> SlugExistsAsync(string slug, CancellationToken cancellationToken = default)
{
var token = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(token)).AnyAsync(x => x.Slug == slug, token);
}
public virtual async Task<List<Blog>> GetListAsync(
string filter = null,
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
CancellationToken cancellationToken = default)
{
var token = GetCancellationToken(cancellationToken);
var query = await GetListQueryAsync(filter, token);
return await query.OrderBy(sorting ?? "creationTime desc")
.As<IMongoQueryable<Blog>>()
.PageBy<Blog, IMongoQueryable<Blog>>(skipCount, maxResultCount)
.ToListAsync(token);
}
public virtual async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default)
{
var token = GetCancellationToken(cancellationToken);
var query = await GetListQueryAsync(filter, token);
return await query.As<IMongoQueryable<Blog>>().LongCountAsync(token);
}
public virtual Task<Blog> GetBySlugAsync([NotNull] string slug, CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(slug, nameof(slug)); Check.NotNullOrEmpty(slug, nameof(slug));
return GetAsync(x => x.Slug == slug, cancellationToken: cancellationToken); return GetAsync(x => x.Slug == slug, cancellationToken: cancellationToken);
} }
protected virtual async Task<IQueryable<Blog>> GetListQueryAsync(string filter = null, CancellationToken cancellationToken = default)
{
return (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)))
.WhereIf(!filter.IsNullOrWhiteSpace(), b => b.Name.Contains(filter));
}
} }
} }

Loading…
Cancel
Save