forked from abpframework/abp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCrudAppService.cs
More file actions
115 lines (95 loc) · 3.35 KB
/
Copy pathCrudAppService.cs
File metadata and controls
115 lines (95 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories;
namespace Volo.Abp.Application.Services;
public abstract class CrudAppService<TEntity, TEntityDto, TKey>
: CrudAppService<TEntity, TEntityDto, TKey, PagedAndSortedResultRequestDto>
where TEntity : class, IEntity<TKey>
{
protected CrudAppService(IRepository<TEntity, TKey> repository)
: base(repository)
{
}
}
public abstract class CrudAppService<TEntity, TEntityDto, TKey, TGetListInput>
: CrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TEntityDto>
where TEntity : class, IEntity<TKey>
{
protected CrudAppService(IRepository<TEntity, TKey> repository)
: base(repository)
{
}
}
public abstract class CrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TCreateInput>
: CrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TCreateInput, TCreateInput>
where TEntity : class, IEntity<TKey>
{
protected CrudAppService(IRepository<TEntity, TKey> repository)
: base(repository)
{
}
}
public abstract class CrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
: CrudAppService<TEntity, TEntityDto, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
where TEntity : class, IEntity<TKey>
{
protected CrudAppService(IRepository<TEntity, TKey> repository)
: base(repository)
{
}
protected override Task<TEntityDto> MapToGetListOutputDtoAsync(TEntity entity)
{
return MapToGetOutputDtoAsync(entity);
}
protected override TEntityDto MapToGetListOutputDto(TEntity entity)
{
return MapToGetOutputDto(entity);
}
}
public abstract class CrudAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
: AbstractKeyCrudAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
where TEntity : class, IEntity<TKey>
{
protected new IRepository<TEntity, TKey> Repository { get; }
protected CrudAppService(IRepository<TEntity, TKey> repository)
: base(repository)
{
Repository = repository;
}
protected override async Task DeleteByIdAsync(TKey id)
{
await Repository.DeleteAsync(id);
}
protected override async Task<TEntity> GetEntityByIdAsync(TKey id)
{
return await Repository.GetAsync(id);
}
protected override async Task<IQueryable<TEntity>?> GetEntityByIdQueryOrNullAsync(TKey id)
{
var query = await Repository.GetQueryableAsync();
return query.Where(EntityHelper.CreateEqualityExpressionForId<TEntity, TKey>(id));
}
protected override void MapToEntity(TUpdateInput updateInput, TEntity entity)
{
if (updateInput is IEntityDto<TKey> entityDto)
{
entityDto.Id = entity.Id;
}
base.MapToEntity(updateInput, entity);
}
protected override IQueryable<TEntity> ApplyDefaultSorting(IQueryable<TEntity> query)
{
if (typeof(TEntity).IsAssignableTo<IHasCreationTime>())
{
return query.OrderByDescending(e => ((IHasCreationTime)e).CreationTime);
}
else
{
return query.OrderByDescending(e => e.Id);
}
}
}