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