Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check & move related blog posts on deletion #21348

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public class BlogDto : ExtensibleEntityDto<Guid>, IHasConcurrencyStamp

public string Slug { get; set; }
public string ConcurrencyStamp { get; set; }

public int BlogPostCount { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;

namespace Volo.CmsKit.Admin.Blogs;

public interface IBlogAdminAppService : ICrudAppService<BlogDto, Guid, BlogGetListInput, CreateBlogDto, UpdateBlogDto>
{
Task<ListResultDto<BlogDto>> GetAllListAsync();

Task MoveAllBlogPostsAsync(Guid blogId, Guid? assignToBlogId = null);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Application.Dtos;
Expand All @@ -20,37 +21,64 @@ namespace Volo.CmsKit.Admin.Blogs;
public class BlogAdminAppService : CmsKitAdminAppServiceBase, IBlogAdminAppService
{
protected IBlogRepository BlogRepository { get; }
protected IBlogPostRepository BlogPostRepository { get; }
protected BlogManager BlogManager { get; }
protected BlogFeatureManager BlogFeatureManager { get; }

public BlogAdminAppService(
IBlogRepository blogRepository,
BlogManager blogManager,
BlogManager blogManager,
IBlogPostRepository blogPostRepository,
BlogFeatureManager blogFeatureManager = null)
{
BlogRepository = blogRepository;
BlogManager = blogManager;
BlogPostRepository = blogPostRepository;
BlogFeatureManager = blogFeatureManager;
}

public virtual async Task<BlogDto> GetAsync(Guid id)
{
var blog = await BlogRepository.GetAsync(id);

return ObjectMapper.Map<Blog, BlogDto>(blog);
var blogDto = ObjectMapper.Map<Blog, BlogDto>(blog);
blogDto.BlogPostCount = await BlogPostRepository.GetCountAsync(blogId : blog.Id);

return blogDto;
}

public virtual async Task<PagedResultDto<BlogDto>> GetListAsync(BlogGetListInput input)
{
var totalCount = await BlogRepository.GetCountAsync(input.Filter);

var blogs = await BlogRepository.GetListAsync(
var blogs = await BlogRepository.GetListWithBlogPostCountAsync(
input.Filter,
input.Sorting,
input.MaxResultCount,
input.SkipCount);

var blogDtos = new PagedResultDto<BlogDto>(totalCount, ObjectMapper.Map<List<Blog>, List<BlogDto>>(blogs.Select(x => x.Blog).ToList()));

foreach (var blogDto in blogDtos.Items)
{
blogDto.BlogPostCount = blogs.First(x => x.Blog.Id == blogDto.Id).BlogPostCount;
}

return new PagedResultDto<BlogDto>(totalCount, ObjectMapper.Map<List<Blog>, List<BlogDto>>(blogs));
return blogDtos;
}

public virtual async Task<ListResultDto<BlogDto>> GetAllListAsync()
{
var blogs = await BlogRepository.GetListWithBlogPostCountAsync(maxResultCount: int.MaxValue);

var blogDtos = new ListResultDto<BlogDto>(ObjectMapper.Map<List<Blog>, List<BlogDto>>(blogs.Select(x => x.Blog).ToList()));

foreach (var blogDto in blogDtos.Items)
{
blogDto.BlogPostCount = blogs.First(x => x.Blog.Id == blogDto.Id).BlogPostCount;
}

return blogDtos;
}

[Authorize(CmsKitAdminPermissions.Blogs.Create)]
Expand Down Expand Up @@ -79,10 +107,18 @@ public virtual async Task<BlogDto> UpdateAsync(Guid id, UpdateBlogDto input)

return ObjectMapper.Map<Blog, BlogDto>(blog);
}

[Authorize(CmsKitAdminPermissions.Blogs.Delete)]
public virtual async Task MoveAllBlogPostsAsync(Guid blogId, Guid? assignToBlogId)
{
var blog = await BlogRepository.GetAsync(blogId);
await BlogPostRepository.UpdateBlogAsync(blog.Id, assignToBlogId);
}

[Authorize(CmsKitAdminPermissions.Blogs.Delete)]
public virtual Task DeleteAsync(Guid id)
{

return BlogRepository.DeleteAsync(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public CmsKitAdminApplicationAutoMapperProfile()
CreateMap<CreateBlogPostDto, BlogPost>(MemberList.Source).MapExtraProperties();
CreateMap<UpdateBlogPostDto, BlogPost>(MemberList.Source).MapExtraProperties();

CreateMap<Blog, BlogDto>().MapExtraProperties();
CreateMap<Blog, BlogDto>().Ignore(b => b.BlogPostCount).MapExtraProperties();

CreateMap<TagEntityTypeDefiniton, TagDefinitionDto>(MemberList.Destination);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,18 @@ public virtual async Task DeleteAsync(Guid id)
{ typeof(Guid), id }
});
}

public virtual async Task<ListResultDto<BlogDto>> GetAllListAsync()
{
return await RequestAsync<ListResultDto<BlogDto>>(nameof(GetAllListAsync));
}

public virtual async Task MoveAllBlogPostsAsync(Guid blogId, Guid? assignToBlogId)
{
await RequestAsync(nameof(MoveAllBlogPostsAsync), new ClientProxyRequestTypeValue
{
{ typeof(Guid), blogId },
{ typeof(Guid?), assignToBlogId }
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,39 @@
"type": "Volo.CmsKit.Admin.Blogs.IBlogAdminAppService",
"name": "IBlogAdminAppService",
"methods": [
{
"name": "GetAllListAsync",
"parametersOnMethod": [],
"returnValue": {
"type": "Volo.Abp.Application.Dtos.ListResultDto<Volo.CmsKit.Admin.Blogs.BlogDto>",
"typeSimple": "Volo.Abp.Application.Dtos.ListResultDto<Volo.CmsKit.Admin.Blogs.BlogDto>"
}
},
{
"name": "MoveAllBlogPostsAsync",
"parametersOnMethod": [
{
"name": "blogId",
"typeAsString": "System.Guid, System.Private.CoreLib",
"type": "System.Guid",
"typeSimple": "string",
"isOptional": false,
"defaultValue": null
},
{
"name": "assignToBlogId",
"typeAsString": "System.Nullable`1[[System.Guid, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib",
"type": "System.Guid?",
"typeSimple": "string?",
"isOptional": false,
"defaultValue": null
}
],
"returnValue": {
"type": "System.Void",
"typeSimple": "System.Void"
}
},
{
"name": "GetAsync",
"parametersOnMethod": [
Expand Down Expand Up @@ -353,6 +386,90 @@
},
"allowAnonymous": false,
"implementFrom": "Volo.Abp.Application.Services.IDeleteAppService<System.Guid>"
},
"GetAllListAsync": {
"uniqueName": "GetAllListAsync",
"name": "GetAllListAsync",
"httpMethod": "GET",
"url": "api/cms-kit-admin/blogs/all",
"supportedVersions": [],
"parametersOnMethod": [],
"parameters": [],
"returnValue": {
"type": "Volo.Abp.Application.Dtos.ListResultDto<Volo.CmsKit.Admin.Blogs.BlogDto>",
"typeSimple": "Volo.Abp.Application.Dtos.ListResultDto<Volo.CmsKit.Admin.Blogs.BlogDto>"
},
"allowAnonymous": false,
"implementFrom": "Volo.CmsKit.Admin.Blogs.IBlogAdminAppService"
},
"MoveAllBlogPostsAsyncByBlogIdAndAssignToBlogId": {
"uniqueName": "MoveAllBlogPostsAsyncByBlogIdAndAssignToBlogId",
"name": "MoveAllBlogPostsAsync",
"httpMethod": "PUT",
"url": "api/cms-kit-admin/blogs/{id}/move-all-blog-posts",
"supportedVersions": [],
"parametersOnMethod": [
{
"name": "blogId",
"typeAsString": "System.Guid, System.Private.CoreLib",
"type": "System.Guid",
"typeSimple": "string",
"isOptional": false,
"defaultValue": null
},
{
"name": "assignToBlogId",
"typeAsString": "System.Nullable`1[[System.Guid, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib",
"type": "System.Guid?",
"typeSimple": "string?",
"isOptional": false,
"defaultValue": null
}
],
"parameters": [
{
"nameOnMethod": "blogId",
"name": "blogId",
"jsonName": null,
"type": "System.Guid",
"typeSimple": "string",
"isOptional": false,
"defaultValue": null,
"constraintTypes": null,
"bindingSourceId": "ModelBinding",
"descriptorName": ""
},
{
"nameOnMethod": "assignToBlogId",
"name": "assignToBlogId",
"jsonName": null,
"type": "System.Guid?",
"typeSimple": "string?",
"isOptional": false,
"defaultValue": null,
"constraintTypes": null,
"bindingSourceId": "Query",
"descriptorName": ""
},
{
"nameOnMethod": "id",
"name": "id",
"jsonName": null,
"type": null,
"typeSimple": null,
"isOptional": false,
"defaultValue": null,
"constraintTypes": [],
"bindingSourceId": "Path",
"descriptorName": ""
}
],
"returnValue": {
"type": "System.Void",
"typeSimple": "System.Void"
},
"allowAnonymous": false,
"implementFrom": "Volo.CmsKit.Admin.Blogs.IBlogAdminAppService"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,19 @@ public Task DeleteAsync(Guid id)
{
return BlogAdminAppService.DeleteAsync(id);
}

[HttpGet]
[Route("all")]
public Task<ListResultDto<BlogDto>> GetAllListAsync()
{
return BlogAdminAppService.GetAllListAsync();
}

[HttpPut]
[Route("{id}/move-all-blog-posts")]
[Authorize(CmsKitAdminPermissions.Blogs.Delete)]
public Task MoveAllBlogPostsAsync(Guid blogId, [FromQuery]Guid? assignToBlogId)
{
return BlogAdminAppService.MoveAllBlogPostsAsync(blogId, assignToBlogId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
@page
@using Microsoft.AspNetCore.Mvc.Localization
@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal
@using Volo.CmsKit.Admin.Web.Pages.CmsKit.Blogs
@using Volo.CmsKit.Localization
@model DeleteBlogModal
@inject IHtmlLocalizer<CmsKitResource> L
@{
Layout = null;
}

<form method="post" asp-page="/CmsKit/Blogs/DeleteBlogModal" autocomplete="off">
@{
var deleteAllClicked = "checked";
var deleteButtonDisabled = "";
<abp-modal>
<abp-modal-header title="@L["AreYouSure"].Value"></abp-modal-header>
<abp-modal-body>

<abp-input asp-for="Blog.Id" type="hidden"></abp-input>

<p class="fw-bold">@L.GetString("BlogDeletionConfirmationMessage", Model.Blog.Name).Value</p>

@if (Model.Blog.BlogPostCount > 0)
{
<p class="mt-2">@L.GetString("ChooseAnActionForBlog", Model.Blog.BlogPostCount).Value</p>


if (Model.Blog.OtherBlogs.Any())
{
deleteAllClicked = "";
deleteButtonDisabled = "disabled";
<div class="form-check">
<input class="form-check-input" type="radio" checked name="assign" id="assign">
<label class="form-check-label" for="assign">@L["AssignBlogPostsToOtherBlog"].Value</label>
</div>
<select name="Blog.AssignToBlogId" id="Blog_AssignToBlogId" class="form-select mt-2">
<option value="" selected>@L["SelectAnBlogToAssign"].Value</option>
@foreach (var blog in Model.Blog.OtherBlogs)
{
<option value="@blog.Key">@blog.Value</option>
}
</select>
}

<div class="form-check mt-2">
<input class="form-check-input" type="radio" @deleteAllClicked name="assign" id="deleteAll">
<label class="form-check-label" for="deleteAll">@L["DeleteAllBlogPostsOfThisBlog"].Value</label>
</div>
}
</abp-modal-body>
<abp-modal-footer>
<button class="btn btn-outline-danger" data-bs-dismiss="modal" type="button">@L["Cancel"]</button>
<button class="btn btn-danger" @deleteButtonDisabled type="submit"><i class="fa fa-trash"></i> <span>@L["Delete"]</span></button>
</abp-modal-footer>
</abp-modal>
}

</form>
Loading
Loading