ScientificReport
GrantRepository.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 GrantRepository : IRepository<Grant>
12  {
13  private readonly ScientificReportDbContext _context;
14 
16  {
17  _context = context;
18  }
19 
20  public virtual IEnumerable<Grant> All()
21  {
22  return _context.Grants
23  .Include(b => b.UserProfilesGrants)
24  .ThenInclude(b => b.UserProfile);
25  }
26 
27  public virtual IEnumerable<Grant> AllWhere(Func<Grant, bool> predicate)
28  {
29  return All().Where(predicate);
30  }
31 
32  public virtual Grant Get(Guid id)
33  {
34  return All().FirstOrDefault(u => u.Id == id);
35  }
36 
37  public virtual Grant Get(Func<Grant, bool> predicate)
38  {
39  return All().Where(predicate).FirstOrDefault();
40  }
41 
42  public virtual void Create(Grant item)
43  {
44  _context.Grants.Add(item);
45  _context.SaveChanges();
46  }
47 
48  public virtual void Update(Grant item)
49  {
50  if (item != null)
51  {
52  _context.Grants.Update(item);
53  _context.SaveChanges();
54  }
55  }
56 
57  public virtual void Delete(Guid id)
58  {
59  var item = _context.Grants.Find(id);
60  if (item != null)
61  {
62  _context.Grants.Remove(item);
63  _context.SaveChanges();
64  }
65  }
66 
67  public virtual IQueryable<Grant> GetQuery()
68  {
69  return _context.Grants;
70  }
71  }
72 }
virtual Grant Get(Func< Grant, bool > predicate)
GrantRepository(ScientificReportDbContext context)
virtual IEnumerable< Grant > AllWhere(Func< Grant, bool > predicate)