Skip to content

Commit 0080da6

Browse files
committed
GetProductByNameAsync
1 parent d3096ea commit 0080da6

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}

0 commit comments

Comments
 (0)