Skip to content

Commit

Permalink
add bulk delete to all controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmoudalaskalany committed Nov 3, 2024
1 parent 6464085 commit 603c353
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 5 deletions.
12 changes: 11 additions & 1 deletion Template.Api/Controllers/V1/Identity/PermissionsController.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -103,6 +105,14 @@ public PermissionsController(IPermissionService permissionService)
[HttpDelete("deleteSoft{id}")]
public async Task<IFinalResult> DeleteSoftAsync(long id) => await _service.DeleteSoftAsync(id);

/// <summary>
/// Bulk Remove by ids
/// </summary>
/// <param name="ids">PK</param>
/// <returns></returns>
[HttpDelete("deleteRange")]
public async Task<IFinalResult> DeleteRangeAsync(List<int> ids) => await _service.DeleteRangeAsync(ids);



}
Expand Down
9 changes: 9 additions & 0 deletions Template.Api/Controllers/V1/Identity/UsersController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -103,6 +104,14 @@ public UsersController(IUserService userService)
[HttpDelete("deleteSoft/{id}")]
public async Task<IFinalResult> DeleteSoftAsync(Guid id) => await _service.DeleteSoftAsync(id);

/// <summary>
/// Bulk Remove by ids
/// </summary>
/// <param name="ids">PK</param>
/// <returns></returns>
[HttpDelete("deleteRange")]
public async Task<IFinalResult> DeleteRangeAsync(List<Guid> ids) => await _service.DeleteRangeAsync(ids);



}
Expand Down
13 changes: 11 additions & 2 deletions Template.Api/Controllers/V1/Lookup/CategoriesController.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -102,6 +103,14 @@ public CategoriesController(ICategoryService categoryService)
/// <returns></returns>
[HttpDelete("deleteSoft/{id}")]
public async Task<IFinalResult> DeleteSoftAsync(int id) => await _categoryService.DeleteSoftAsync(id);


/// <summary>
/// Bulk Remove by ids
/// </summary>
/// <param name="ids">PK</param>
/// <returns></returns>
[HttpDelete("deleteRange")]
public async Task<IFinalResult> DeleteRangeAsync(List<int> ids) => await _categoryService.DeleteRangeAsync(ids);

}
}
11 changes: 10 additions & 1 deletion Template.Api/Controllers/V1/Lookup/StatusesController.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -101,5 +102,13 @@ public StatusesController(IStatusService statusService)
/// <returns></returns>
[HttpDelete("deleteSoft/{id}")]
public async Task<IFinalResult> DeleteSoftAsync(int id) => await _statusService.DeleteSoftAsync(id);

/// <summary>
/// Bulk Remove by ids
/// </summary>
/// <param name="ids">PK</param>
/// <returns></returns>
[HttpDelete("deleteRange")]
public async Task<IFinalResult> DeleteRangeAsync(List<int> ids) => await _statusService.DeleteRangeAsync(ids);
}
}
28 changes: 28 additions & 0 deletions Template.Api/Template.Api.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -12,5 +13,7 @@ public interface IPermissionService : IBaseService<Domain.Entities.Identity.Perm
Task<DataPaging> GetAllPagedAsync(BaseParam<PermissionFilter> filter);

Task<DataPaging> GetDropDownAsync(BaseParam<SearchCriteriaFilter> filter);

Task<IFinalResult> DeleteRangeAsync(List<int> ids);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public async Task<DataPaging> GetDropDownAsync(BaseParam<SearchCriteriaFilter> f

}

public async Task<IFinalResult> DeleteRangeAsync(List<int> 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<Func<Domain.Entities.Identity.Permission, bool>> PredicateBuilderFunction(PermissionFilter filter)
{
var predicate = PredicateBuilder.New<Domain.Entities.Identity.Permission>(x => x.IsDeleted == filter.IsDeleted);
Expand Down
3 changes: 3 additions & 0 deletions Template.Application/Services/Identity/User/IUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -13,5 +14,7 @@ public interface IUserService : IBaseService<Domain.Entities.Identity.User, AddU
Task<DataPaging> GetAllPagedAsync(BaseParam<UserFilter> filter);

Task<DataPaging> GetDropDownAsync(BaseParam<SearchCriteriaFilter> filter);

Task<IFinalResult> DeleteRangeAsync(List<Guid> ids);
}
}
10 changes: 10 additions & 0 deletions Template.Application/Services/Identity/User/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public async Task<DataPaging> GetDropDownAsync(BaseParam<SearchCriteriaFilter> f

}

public async Task<IFinalResult> DeleteRangeAsync(List<Guid> 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<Func<Domain.Entities.Identity.User, bool>> PredicateBuilderFunction(UserFilter filter)
{
var predicate = PredicateBuilder.New<Domain.Entities.Identity.User>(x => x.IsDeleted == filter.IsDeleted);
Expand Down
10 changes: 10 additions & 0 deletions Template.Application/Services/Lookups/Category/CategoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public async Task<DataPaging> GetDropDownAsync(BaseParam<SearchCriteriaFilter> f

}

public async Task<IFinalResult> DeleteRangeAsync(List<int> 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<Func<Domain.Entities.Lookup.Category, bool>> PredicateBuilderFunction(CategoryFilter filter)
{
var predicate = PredicateBuilder.New<Domain.Entities.Lookup.Category>(x => x.IsDeleted == filter.IsDeleted);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,5 +13,7 @@ public interface ICategoryService : IBaseService<Domain.Entities.Lookup.Category
Task<DataPaging> GetAllPagedAsync(BaseParam<CategoryFilter> filter);

Task<DataPaging> GetDropDownAsync(BaseParam<SearchCriteriaFilter> filter);

Task<IFinalResult> DeleteRangeAsync(List<int> ids);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -12,5 +13,7 @@ public interface IStatusService : IBaseService<Domain.Entities.Lookup.Status, Ad
Task<DataPaging> GetAllPagedAsync(BaseParam<StatusFilter> filter);

Task<DataPaging> GetDropDownAsync(BaseParam<SearchCriteriaFilter> filter);

Task<IFinalResult> DeleteRangeAsync(List<int> ids);
}
}
10 changes: 10 additions & 0 deletions Template.Application/Services/Lookups/Status/StatusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public async Task<DataPaging> GetDropDownAsync(BaseParam<SearchCriteriaFilter> f

}

public async Task<IFinalResult> DeleteRangeAsync(List<int> 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<Func<Domain.Entities.Lookup.Status, bool>> PredicateBuilderFunction(StatusFilter filter)
{
var predicate = PredicateBuilder.New<Domain.Entities.Lookup.Status>(x => x.IsDeleted == filter.IsDeleted);
Expand Down

0 comments on commit 603c353

Please sign in to comment.