Skip to content

Commit f79c7c8

Browse files
committed
finish method in genric repo :GetAllWithSpecAsync
and do specf of MonthOfExpense
1 parent 2257267 commit f79c7c8

File tree

3 files changed

+65
-32
lines changed

3 files changed

+65
-32
lines changed

ThriftinessCore/Repos/IGenricRepo.cs

+10-7
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44
using System.Text;
55
using System.Threading.Tasks;
66
using ThriftinessCore.Entites;
7+
using ThriftinessCore.Specfictions;
78

89
namespace ThriftinessCore.Repos
910
{
10-
public interface IGenricRepo<T> where T : BaseEntity
11-
{
12-
Task<T> GetbyIdAsync(int id);
11+
public interface IGenricRepo<T> where T : BaseEntity
12+
{
13+
Task<T> GetbyIdAsync(int id);
1314

14-
Task AddAsync(T item);
15+
Task<IReadOnlyList<T>> GetAllWithSpecAsync(ISpecfiction<T> Spec);
1516

16-
void DeleteAsync(T item);
17+
Task AddAsync(T item);
1718

18-
void Update(T item);
19-
}
19+
void DeleteAsync(T item);
20+
21+
void Update(T item);
22+
}
2023
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using ThriftinessCore.Entites;
7+
8+
namespace ThriftinessCore.Specfictions
9+
{
10+
public class MonthOfExpenseSpecf : BaseSpecfiction<MonthOfExpense>
11+
{
12+
public MonthOfExpenseSpecf(string userId) : base(p => p.User_Id == userId)
13+
{
14+
Includes.Add(p => p.Expenses);
15+
}
16+
}
17+
}
+38-25
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,49 @@
1-
using System;
1+
using Microsoft.EntityFrameworkCore;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
56
using System.Threading.Tasks;
67
using ThriftinessCore.Entites;
78
using ThriftinessCore.Repos;
9+
using ThriftinessCore.Specfictions;
810
using ThriftinessRepository.Contexts;
11+
using ThriftinessRepository.Spec;
912

1013
namespace ThriftinessRepository.Repos
1114
{
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+
}
3649
}

0 commit comments

Comments
 (0)