1
- using System ;
1
+ using Microsoft . EntityFrameworkCore ;
2
+ using System ;
2
3
using System . Collections . Generic ;
3
4
using System . Linq ;
4
5
using System . Text ;
5
6
using System . Threading . Tasks ;
6
7
using ThriftinessCore . Entites ;
7
8
using ThriftinessCore . Repos ;
9
+ using ThriftinessCore . Specfictions ;
8
10
using ThriftinessRepository . Contexts ;
11
+ using ThriftinessRepository . Spec ;
9
12
10
13
namespace ThriftinessRepository . Repos
11
14
{
12
- public class GenricRepo < T > : IGenricRepo < T > where T : BaseEntity
13
- {
14
- private readonly ThriftinessContext _dbContext ;
15
-
16
- public GenricRepo ( ThriftinessContext dbContext )
17
- {
18
- _dbContext = dbContext ;
19
- }
20
-
21
- public async Task AddAsync ( T item )
22
- => await _dbContext . Set < T > ( ) . AddAsync ( item ) ;
23
-
24
- public void DeleteAsync ( T item )
25
- {
26
- _dbContext . Remove ( item ) ;
27
- }
28
-
29
- public async Task < T ? > GetbyIdAsync ( int id ) => await _dbContext . Set < T > ( ) . FindAsync ( id ) ;
30
-
31
- public void Update ( T item )
32
- {
33
- _dbContext . Update ( item ) ;
34
- }
35
- }
15
+ public class GenricRepo < T > : IGenricRepo < T > where T : BaseEntity
16
+ {
17
+ private readonly ThriftinessContext _dbContext ;
18
+
19
+ public GenricRepo ( ThriftinessContext dbContext )
20
+ {
21
+ _dbContext = dbContext ;
22
+ }
23
+
24
+ public async Task AddAsync ( T item )
25
+ => await _dbContext . Set < T > ( ) . AddAsync ( item ) ;
26
+
27
+ public void DeleteAsync ( T item )
28
+ {
29
+ _dbContext . Remove ( item ) ;
30
+ }
31
+
32
+ public async Task < IReadOnlyList < T > > GetAllWithSpecAsync ( ISpecfiction < T > Spec )
33
+ {
34
+ return await GenerateSpec ( Spec ) . ToListAsync ( ) ;
35
+ }
36
+
37
+ public async Task < T ? > GetbyIdAsync ( int id ) => await _dbContext . Set < T > ( ) . FindAsync ( id ) ;
38
+
39
+ public void Update ( T item )
40
+ {
41
+ _dbContext . Update ( item ) ;
42
+ }
43
+
44
+ private IQueryable < T > GenerateSpec ( ISpecfiction < T > Spec )
45
+ {
46
+ return SpecificationEvalutor < T > . GetQuery ( _dbContext . Set < T > ( ) , Spec ) . Result ;
47
+ }
48
+ }
36
49
}
0 commit comments