-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathOrderRepository.cs
37 lines (32 loc) · 1.04 KB
/
OrderRepository.cs
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
using AspnetRunBasics.Data;
using AspnetRunBasics.Entities;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AspnetRunBasics.Repositories.Interfaces;
namespace AspnetRunBasics.Repositories
{
public class OrderRepository : IOrderRepository
{
protected readonly AspnetRunContext _dbContext;
public OrderRepository(AspnetRunContext dbContext)
{
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
}
public async Task<Order> CheckOut(Order order)
{
_dbContext.Orders.Add(order);
await _dbContext.SaveChangesAsync();
return order;
}
public async Task<IEnumerable<Order>> GetOrdersByUserName(string userName)
{
var orderList = await _dbContext.Orders
.Where(o => o.UserName == userName)
.ToListAsync();
return orderList;
}
}
}