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