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