| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- using System.Linq;
- using System.Threading.Tasks;
- using Abp.Application.Services.Dto;
- using Abp.Domain.Entities;
- using Abp.Domain.Repositories;
- using Abp.Linq;
- namespace Abp.Application.Services
- {
- public abstract class AsyncCrudAppService<TEntity, TEntityDto>
- : AsyncCrudAppService<TEntity, TEntityDto, int>
- where TEntity : class, IEntity<int>
- where TEntityDto : IEntityDto<int>
- {
- protected AsyncCrudAppService(IRepository<TEntity, int> 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 = NullAsyncQueryableExecuter.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);
- }
- }
- }
|