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