-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeerRepository.cs
More file actions
40 lines (31 loc) · 1.07 KB
/
BeerRepository.cs
File metadata and controls
40 lines (31 loc) · 1.07 KB
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
38
39
40
using async.Models;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
namespace async.Repository
{
public class BeerRepository : IRepository<Beer>
{
private StoreContext _context;
public BeerRepository(StoreContext context)
{
_context = context;
}
public async Task Add(Beer entity)
=> await _context.Beers.AddAsync(entity);
public void Delete(Beer entity)
=> _context.Beers.Remove(entity);
public async Task<IEnumerable<Beer>> Get()
=> await _context.Beers.ToListAsync();
public async Task<Beer> GetById(int id)
=> await _context.Beers.FindAsync(id);
public async Task Save()
=> await _context.SaveChangesAsync();
public void Update(Beer entity)
{
_context.Beers.Attach(entity);
_context.Entry(entity).State = EntityState.Modified;
}
public IEnumerable<Beer> Search(Func<Beer, bool> filter) =>
_context.Beers.Where(filter).ToList();
}
}