ScientificReport
OppositionRepository.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using Microsoft.EntityFrameworkCore;
8 
9 namespace ScientificReport.DAL.Repositories
10 {
11  public class OppositionRepository: IRepository<Opposition>
12  {
13  private readonly ScientificReportDbContext _context;
14 
16  {
17  _context = context;
18  }
19 
20  public virtual IEnumerable<Opposition> All()
21  {
22  return _context.Oppositions.Include(o => o.Opponent);
23  }
24 
25  public virtual IEnumerable<Opposition> AllWhere(Func<Opposition, bool> predicate)
26  {
27  return All().Where(predicate);
28  }
29 
30  public virtual Opposition Get(Guid id)
31  {
32  return All().FirstOrDefault(u => u.Id == id);
33  }
34 
35  public virtual Opposition Get(Func<Opposition, bool> predicate)
36  {
37  return All().Where(predicate).FirstOrDefault();
38  }
39 
40  public virtual void Create(Opposition item)
41  {
42  _context.Oppositions.Add(item);
43  _context.SaveChanges();
44  }
45 
46  public virtual void Update(Opposition item)
47  {
48  if (item != null)
49  {
50  _context.Oppositions.Update(item);
51  _context.SaveChanges();
52  }
53  }
54 
55  public virtual void Delete(Guid id)
56  {
57  var item = _context.Oppositions.Find(id);
58  if (item != null)
59  {
60  _context.Oppositions.Remove(item);
61  _context.SaveChanges();
62  }
63  }
64 
65  public virtual IQueryable<Opposition> GetQuery()
66  {
67  return _context.Oppositions;
68  }
69  }
70 }
virtual IEnumerable< Opposition > AllWhere(Func< Opposition, bool > predicate)
virtual Opposition Get(Func< Opposition, bool > predicate)