mirror of https://github.com/abpframework/abp.git
7 changed files with 146 additions and 18 deletions
@ -0,0 +1,46 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
|
using Volo.Abp.Domain.Services; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
|
||||
|
namespace Volo.CmsKit.Blogs |
||||
|
{ |
||||
|
public class BlogManager : DomainService |
||||
|
{ |
||||
|
protected IBlogRepository BlogRepository { get; } |
||||
|
|
||||
|
public BlogManager(IBlogRepository blogRepository) |
||||
|
{ |
||||
|
BlogRepository = blogRepository; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<Blog> CreateAsync([NotNull] string name, [NotNull] string slug) |
||||
|
{ |
||||
|
await CheckSlugAsync(slug); |
||||
|
|
||||
|
return new Blog(GuidGenerator.Create(), name, slug, CurrentTenant.GetId()); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<Blog> UpdateAsync([NotNull] Blog blog, [NotNull] string name, [NotNull] string slug) |
||||
|
{ |
||||
|
if (slug != blog.Slug) |
||||
|
{ |
||||
|
await CheckSlugAsync(slug); |
||||
|
} |
||||
|
|
||||
|
blog.SetName(name); |
||||
|
blog.SetSlug(slug); |
||||
|
|
||||
|
return blog; |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task CheckSlugAsync([NotNull] string slug) |
||||
|
{ |
||||
|
if (await BlogRepository.SlugExistsAsync(slug)) |
||||
|
{ |
||||
|
throw new BlogSlugAlreadyExistException(slug); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
using System; |
||||
|
using System.Runtime.Serialization; |
||||
|
using Volo.Abp; |
||||
|
|
||||
|
namespace Volo.CmsKit.Blogs |
||||
|
{ |
||||
|
[Serializable] |
||||
|
public class BlogSlugAlreadyExistException : BusinessException |
||||
|
{ |
||||
|
public BlogSlugAlreadyExistException(string slug) |
||||
|
{ |
||||
|
Code = CmsKitErrorCodes.Blogs.SlugAlreadyExist; |
||||
|
|
||||
|
WithData(nameof(Blog.Slug), slug); |
||||
|
} |
||||
|
|
||||
|
public BlogSlugAlreadyExistException( |
||||
|
SerializationInfo serializationInfo, StreamingContext context) : base(serializationInfo, context) |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue