File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed
AspNetRunBasic/Repositories Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ using AspNetRunBasic . Entities ;
2+ using System . Collections . Generic ;
3+ using System . Threading . Tasks ;
4+
5+ namespace AspNetRunBasic . Repositories
6+ {
7+ public interface IProductRepository
8+ {
9+ Task < IEnumerable < Product > > GetProductListAsync ( ) ;
10+ Task < IEnumerable < Product > > GetProductByNameAsync ( string name ) ;
11+ Task < IEnumerable < Product > > GetProductByCategoryAsync ( int categoryId ) ;
12+ }
13+ }
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Threading . Tasks ;
5+ using AspNetRunBasic . Data ;
6+ using AspNetRunBasic . Entities ;
7+ using Microsoft . EntityFrameworkCore ;
8+
9+ namespace AspNetRunBasic . Repositories
10+ {
11+ public class ProductRepository : IProductRepository
12+ {
13+ protected readonly AspnetRunContext _dbContext ;
14+
15+ public ProductRepository ( AspnetRunContext dbContext )
16+ {
17+ _dbContext = dbContext ?? throw new ArgumentNullException ( nameof ( dbContext ) ) ;
18+ }
19+
20+ public async Task < IEnumerable < Product > > GetProductListAsync ( )
21+ {
22+ return await _dbContext . Products . ToListAsync ( ) ;
23+ }
24+
25+ public async Task < IEnumerable < Product > > GetProductByNameAsync ( string name )
26+ {
27+ return await _dbContext . Products . Where ( p => p . Name . Contains ( name ) ) . ToListAsync ( ) ;
28+ }
29+
30+ public async Task < IEnumerable < Product > > GetProductByCategoryAsync ( int categoryId )
31+ {
32+ throw new NotImplementedException ( ) ;
33+ }
34+
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments