ScientificReport
UserProfileRepository.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 UserProfileRepository : IRepository<UserProfile>
12  {
13  private readonly ScientificReportDbContext _context;
14 
16  {
17  _context = context;
18  }
19 
20  public virtual IEnumerable<UserProfile> All()
21  {
22  return _context.UserProfiles
23  .Include(b => b.UserProfilesPublications)
24  .Include(g => g.UserProfilesGrants)
25  .Include(sw => sw.UserProfilesScientificWorks)
26  .Include(a => a.UserProfilesArticles)
27 // .Include(a => a.Department)
28  .Include(rt => rt.UserProfilesReportTheses)
29  .Include(si => si.UserProfilesScientificInternships)
30  .Include(ap => ap.AuthorsPatentLicenseActivities)
31  .Include(apl => apl.ApplicantsPatentLicenseActivities);
32  }
33 
34  public virtual IEnumerable<UserProfile> AllWhere(Func<UserProfile, bool> predicate)
35  {
36  return All().Where(predicate);
37  }
38 
39  public virtual UserProfile Get(Guid id)
40  {
41  return All().FirstOrDefault(u => u.Id == id);
42  }
43 
44  public virtual UserProfile Get(Func<UserProfile, bool> predicate)
45  {
46  return All().Where(predicate).FirstOrDefault();
47  }
48 
49  public virtual void Create(UserProfile item)
50  {
51  _context.UserProfiles.Add(item);
52  _context.SaveChanges();
53  }
54 
55  public virtual void Update(UserProfile item)
56  {
57  if (item == null) return;
58  _context.UserProfiles.Update(item);
59  _context.SaveChanges();
60  }
61 
62  public virtual void Delete(Guid id)
63  {
64  var item = _context.UserProfiles.Find(id);
65  if (item == null)
66  {
67  return;
68  }
69 
70  _context.UserProfiles.Remove(item);
71  _context.SaveChanges();
72  }
73 
74  public virtual IQueryable<UserProfile> GetQuery()
75  {
76  return _context.UserProfiles;
77  }
78  }
79 }
virtual UserProfile Get(Func< UserProfile, bool > predicate)
virtual IEnumerable< UserProfile > AllWhere(Func< UserProfile, bool > predicate)