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