mirror of https://github.com/abpframework/abp.git
17 changed files with 811 additions and 1 deletions
@ -0,0 +1,168 @@ |
|||
using System; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Services.Dtos; |
|||
using Volo.Abp.Domain.Entities; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Volo.Abp.Linq; |
|||
|
|||
namespace Abp.Application.Services |
|||
{ |
|||
public abstract class AsyncCrudAppService<TEntity, TEntityDto> |
|||
: AsyncCrudAppService<TEntity, TEntityDto, Guid> |
|||
where TEntity : class, IEntity<Guid> |
|||
where TEntityDto : IEntityDto<Guid> |
|||
{ |
|||
protected AsyncCrudAppService(IRepository<TEntity, Guid> repository) |
|||
: base(repository) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
|
|||
public abstract class AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey> |
|||
: AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, PagedAndSortedResultRequestDto> |
|||
where TEntity : class, IEntity<TPrimaryKey> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
{ |
|||
protected AsyncCrudAppService(IRepository<TEntity, TPrimaryKey> repository) |
|||
: base(repository) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
|
|||
public abstract class AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput> |
|||
: AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TEntityDto, TEntityDto> |
|||
where TEntity : class, IEntity<TPrimaryKey> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
{ |
|||
protected AsyncCrudAppService(IRepository<TEntity, TPrimaryKey> repository) |
|||
: base(repository) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
|
|||
public abstract class AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput> |
|||
: AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TCreateInput> |
|||
where TGetAllInput : IPagedAndSortedResultRequest |
|||
where TEntity : class, IEntity<TPrimaryKey> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
where TCreateInput : IEntityDto<TPrimaryKey> |
|||
{ |
|||
protected AsyncCrudAppService(IRepository<TEntity, TPrimaryKey> repository) |
|||
: base(repository) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
|
|||
public abstract class AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput> |
|||
: AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, EntityDto<TPrimaryKey>> |
|||
where TEntity : class, IEntity<TPrimaryKey> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
where TUpdateInput : IEntityDto<TPrimaryKey> |
|||
{ |
|||
protected AsyncCrudAppService(IRepository<TEntity, TPrimaryKey> repository) |
|||
: base(repository) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
|
|||
public abstract class AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput> |
|||
: AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput, EntityDto<TPrimaryKey>> |
|||
where TEntity : class, IEntity<TPrimaryKey> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
where TUpdateInput : IEntityDto<TPrimaryKey> |
|||
where TGetInput : IEntityDto<TPrimaryKey> |
|||
{ |
|||
protected AsyncCrudAppService(IRepository<TEntity, TPrimaryKey> repository) |
|||
: base(repository) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
|
|||
public abstract class AsyncCrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput, TDeleteInput> |
|||
: CrudAppServiceBase<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput>, |
|||
IAsyncCrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput, TDeleteInput> |
|||
where TEntity : class, IEntity<TPrimaryKey> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
where TUpdateInput : IEntityDto<TPrimaryKey> |
|||
where TGetInput : IEntityDto<TPrimaryKey> |
|||
where TDeleteInput : IEntityDto<TPrimaryKey> |
|||
{ |
|||
public IAsyncQueryableExecuter AsyncQueryableExecuter { get; set; } |
|||
|
|||
protected AsyncCrudAppService(IRepository<TEntity, TPrimaryKey> repository) |
|||
:base(repository) |
|||
{ |
|||
AsyncQueryableExecuter = DefaultAsyncQueryableExecuter.Instance; |
|||
} |
|||
|
|||
public virtual async Task<TEntityDto> Get(TGetInput input) |
|||
{ |
|||
CheckGetPermission(); |
|||
|
|||
var entity = await GetEntityByIdAsync(input.Id); |
|||
return MapToEntityDto(entity); |
|||
} |
|||
|
|||
public virtual async Task<PagedResultDto<TEntityDto>> GetAll(TGetAllInput input) |
|||
{ |
|||
CheckGetAllPermission(); |
|||
|
|||
var query = CreateFilteredQuery(input); |
|||
|
|||
var totalCount = await AsyncQueryableExecuter.CountAsync(query); |
|||
|
|||
query = ApplySorting(query, input); |
|||
query = ApplyPaging(query, input); |
|||
|
|||
var entities = await AsyncQueryableExecuter.ToListAsync(query); |
|||
|
|||
return new PagedResultDto<TEntityDto>( |
|||
totalCount, |
|||
entities.Select(MapToEntityDto).ToList() |
|||
); |
|||
} |
|||
|
|||
public virtual async Task<TEntityDto> Create(TCreateInput input) |
|||
{ |
|||
CheckCreatePermission(); |
|||
|
|||
var entity = MapToEntity(input); |
|||
|
|||
await Repository.InsertAsync(entity); |
|||
await CurrentUnitOfWork.SaveChangesAsync(); |
|||
|
|||
return MapToEntityDto(entity); |
|||
} |
|||
|
|||
public virtual async Task<TEntityDto> Update(TUpdateInput input) |
|||
{ |
|||
CheckUpdatePermission(); |
|||
|
|||
var entity = await GetEntityByIdAsync(input.Id); |
|||
|
|||
MapToEntity(input, entity); |
|||
await CurrentUnitOfWork.SaveChangesAsync(); |
|||
|
|||
return MapToEntityDto(entity); |
|||
} |
|||
|
|||
public virtual Task Delete(TDeleteInput input) |
|||
{ |
|||
CheckDeletePermission(); |
|||
|
|||
return Repository.DeleteAsync(input.Id); |
|||
} |
|||
|
|||
protected virtual Task<TEntity> GetEntityByIdAsync(TPrimaryKey id) |
|||
{ |
|||
return Repository.GetAsync(id); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,163 @@ |
|||
using System; |
|||
using System.Linq; |
|||
using Volo.Abp.Application.Services.Dtos; |
|||
using Volo.Abp.Domain.Entities; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Abp.Application.Services |
|||
{ |
|||
public abstract class CrudAppService<TEntity, TEntityDto> |
|||
: CrudAppService<TEntity, TEntityDto, Guid> |
|||
where TEntity : class, IEntity<Guid> |
|||
where TEntityDto : IEntityDto<Guid> |
|||
{ |
|||
protected CrudAppService(IRepository<TEntity, Guid> repository) |
|||
: base(repository) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
|
|||
public abstract class CrudAppService<TEntity, TEntityDto, TPrimaryKey> |
|||
: CrudAppService<TEntity, TEntityDto, TPrimaryKey, PagedAndSortedResultRequestDto> |
|||
where TEntity : class, IEntity<TPrimaryKey> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
{ |
|||
protected CrudAppService(IRepository<TEntity, TPrimaryKey> repository) |
|||
: base(repository) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
|
|||
public abstract class CrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput> |
|||
: CrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TEntityDto, TEntityDto> |
|||
where TEntity : class, IEntity<TPrimaryKey> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
{ |
|||
protected CrudAppService(IRepository<TEntity, TPrimaryKey> repository) |
|||
: base(repository) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
|
|||
public abstract class CrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput> |
|||
: CrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TCreateInput> |
|||
where TEntity : class, IEntity<TPrimaryKey> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
where TCreateInput : IEntityDto<TPrimaryKey> |
|||
{ |
|||
protected CrudAppService(IRepository<TEntity, TPrimaryKey> repository) |
|||
: base(repository) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
|
|||
public abstract class CrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput> |
|||
: CrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, EntityDto<TPrimaryKey>> |
|||
where TEntity : class, IEntity<TPrimaryKey> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
where TUpdateInput : IEntityDto<TPrimaryKey> |
|||
{ |
|||
protected CrudAppService(IRepository<TEntity, TPrimaryKey> repository) |
|||
: base(repository) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
|
|||
public abstract class CrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput> |
|||
: CrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput, EntityDto<TPrimaryKey>> |
|||
where TEntity : class, IEntity<TPrimaryKey> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
where TUpdateInput : IEntityDto<TPrimaryKey> |
|||
where TGetInput : IEntityDto<TPrimaryKey> |
|||
{ |
|||
protected CrudAppService(IRepository<TEntity, TPrimaryKey> repository) |
|||
: base(repository) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
|
|||
public abstract class CrudAppService<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput, TDeleteInput> |
|||
: CrudAppServiceBase<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput>, |
|||
ICrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput, TDeleteInput> |
|||
where TEntity : class, IEntity<TPrimaryKey> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
where TUpdateInput : IEntityDto<TPrimaryKey> |
|||
where TGetInput : IEntityDto<TPrimaryKey> |
|||
where TDeleteInput : IEntityDto<TPrimaryKey> |
|||
{ |
|||
protected CrudAppService(IRepository<TEntity, TPrimaryKey> repository) |
|||
: base(repository) |
|||
{ |
|||
|
|||
} |
|||
|
|||
public virtual TEntityDto Get(TGetInput input) |
|||
{ |
|||
CheckGetPermission(); |
|||
|
|||
var entity = GetEntityById(input.Id); |
|||
return MapToEntityDto(entity); |
|||
} |
|||
|
|||
public virtual PagedResultDto<TEntityDto> GetAll(TGetAllInput input) |
|||
{ |
|||
CheckGetAllPermission(); |
|||
|
|||
var query = CreateFilteredQuery(input); |
|||
|
|||
var totalCount = query.Count(); |
|||
|
|||
query = ApplySorting(query, input); |
|||
query = ApplyPaging(query, input); |
|||
|
|||
var entities = query.ToList(); |
|||
|
|||
return new PagedResultDto<TEntityDto>( |
|||
totalCount, |
|||
entities.Select(MapToEntityDto).ToList() |
|||
); |
|||
} |
|||
|
|||
public virtual TEntityDto Create(TCreateInput input) |
|||
{ |
|||
CheckCreatePermission(); |
|||
|
|||
var entity = MapToEntity(input); |
|||
|
|||
Repository.Insert(entity); |
|||
CurrentUnitOfWork.SaveChanges(); |
|||
|
|||
return MapToEntityDto(entity); |
|||
} |
|||
|
|||
public virtual TEntityDto Update(TUpdateInput input) |
|||
{ |
|||
CheckUpdatePermission(); |
|||
|
|||
var entity = GetEntityById(input.Id); |
|||
|
|||
MapToEntity(input, entity); |
|||
CurrentUnitOfWork.SaveChanges(); |
|||
|
|||
return MapToEntityDto(entity); |
|||
} |
|||
|
|||
public virtual void Delete(TDeleteInput input) |
|||
{ |
|||
CheckDeletePermission(); |
|||
|
|||
Repository.Delete(input.Id); |
|||
} |
|||
|
|||
protected virtual TEntity GetEntityById(TPrimaryKey id) |
|||
{ |
|||
return Repository.Get(id); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,172 @@ |
|||
using System; |
|||
using System.Linq; |
|||
using System.Linq.Dynamic.Core; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Application.Services.Dtos; |
|||
using Volo.Abp.Domain.Entities; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Volo.Abp.Linq.Extensions; |
|||
|
|||
namespace Abp.Application.Services |
|||
{ |
|||
/// <summary>
|
|||
/// This is a common base class for CrudAppService and AsyncCrudAppService classes.
|
|||
/// Inherit either from CrudAppService or AsyncCrudAppService, not from this class.
|
|||
/// </summary>
|
|||
public abstract class CrudAppServiceBase<TEntity, TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput> : ApplicationService |
|||
where TEntity : class, IEntity<TPrimaryKey> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
where TUpdateInput : IEntityDto<TPrimaryKey> |
|||
{ |
|||
protected IRepository<TEntity, TPrimaryKey> Repository { get; } |
|||
|
|||
protected virtual string GetPermissionName { get; set; } |
|||
|
|||
protected virtual string GetAllPermissionName { get; set; } |
|||
|
|||
protected virtual string CreatePermissionName { get; set; } |
|||
|
|||
protected virtual string UpdatePermissionName { get; set; } |
|||
|
|||
protected virtual string DeletePermissionName { get; set; } |
|||
|
|||
protected CrudAppServiceBase(IRepository<TEntity, TPrimaryKey> repository) |
|||
{ |
|||
Repository = repository; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Should apply sorting if needed.
|
|||
/// </summary>
|
|||
/// <param name="query">The query.</param>
|
|||
/// <param name="input">The input.</param>
|
|||
protected virtual IQueryable<TEntity> ApplySorting(IQueryable<TEntity> query, TGetAllInput input) |
|||
{ |
|||
//Try to sort query if available
|
|||
var sortInput = input as ISortedResultRequest; |
|||
if (sortInput != null) |
|||
{ |
|||
if (!sortInput.Sorting.IsNullOrWhiteSpace()) |
|||
{ |
|||
return query.OrderBy(sortInput.Sorting); |
|||
} |
|||
} |
|||
|
|||
//IQueryable.Task requires sorting, so we should sort if Take will be used.
|
|||
if (input is ILimitedResultRequest) |
|||
{ |
|||
return query.OrderByDescending(e => e.Id); |
|||
} |
|||
|
|||
//No sorting
|
|||
return query; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Should apply paging if needed.
|
|||
/// </summary>
|
|||
/// <param name="query">The query.</param>
|
|||
/// <param name="input">The input.</param>
|
|||
protected virtual IQueryable<TEntity> ApplyPaging(IQueryable<TEntity> query, TGetAllInput input) |
|||
{ |
|||
//Try to use paging if available
|
|||
var pagedInput = input as IPagedResultRequest; |
|||
if (pagedInput != null) |
|||
{ |
|||
return query.PageBy(pagedInput); |
|||
} |
|||
|
|||
//Try to limit query result if available
|
|||
var limitedInput = input as ILimitedResultRequest; |
|||
if (limitedInput != null) |
|||
{ |
|||
return query.Take(limitedInput.MaxResultCount); |
|||
} |
|||
|
|||
//No paging
|
|||
return query; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// This method should create <see cref="IQueryable{TEntity}"/> based on given input.
|
|||
/// It should filter query if needed, but should not do sorting or paging.
|
|||
/// Sorting should be done in <see cref="ApplySorting"/> and paging should be done in <see cref="ApplyPaging"/>
|
|||
/// methods.
|
|||
/// </summary>
|
|||
/// <param name="input">The input.</param>
|
|||
protected virtual IQueryable<TEntity> CreateFilteredQuery(TGetAllInput input) |
|||
{ |
|||
var queryableRepository = Repository as IQueryableRepository<TEntity, TPrimaryKey>; |
|||
if (queryableRepository == null) |
|||
{ |
|||
throw new AbpException("Repository should be IQueryableRepository in order to call CreateFilteredQuery, but it's not. It's type: " + Repository.GetType().AssemblyQualifiedName); |
|||
} |
|||
|
|||
return queryableRepository; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Maps <see cref="TEntity"/> to <see cref="TEntityDto"/>.
|
|||
/// It uses <see cref="IObjectMapper"/> by default.
|
|||
/// It can be overrided for custom mapping.
|
|||
/// </summary>
|
|||
protected virtual TEntityDto MapToEntityDto(TEntity entity) |
|||
{ |
|||
return ObjectMapper.Map<TEntity, TEntityDto>(entity); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Maps <see cref="TEntityDto"/> to <see cref="TEntity"/> to create a new entity.
|
|||
/// It uses <see cref="IObjectMapper"/> by default.
|
|||
/// It can be overrided for custom mapping.
|
|||
/// </summary>
|
|||
protected virtual TEntity MapToEntity(TCreateInput createInput) |
|||
{ |
|||
return ObjectMapper.Map<TCreateInput, TEntity>(createInput); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Maps <see cref="TUpdateInput"/> to <see cref="TEntity"/> to update the entity.
|
|||
/// It uses <see cref="IObjectMapper"/> by default.
|
|||
/// It can be overrided for custom mapping.
|
|||
/// </summary>
|
|||
protected virtual void MapToEntity(TUpdateInput updateInput, TEntity entity) |
|||
{ |
|||
ObjectMapper.Map(updateInput, entity); |
|||
} |
|||
|
|||
protected virtual void CheckPermission(string permissionName) |
|||
{ |
|||
if (!string.IsNullOrEmpty(permissionName)) |
|||
{ |
|||
//TODO: PermissionChecker.Authorize(permissionName); //Will be implemented when PermissionChecker is available
|
|||
} |
|||
} |
|||
|
|||
protected virtual void CheckGetPermission() |
|||
{ |
|||
CheckPermission(GetPermissionName); |
|||
} |
|||
|
|||
protected virtual void CheckGetAllPermission() |
|||
{ |
|||
CheckPermission(GetAllPermissionName); |
|||
} |
|||
|
|||
protected virtual void CheckCreatePermission() |
|||
{ |
|||
CheckPermission(CreatePermissionName); |
|||
} |
|||
|
|||
protected virtual void CheckUpdatePermission() |
|||
{ |
|||
CheckPermission(UpdatePermissionName); |
|||
} |
|||
|
|||
protected virtual void CheckDeletePermission() |
|||
{ |
|||
CheckPermission(DeletePermissionName); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
namespace Volo.Abp.Application.Services.Dtos |
|||
{ |
|||
/// <summary>
|
|||
/// This interface is defined to standardize to set "Total Count of Items" to a DTO for long type.
|
|||
/// </summary>
|
|||
public interface IHasLongTotalCount |
|||
{ |
|||
/// <summary>
|
|||
/// Total count of Items.
|
|||
/// </summary>
|
|||
long TotalCount { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
namespace Volo.Abp.Application.Services.Dtos |
|||
{ |
|||
/// <summary>
|
|||
/// This interface is defined to standardize to set "Total Count of Items" to a DTO.
|
|||
/// </summary>
|
|||
public interface IHasTotalCount |
|||
{ |
|||
/// <summary>
|
|||
/// Total count of Items.
|
|||
/// </summary>
|
|||
int TotalCount { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.Application.Services.Dtos |
|||
{ |
|||
/// <summary>
|
|||
/// This interface is defined to standardize to return a list of items to clients.
|
|||
/// </summary>
|
|||
/// <typeparam name="T">Type of the items in the <see cref="Items"/> list</typeparam>
|
|||
public interface IListResult<T> |
|||
{ |
|||
/// <summary>
|
|||
/// List of items.
|
|||
/// </summary>
|
|||
IReadOnlyList<T> Items { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
namespace Volo.Abp.Application.Services.Dtos |
|||
{ |
|||
/// <summary>
|
|||
/// This interface is defined to standardize to request a paged and sorted result.
|
|||
/// </summary>
|
|||
public interface IPagedAndSortedResultRequest : IPagedResultRequest, ISortedResultRequest |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
namespace Volo.Abp.Application.Services.Dtos |
|||
{ |
|||
/// <summary>
|
|||
/// This interface is defined to standardize to return a page of items to clients.
|
|||
/// </summary>
|
|||
/// <typeparam name="T">Type of the items in the <see cref="IListResult{T}.Items"/> list</typeparam>
|
|||
public interface IPagedResult<T> : IListResult<T>, IHasTotalCount |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
namespace Volo.Abp.Application.Services.Dtos |
|||
{ |
|||
/// <summary>
|
|||
/// This interface is defined to standardize to request a sorted result.
|
|||
/// </summary>
|
|||
public interface ISortedResultRequest |
|||
{ |
|||
/// <summary>
|
|||
/// Sorting information.
|
|||
/// Should include sorting field and optionally a direction (ASC or DESC)
|
|||
/// Can contain more than one field separated by comma (,).
|
|||
/// </summary>
|
|||
/// <example>
|
|||
/// Examples:
|
|||
/// "Name"
|
|||
/// "Name DESC"
|
|||
/// "Name ASC, Age DESC"
|
|||
/// </example>
|
|||
string Sorting { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace Volo.Abp.Application.Services.Dtos |
|||
{ |
|||
/// <summary>
|
|||
/// Simply implements <see cref="ILimitedResultRequest"/>.
|
|||
/// </summary>
|
|||
public class LimitedResultRequestDto : ILimitedResultRequest |
|||
{ |
|||
[Range(1, int.MaxValue)] |
|||
public virtual int MaxResultCount { get; set; } = 10; |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.Application.Services.Dtos |
|||
{ |
|||
/// <summary>
|
|||
/// Simply implements <see cref="IPagedAndSortedResultRequest"/>.
|
|||
/// </summary>
|
|||
[Serializable] |
|||
public class PagedAndSortedResultRequestDto : PagedResultRequestDto, IPagedAndSortedResultRequest |
|||
{ |
|||
public virtual string Sorting { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.Application.Services.Dtos |
|||
{ |
|||
/// <summary>
|
|||
/// Implements <see cref="IPagedResult{T}"/>.
|
|||
/// </summary>
|
|||
/// <typeparam name="T">Type of the items in the <see cref="ListResultDto{T}.Items"/> list</typeparam>
|
|||
[Serializable] |
|||
public class PagedResultDto<T> : ListResultDto<T>, IPagedResult<T> |
|||
{ |
|||
/// <summary>
|
|||
/// Total count of Items.
|
|||
/// </summary>
|
|||
public int TotalCount { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Creates a new <see cref="PagedResultDto{T}"/> object.
|
|||
/// </summary>
|
|||
public PagedResultDto() |
|||
{ |
|||
|
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Creates a new <see cref="PagedResultDto{T}"/> object.
|
|||
/// </summary>
|
|||
/// <param name="totalCount">Total count of Items</param>
|
|||
/// <param name="items">List of items in current page</param>
|
|||
public PagedResultDto(int totalCount, IReadOnlyList<T> items) |
|||
: base(items) |
|||
{ |
|||
TotalCount = totalCount; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
using System; |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace Volo.Abp.Application.Services.Dtos |
|||
{ |
|||
/// <summary>
|
|||
/// Simply implements <see cref="IPagedResultRequest"/>.
|
|||
/// </summary>
|
|||
[Serializable] |
|||
public class PagedResultRequestDto : LimitedResultRequestDto, IPagedResultRequest |
|||
{ |
|||
[Range(0, int.MaxValue)] |
|||
public virtual int SkipCount { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,71 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Application.Services.Dtos; |
|||
|
|||
namespace Abp.Application.Services |
|||
{ |
|||
public interface IAsyncCrudAppService<TEntityDto> |
|||
: IAsyncCrudAppService<TEntityDto, Guid> |
|||
where TEntityDto : IEntityDto<Guid> |
|||
{ |
|||
|
|||
} |
|||
|
|||
public interface IAsyncCrudAppService<TEntityDto, TPrimaryKey> |
|||
: IAsyncCrudAppService<TEntityDto, TPrimaryKey, PagedAndSortedResultRequestDto> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
{ |
|||
|
|||
} |
|||
|
|||
public interface IAsyncCrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput> |
|||
: IAsyncCrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TEntityDto, TEntityDto> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
{ |
|||
|
|||
} |
|||
|
|||
public interface IAsyncCrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput, in TCreateInput> |
|||
: IAsyncCrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TCreateInput> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
where TCreateInput : IEntityDto<TPrimaryKey> |
|||
{ |
|||
|
|||
} |
|||
|
|||
public interface IAsyncCrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput, in TCreateInput, in TUpdateInput> |
|||
: IAsyncCrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, EntityDto<TPrimaryKey>> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
where TUpdateInput : IEntityDto<TPrimaryKey> |
|||
{ |
|||
|
|||
} |
|||
|
|||
public interface IAsyncCrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput, in TCreateInput, in TUpdateInput, in TGetInput> |
|||
: IAsyncCrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput, EntityDto<TPrimaryKey>> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
where TUpdateInput : IEntityDto<TPrimaryKey> |
|||
where TGetInput : IEntityDto<TPrimaryKey> |
|||
{ |
|||
|
|||
} |
|||
|
|||
public interface IAsyncCrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput, in TCreateInput, in TUpdateInput, in TGetInput, in TDeleteInput> |
|||
: IApplicationService |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
where TUpdateInput : IEntityDto<TPrimaryKey> |
|||
where TGetInput : IEntityDto<TPrimaryKey> |
|||
where TDeleteInput : IEntityDto<TPrimaryKey> |
|||
{ |
|||
Task<TEntityDto> Get(TGetInput input); |
|||
|
|||
Task<PagedResultDto<TEntityDto>> GetAll(TGetAllInput input); |
|||
|
|||
Task<TEntityDto> Create(TCreateInput input); |
|||
|
|||
Task<TEntityDto> Update(TUpdateInput input); |
|||
|
|||
Task Delete(TDeleteInput input); |
|||
} |
|||
} |
|||
@ -0,0 +1,70 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Application.Services.Dtos; |
|||
|
|||
namespace Abp.Application.Services |
|||
{ |
|||
public interface ICrudAppService<TEntityDto> |
|||
: ICrudAppService<TEntityDto, Guid> |
|||
where TEntityDto : IEntityDto<Guid> |
|||
{ |
|||
|
|||
} |
|||
|
|||
public interface ICrudAppService<TEntityDto, TPrimaryKey> |
|||
: ICrudAppService<TEntityDto, TPrimaryKey, PagedAndSortedResultRequestDto> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
{ |
|||
|
|||
} |
|||
|
|||
public interface ICrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput> |
|||
: ICrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TEntityDto, TEntityDto> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
{ |
|||
|
|||
} |
|||
|
|||
public interface ICrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput, in TCreateInput> |
|||
: ICrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TCreateInput> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
where TCreateInput : IEntityDto<TPrimaryKey> |
|||
{ |
|||
|
|||
} |
|||
|
|||
public interface ICrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput, in TCreateInput, in TUpdateInput> |
|||
: ICrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, EntityDto<TPrimaryKey>> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
where TUpdateInput : IEntityDto<TPrimaryKey> |
|||
{ |
|||
|
|||
} |
|||
|
|||
public interface ICrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput, in TCreateInput, in TUpdateInput, in TGetInput> |
|||
: ICrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TUpdateInput, TGetInput, EntityDto<TPrimaryKey>> |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
where TUpdateInput : IEntityDto<TPrimaryKey> |
|||
where TGetInput : IEntityDto<TPrimaryKey> |
|||
{ |
|||
|
|||
} |
|||
|
|||
public interface ICrudAppService<TEntityDto, TPrimaryKey, in TGetAllInput, in TCreateInput, in TUpdateInput, in TGetInput, in TDeleteInput> |
|||
: IApplicationService |
|||
where TEntityDto : IEntityDto<TPrimaryKey> |
|||
where TUpdateInput : IEntityDto<TPrimaryKey> |
|||
where TGetInput : IEntityDto<TPrimaryKey> |
|||
where TDeleteInput : IEntityDto<TPrimaryKey> |
|||
{ |
|||
TEntityDto Get(TGetInput input); |
|||
|
|||
PagedResultDto<TEntityDto> GetAll(TGetAllInput input); |
|||
|
|||
TEntityDto Create(TCreateInput input); |
|||
|
|||
TEntityDto Update(TUpdateInput input); |
|||
|
|||
void Delete(TDeleteInput input); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue