mirror of https://github.com/abpframework/abp.git
17 changed files with 224 additions and 1 deletions
@ -0,0 +1,11 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace Volo.CmsKit.Admin.Blogs |
|||
{ |
|||
public class BlogFeatureDto |
|||
{ |
|||
[Required] |
|||
public string FeatureName { get; set; } |
|||
public bool Enabled { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.CmsKit.Admin.Blogs |
|||
{ |
|||
public interface IBlogFeatureAdminAppService |
|||
{ |
|||
Task SetAsync(Guid blogId, BlogFeatureDto dto); |
|||
|
|||
Task<List<BlogFeatureDto>> GetListAsync(Guid blogId); |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.CmsKit.Admin.Blogs; |
|||
using Volo.CmsKit.Blogs; |
|||
using Volo.CmsKit.Permissions; |
|||
|
|||
namespace Volo.CmsKit.Admin.Blogs |
|||
{ |
|||
public class BlogFeatureAdminAppService : CmsKitAdminAppServiceBase, IBlogFeatureAdminAppService |
|||
{ |
|||
protected IBlogFeatureRepository BlogFeatureRepository { get; } |
|||
|
|||
public BlogFeatureAdminAppService(IBlogFeatureRepository blogFeatureRepository) |
|||
{ |
|||
BlogFeatureRepository = blogFeatureRepository; |
|||
} |
|||
|
|||
[Authorize(CmsKitAdminPermissions.Blogs.Features)] |
|||
public async Task<List<BlogFeatureDto>> GetListAsync(Guid blogId) |
|||
{ |
|||
var list = await BlogFeatureRepository.GetListAsync(blogId); |
|||
|
|||
return ObjectMapper.Map<List<BlogFeature>, List<BlogFeatureDto>>(list); |
|||
} |
|||
|
|||
[Authorize(CmsKitAdminPermissions.Blogs.Features)] |
|||
public async Task SetAsync(Guid blogId, BlogFeatureDto dto) |
|||
{ |
|||
var existing = await BlogFeatureRepository.FindAsync(blogId, dto.FeatureName); |
|||
if (existing == null) |
|||
{ |
|||
var blogFeature = new BlogFeature(blogId, dto.FeatureName, dto.Enabled); |
|||
await BlogFeatureRepository.InsertAsync(blogFeature); |
|||
} |
|||
else |
|||
{ |
|||
existing.Enabled = dto.Enabled; |
|||
await BlogFeatureRepository.UpdateAsync(existing); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public static class BlogFeatureConsts |
|||
{ |
|||
public const int MaxFeatureNameLenth = 64; |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Entities.Auditing; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public class BlogFeature : FullAuditedAggregateRoot<Guid> |
|||
{ |
|||
protected BlogFeature() // Keep for ORM
|
|||
{ |
|||
} |
|||
|
|||
public BlogFeature(Guid blogId, string featureName, bool enabled = true) |
|||
{ |
|||
BlogId = blogId; |
|||
FeatureName = featureName; |
|||
Enabled = enabled; |
|||
} |
|||
|
|||
public Guid BlogId { get; protected set; } |
|||
|
|||
public string FeatureName { get; protected set; } |
|||
|
|||
public bool Enabled { get; set; } = true; |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Data; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public class BlogFeatureDataSeeContributor : IDataSeedContributor |
|||
{ |
|||
public Task SeedAsync(DataSeedContext context) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public interface IBlogFeatureRepository : IBasicRepository<BlogFeature, Guid> |
|||
{ |
|||
Task<List<BlogFeature>> GetListAsync(Guid blogId); |
|||
|
|||
Task<BlogFeature> FindAsync(Guid blogId, string featureName); |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.CmsKit.EntityFrameworkCore; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public class EfCoreBlogFeatureRepository : EfCoreRepository<CmsKitDbContext, BlogFeature, Guid>, IBlogFeatureRepository |
|||
{ |
|||
public EfCoreBlogFeatureRepository(IDbContextProvider<CmsKitDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public Task<BlogFeature> FindAsync(Guid blogId, string featureName) |
|||
{ |
|||
return base.FindAsync(x => x.BlogId == blogId && x.FeatureName == featureName); |
|||
} |
|||
|
|||
public async Task<List<BlogFeature>> GetListAsync(Guid blogId) |
|||
{ |
|||
return await (await GetQueryableAsync()) |
|||
.Where(x => x.BlogId == blogId) |
|||
.ToListAsync(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using MongoDB.Driver.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories.MongoDB; |
|||
using Volo.Abp.MongoDB; |
|||
using Volo.CmsKit.Blogs; |
|||
using MongoDB.Driver; |
|||
|
|||
namespace Volo.CmsKit.MongoDB.Blogs |
|||
{ |
|||
public class MongoBlogFeatureRepository : MongoDbRepository<ICmsKitMongoDbContext, BlogFeature, Guid> , IBlogFeatureRepository |
|||
{ |
|||
public MongoBlogFeatureRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public Task<BlogFeature> FindAsync(Guid blogId, string featureName) |
|||
{ |
|||
return base.FindAsync(x => x.BlogId == blogId && x.FeatureName == featureName); |
|||
} |
|||
|
|||
public async Task<List<BlogFeature>> GetListAsync(Guid blogId) |
|||
{ |
|||
return await (await GetMongoQueryableAsync()) |
|||
.Where(x => x.BlogId == blogId) |
|||
.ToListAsync(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue