From 603c35397597dd709a67866019c4874c5b037437 Mon Sep 17 00:00:00 2001 From: Mahmoud Alaskalany Date: Sun, 3 Nov 2024 10:08:46 +0400 Subject: [PATCH] add bulk delete to all controllers --- .../V1/Identity/PermissionsController.cs | 12 +++++++- .../V1/Identity/UsersController.cs | 9 ++++++ .../V1/Lookup/CategoriesController.cs | 13 +++++++-- .../V1/Lookup/StatusesController.cs | 11 +++++++- Template.Api/Template.Api.xml | 28 +++++++++++++++++++ .../Identity/Permission/IPermissionService.cs | 3 ++ .../Identity/Permission/PermissionService.cs | 10 +++++++ .../Services/Identity/User/IUserService.cs | 3 ++ .../Services/Identity/User/UserService.cs | 10 +++++++ .../Lookups/Category/CategoryService.cs | 10 +++++++ .../Lookups/Category/ICategoryService.cs | 5 +++- .../Services/Lookups/Status/IStatusService.cs | 3 ++ .../Services/Lookups/Status/StatusService.cs | 10 +++++++ 13 files changed, 122 insertions(+), 5 deletions(-) diff --git a/Template.Api/Controllers/V1/Identity/PermissionsController.cs b/Template.Api/Controllers/V1/Identity/PermissionsController.cs index dc07c72..01e4e67 100644 --- a/Template.Api/Controllers/V1/Identity/PermissionsController.cs +++ b/Template.Api/Controllers/V1/Identity/PermissionsController.cs @@ -1,4 +1,6 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System; +using System.Threading.Tasks; using Asp.Versioning; using Microsoft.AspNetCore.Mvc; using Template.Api.Controllers.V1.Base; @@ -103,6 +105,14 @@ public PermissionsController(IPermissionService permissionService) [HttpDelete("deleteSoft{id}")] public async Task DeleteSoftAsync(long id) => await _service.DeleteSoftAsync(id); + /// + /// Bulk Remove by ids + /// + /// PK + /// + [HttpDelete("deleteRange")] + public async Task DeleteRangeAsync(List ids) => await _service.DeleteRangeAsync(ids); + } diff --git a/Template.Api/Controllers/V1/Identity/UsersController.cs b/Template.Api/Controllers/V1/Identity/UsersController.cs index a339103..d7ac076 100644 --- a/Template.Api/Controllers/V1/Identity/UsersController.cs +++ b/Template.Api/Controllers/V1/Identity/UsersController.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using Asp.Versioning; using Microsoft.AspNetCore.Mvc; @@ -103,6 +104,14 @@ public UsersController(IUserService userService) [HttpDelete("deleteSoft/{id}")] public async Task DeleteSoftAsync(Guid id) => await _service.DeleteSoftAsync(id); + /// + /// Bulk Remove by ids + /// + /// PK + /// + [HttpDelete("deleteRange")] + public async Task DeleteRangeAsync(List ids) => await _service.DeleteRangeAsync(ids); + } diff --git a/Template.Api/Controllers/V1/Lookup/CategoriesController.cs b/Template.Api/Controllers/V1/Lookup/CategoriesController.cs index 726299e..445b3c1 100644 --- a/Template.Api/Controllers/V1/Lookup/CategoriesController.cs +++ b/Template.Api/Controllers/V1/Lookup/CategoriesController.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System.Threading.Tasks; using Asp.Versioning; using Microsoft.AspNetCore.Mvc; using Template.Api.Controllers.V1.Base; @@ -102,6 +103,14 @@ public CategoriesController(ICategoryService categoryService) /// [HttpDelete("deleteSoft/{id}")] public async Task DeleteSoftAsync(int id) => await _categoryService.DeleteSoftAsync(id); - + + /// + /// Bulk Remove by ids + /// + /// PK + /// + [HttpDelete("deleteRange")] + public async Task DeleteRangeAsync(List ids) => await _categoryService.DeleteRangeAsync(ids); + } } diff --git a/Template.Api/Controllers/V1/Lookup/StatusesController.cs b/Template.Api/Controllers/V1/Lookup/StatusesController.cs index 78f8d34..893494d 100644 --- a/Template.Api/Controllers/V1/Lookup/StatusesController.cs +++ b/Template.Api/Controllers/V1/Lookup/StatusesController.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System.Threading.Tasks; using Asp.Versioning; using Microsoft.AspNetCore.Mvc; using Template.Api.Controllers.V1.Base; @@ -101,5 +102,13 @@ public StatusesController(IStatusService statusService) /// [HttpDelete("deleteSoft/{id}")] public async Task DeleteSoftAsync(int id) => await _statusService.DeleteSoftAsync(id); + + /// + /// Bulk Remove by ids + /// + /// PK + /// + [HttpDelete("deleteRange")] + public async Task DeleteRangeAsync(List ids) => await _statusService.DeleteRangeAsync(ids); } } diff --git a/Template.Api/Template.Api.xml b/Template.Api/Template.Api.xml index 3d48e9d..08f60d0 100644 --- a/Template.Api/Template.Api.xml +++ b/Template.Api/Template.Api.xml @@ -159,6 +159,13 @@ PK + + + Bulk Remove by ids + + PK + + Users Controller @@ -229,6 +236,13 @@ PK + + + Bulk Remove by ids + + PK + + Actions Controller @@ -376,6 +390,13 @@ PK + + + Bulk Remove by ids + + PK + + Statuses Controller @@ -446,6 +467,13 @@ PK + + + Bulk Remove by ids + + PK + + diff --git a/Template.Application/Services/Identity/Permission/IPermissionService.cs b/Template.Application/Services/Identity/Permission/IPermissionService.cs index c6e9549..622d742 100644 --- a/Template.Application/Services/Identity/Permission/IPermissionService.cs +++ b/Template.Application/Services/Identity/Permission/IPermissionService.cs @@ -4,6 +4,7 @@ using Template.Common.DTO.Identity.Permission; using Template.Common.DTO.Identity.Permission.Parameters; using Template.Application.Services.Base; +using System.Collections.Generic; namespace Template.Application.Services.Identity.Permission { @@ -12,5 +13,7 @@ public interface IPermissionService : IBaseService GetAllPagedAsync(BaseParam filter); Task GetDropDownAsync(BaseParam filter); + + Task DeleteRangeAsync(List ids); } } \ No newline at end of file diff --git a/Template.Application/Services/Identity/Permission/PermissionService.cs b/Template.Application/Services/Identity/Permission/PermissionService.cs index 54c6b51..e0b3eca 100644 --- a/Template.Application/Services/Identity/Permission/PermissionService.cs +++ b/Template.Application/Services/Identity/Permission/PermissionService.cs @@ -53,6 +53,16 @@ public async Task GetDropDownAsync(BaseParam f } + public async Task DeleteRangeAsync(List ids) + { + var rows = await UnitOfWork.Repository.RemoveBulkAsync(x => ids.Contains(x.Id)); + if (rows > 0) + { + return new ResponseResult().PostResult(result: true, status: HttpStatusCode.OK, message: MessagesConstants.DeleteSuccess); + } + return new ResponseResult().PostResult(result: false, status: HttpStatusCode.BadRequest, message: MessagesConstants.DeleteError); + } + static Expression> PredicateBuilderFunction(PermissionFilter filter) { var predicate = PredicateBuilder.New(x => x.IsDeleted == filter.IsDeleted); diff --git a/Template.Application/Services/Identity/User/IUserService.cs b/Template.Application/Services/Identity/User/IUserService.cs index 37c738c..12cae7b 100644 --- a/Template.Application/Services/Identity/User/IUserService.cs +++ b/Template.Application/Services/Identity/User/IUserService.cs @@ -5,6 +5,7 @@ using Template.Common.DTO.Identity.User; using Template.Common.DTO.Identity.User.Parameters; using Template.Application.Services.Base; +using System.Collections.Generic; namespace Template.Application.Services.Identity.User { @@ -13,5 +14,7 @@ public interface IUserService : IBaseService GetAllPagedAsync(BaseParam filter); Task GetDropDownAsync(BaseParam filter); + + Task DeleteRangeAsync(List ids); } } \ No newline at end of file diff --git a/Template.Application/Services/Identity/User/UserService.cs b/Template.Application/Services/Identity/User/UserService.cs index 35cb66d..122866e 100644 --- a/Template.Application/Services/Identity/User/UserService.cs +++ b/Template.Application/Services/Identity/User/UserService.cs @@ -53,6 +53,16 @@ public async Task GetDropDownAsync(BaseParam f } + public async Task DeleteRangeAsync(List ids) + { + var rows = await UnitOfWork.Repository.RemoveBulkAsync(x => ids.Contains(x.Id)); + if (rows > 0) + { + return new ResponseResult().PostResult(result: true, status: HttpStatusCode.OK, message: MessagesConstants.DeleteSuccess); + } + return new ResponseResult().PostResult(result: false, status: HttpStatusCode.BadRequest, message: MessagesConstants.DeleteError); + } + static Expression> PredicateBuilderFunction(UserFilter filter) { var predicate = PredicateBuilder.New(x => x.IsDeleted == filter.IsDeleted); diff --git a/Template.Application/Services/Lookups/Category/CategoryService.cs b/Template.Application/Services/Lookups/Category/CategoryService.cs index 7e99762..54b0ef9 100644 --- a/Template.Application/Services/Lookups/Category/CategoryService.cs +++ b/Template.Application/Services/Lookups/Category/CategoryService.cs @@ -53,6 +53,16 @@ public async Task GetDropDownAsync(BaseParam f } + public async Task DeleteRangeAsync(List ids) + { + var rows = await UnitOfWork.Repository.RemoveBulkAsync(x => ids.Contains(x.Id)); + if (rows > 0) + { + return new ResponseResult().PostResult(result: true, status: HttpStatusCode.OK, message: MessagesConstants.DeleteSuccess); + } + return new ResponseResult().PostResult(result: false, status: HttpStatusCode.BadRequest, message: MessagesConstants.DeleteError); + } + static Expression> PredicateBuilderFunction(CategoryFilter filter) { var predicate = PredicateBuilder.New(x => x.IsDeleted == filter.IsDeleted); diff --git a/Template.Application/Services/Lookups/Category/ICategoryService.cs b/Template.Application/Services/Lookups/Category/ICategoryService.cs index 26d54e7..f5e5b10 100644 --- a/Template.Application/Services/Lookups/Category/ICategoryService.cs +++ b/Template.Application/Services/Lookups/Category/ICategoryService.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System.Threading.Tasks; using Template.Application.Services.Base; using Template.Common.Core; using Template.Common.DTO.Base; @@ -12,5 +13,7 @@ public interface ICategoryService : IBaseService GetAllPagedAsync(BaseParam filter); Task GetDropDownAsync(BaseParam filter); + + Task DeleteRangeAsync(List ids); } } diff --git a/Template.Application/Services/Lookups/Status/IStatusService.cs b/Template.Application/Services/Lookups/Status/IStatusService.cs index db82174..749b05a 100644 --- a/Template.Application/Services/Lookups/Status/IStatusService.cs +++ b/Template.Application/Services/Lookups/Status/IStatusService.cs @@ -4,6 +4,7 @@ using Template.Application.Services.Base; using Template.Common.DTO.Base; using Template.Common.DTO.Lookup.Status.Parameters; +using System.Collections.Generic; namespace Template.Application.Services.Lookups.Status { @@ -12,5 +13,7 @@ public interface IStatusService : IBaseService GetAllPagedAsync(BaseParam filter); Task GetDropDownAsync(BaseParam filter); + + Task DeleteRangeAsync(List ids); } } diff --git a/Template.Application/Services/Lookups/Status/StatusService.cs b/Template.Application/Services/Lookups/Status/StatusService.cs index 6c5f638..fe4134f 100644 --- a/Template.Application/Services/Lookups/Status/StatusService.cs +++ b/Template.Application/Services/Lookups/Status/StatusService.cs @@ -53,6 +53,16 @@ public async Task GetDropDownAsync(BaseParam f } + public async Task DeleteRangeAsync(List ids) + { + var rows = await UnitOfWork.Repository.RemoveBulkAsync(x => ids.Contains(x.Id)); + if (rows > 0) + { + return new ResponseResult().PostResult(result: true, status: HttpStatusCode.OK, message: MessagesConstants.DeleteSuccess); + } + return new ResponseResult().PostResult(result: false, status: HttpStatusCode.BadRequest, message: MessagesConstants.DeleteError); + } + static Expression> PredicateBuilderFunction(StatusFilter filter) { var predicate = PredicateBuilder.New(x => x.IsDeleted == filter.IsDeleted);