ScientificReport
TeacherReportService.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
9 
10 namespace ScientificReport.BLL.Services
11 {
13  {
14  private readonly TeacherReportRepository _teacherReportRepository;
15  private readonly ArticleRepository _articleRepository;
16  private readonly ScientificWorkRepository _scientificWorkRepository;
17  private readonly ReportThesisRepository _reportThesisRepository;
18  private readonly PublicationRepository _publicationRepository;
19 
20  private readonly GrantRepository _grantRepository;
21  private readonly ScientificInternshipRepository _scientificInternshipRepository;
22  private readonly PostgraduateGuidanceRepository _postgraduateGuidanceRepository;
23  private readonly ScientificConsultationRepository _scientificConsultationRepository;
24  private readonly PostgraduateDissertationGuidanceRepository _postgraduateDissertationGuidanceRepository;
25  private readonly ReviewRepository _reviewRepository;
26  private readonly OppositionRepository _oppositionRepository;
27  private readonly PatentLicenseActivityRepository _patentRepository;
28  private readonly MembershipRepository _membershipRepository;
29 
31  {
32  _teacherReportRepository = new TeacherReportRepository(context);
33  _articleRepository = new ArticleRepository(context);
34  _scientificWorkRepository = new ScientificWorkRepository(context);
35  _reportThesisRepository = new ReportThesisRepository(context);
36  _publicationRepository = new PublicationRepository(context);
37  _grantRepository = new GrantRepository(context);
38  _scientificInternshipRepository = new ScientificInternshipRepository(context);
39  _postgraduateGuidanceRepository = new PostgraduateGuidanceRepository(context);
40  _scientificConsultationRepository = new ScientificConsultationRepository(context);
41  _postgraduateDissertationGuidanceRepository = new PostgraduateDissertationGuidanceRepository(context);
42  _reviewRepository = new ReviewRepository(context);
43  _oppositionRepository = new OppositionRepository(context);
44  _patentRepository = new PatentLicenseActivityRepository(context);
45  _membershipRepository = new MembershipRepository(context);
46  }
47 
48  public virtual IEnumerable<TeacherReport> GetAll()
49  {
50  return _teacherReportRepository.All();
51  }
52 
53  public virtual IEnumerable<TeacherReport> GetAllWhere(Func<TeacherReport, bool> predicate)
54  {
55  return _teacherReportRepository.AllWhere(predicate);
56  }
57 
58  public virtual TeacherReport GetById(Guid id)
59  {
60  return _teacherReportRepository.Get(id);
61  }
62 
63  public virtual TeacherReport Get(Func<TeacherReport, bool> predicate)
64  {
65  return _teacherReportRepository.Get(predicate);
66  }
67 
68  public virtual void CreateItem(TeacherReport item)
69  {
70  _teacherReportRepository.Create(item);
71  }
72 
73  public virtual void UpdateItem(TeacherReport item)
74  {
75  _teacherReportRepository.Update(item);
76  }
77 
78  public virtual void DeleteById(Guid id)
79  {
80  _teacherReportRepository.Delete(id);
81  }
82 
83  public virtual bool Any(Func<TeacherReport, bool> predicate)
84  {
85  return _teacherReportRepository.AllWhere(predicate).Any();
86  }
87 
88  public virtual bool Exists(Guid id)
89  {
90  return Any(r => r.Id == id);
91  }
92 
93  public void AddPublication(Guid id, Guid entityId)
94  {
95  var report = GetById(id);
96  var entity = _publicationRepository.Get(entityId);
97  if (report.TeacherReportsPublications.Any(u => u.Publication.Id == entityId))
98  return;
99 
100  report.TeacherReportsPublications.Add(new TeacherReportsPublications
101  {
102  TeacherReport = report,
103  Publication = entity
104  });
105  UpdateItem(report);
106  }
107 
108  public void RemovePublication(Guid id, Guid entityId)
109  {
110  var report = _teacherReportRepository.Get(id);
111  if (report.TeacherReportsPublications.All(u => u.Publication.Id != entityId))
112  return;
113 
114 
115  report.TeacherReportsPublications = report.TeacherReportsPublications
116  .Where(u => u.Publication.Id != entityId).ToList();
117  UpdateItem(report);
118  }
119 
120  public void AddArticle(Guid id, Guid entityId)
121  {
122  var report = GetById(id);
123  var entity = _articleRepository.Get(entityId);
124  if (report.TeacherReportsArticles.Any(u => u.Article.Id == entityId))
125  return;
126 
127  report.TeacherReportsArticles.Add(new TeacherReportsArticles
128  {
129  TeacherReport = report,
130  Article = entity
131  });
132  UpdateItem(report);
133  }
134 
135  public void RemoveArticle(Guid id, Guid entityId)
136  {
137  var report = _teacherReportRepository.Get(id);
138  if (report.TeacherReportsArticles.All(u => u.Article.Id != entityId))
139  return;
140 
141 
142  report.TeacherReportsArticles = report.TeacherReportsArticles
143  .Where(u => u.Article.Id != entityId).ToList();
144  UpdateItem(report);
145  }
146 
147  public void AddScientificWork(Guid id, Guid entityId)
148  {
149  var report = GetById(id);
150  var entity = _scientificWorkRepository.Get(entityId);
151  if (report.TeacherReportsScientificWorks.Any(u => u.ScientificWork.Id == entityId))
152  return;
153 
154  report.TeacherReportsScientificWorks.Add(new TeacherReportsScientificWorks
155  {
156  TeacherReport = report,
157  ScientificWork = entity
158  });
159  UpdateItem(report);
160  }
161 
162  public void RemoveScientificWork(Guid id, Guid entityId)
163  {
164  var report = _teacherReportRepository.Get(id);
165  if (report.TeacherReportsScientificWorks.All(u => u.ScientificWork.Id != entityId))
166  return;
167 
168 
169  report.TeacherReportsScientificWorks = report.TeacherReportsScientificWorks
170  .Where(u => u.ScientificWork.Id != entityId).ToList();
171  UpdateItem(report);
172  }
173 
174  public void AddReportThesis(Guid id, Guid entityId)
175  {
176  var report = GetById(id);
177  var entity = _reportThesisRepository.Get(entityId);
178  if (report.TeacherReportsReportThesis.Any(u => u.ReportThesis.Id == entityId))
179  return;
180 
181  report.TeacherReportsReportThesis.Add(new TeacherReportsReportThesis
182  {
183  TeacherReport = report,
184  ReportThesis = entity
185  });
186  UpdateItem(report);
187  }
188 
189  public void RemoveReportThesis(Guid id, Guid entityId)
190  {
191  var report = _teacherReportRepository.Get(id);
192  if (report.TeacherReportsReportThesis.All(u => u.ReportThesis.Id != entityId))
193  return;
194 
195 
196  report.TeacherReportsReportThesis = report.TeacherReportsReportThesis
197  .Where(u => u.ReportThesis.Id != entityId).ToList();
198  UpdateItem(report);
199  }
200 
201  public void AddGrant(Guid id, Guid entityId)
202  {
203  var report = GetById(id);
204  var entity = _grantRepository.Get(entityId);
205  if (report.TeacherReportsGrants.Any(u => u.Grant.Id == entityId))
206  return;
207 
208  report.TeacherReportsGrants.Add(new TeacherReportsGrants
209  {
210  TeacherReport = report,
211  Grant = entity
212  });
213  UpdateItem(report);
214  }
215 
216  public void RemoveGrant(Guid id, Guid entityId)
217  {
218  var report = _teacherReportRepository.Get(id);
219  if (report.TeacherReportsGrants.All(u => u.Grant.Id != entityId))
220  return;
221 
222 
223  report.TeacherReportsGrants = report.TeacherReportsGrants
224  .Where(u => u.Grant.Id != entityId).ToList();
225  UpdateItem(report);
226  }
227 
228  public void AddScientificInternship(Guid id, Guid entityId)
229  {
230  var report = GetById(id);
231  var entity = _scientificInternshipRepository.Get(entityId);
232  if (report.TeacherReportsScientificInternships.Any(u => u.ScientificInternship.Id == entityId))
233  return;
234 
235  report.TeacherReportsScientificInternships.Add(new TeacherReportsScientificInternships
236  {
237  TeacherReport = report,
238  ScientificInternship = entity
239  });
240  UpdateItem(report);
241  }
242 
243  public void RemoveScientificInternship(Guid id, Guid entityId)
244  {
245  var report = _teacherReportRepository.Get(id);
246  if (report.TeacherReportsScientificInternships.All(u => u.ScientificInternship.Id != entityId))
247  return;
248 
249 
250  report.TeacherReportsScientificInternships = report.TeacherReportsScientificInternships
251  .Where(u => u.ScientificInternship.Id != entityId).ToList();
252  UpdateItem(report);
253  }
254 
255  public void AddPostgraduateGuidance(Guid id, Guid entityId)
256  {
257  var report = GetById(id);
258  var entity = _postgraduateGuidanceRepository.Get(entityId);
259  if (report.TeacherReportsPostgraduateGuidances.Any(u => u.PostgraduateGuidance.Id == entityId))
260  return;
261 
262  report.TeacherReportsPostgraduateGuidances.Add(new TeacherReportsPostgraduateGuidances
263  {
264  TeacherReport = report,
265  PostgraduateGuidance = entity
266  });
267  UpdateItem(report);
268  }
269 
270  public void RemovePostgraduateGuidance(Guid id, Guid entityId)
271  {
272  var report = _teacherReportRepository.Get(id);
273  if (report.TeacherReportsPostgraduateGuidances.All(u => u.PostgraduateGuidance.Id != entityId))
274  return;
275 
276 
277  report.TeacherReportsPostgraduateGuidances = report.TeacherReportsPostgraduateGuidances
278  .Where(u => u.PostgraduateGuidance.Id != entityId).ToList();
279  UpdateItem(report);
280  }
281 
282  public void AddScientificConsultation(Guid id, Guid entityId)
283  {
284  var report = GetById(id);
285  var entity = _scientificConsultationRepository.Get(entityId);
286  if (report.TeacherReportsScientificConsultations.Any(u => u.ScientificConsultation.Id == entityId))
287  return;
288 
289  report.TeacherReportsScientificConsultations.Add(new TeacherReportsScientificConsultations
290  {
291  TeacherReport = report,
292  ScientificConsultation = entity
293  });
294  UpdateItem(report);
295  }
296 
297  public void RemoveScientificConsultation(Guid id, Guid entityId)
298  {
299  var report = _teacherReportRepository.Get(id);
300  if (report.TeacherReportsScientificConsultations.All(u => u.ScientificConsultation.Id != entityId))
301  return;
302 
303 
304  report.TeacherReportsScientificConsultations = report.TeacherReportsScientificConsultations
305  .Where(u => u.ScientificConsultation.Id != entityId).ToList();
306  UpdateItem(report);
307  }
308 
309  public void AddPostgraduateDissertationGuidance(Guid id, Guid entityId)
310  {
311  var report = GetById(id);
312  var entity = _postgraduateDissertationGuidanceRepository.Get(entityId);
313  if (report.TeacherReportsPostgraduateDissertationGuidances.Any(u =>
314  u.PostgraduateDissertationGuidance.Id == entityId))
315  return;
316 
317  report.TeacherReportsPostgraduateDissertationGuidances.Add(
319  {
320  TeacherReport = report,
321  PostgraduateDissertationGuidance = entity
322  });
323  UpdateItem(report);
324  }
325 
326  public void RemovePostgraduateDissertationGuidance(Guid id, Guid entityId)
327  {
328  var report = _teacherReportRepository.Get(id);
329  if (report.TeacherReportsPostgraduateDissertationGuidances.All(u =>
330  u.PostgraduateDissertationGuidance.Id != entityId))
331  return;
332 
333 
334  report.TeacherReportsPostgraduateDissertationGuidances = report
335  .TeacherReportsPostgraduateDissertationGuidances
336  .Where(u => u.PostgraduateDissertationGuidance.Id != entityId).ToList();
337  UpdateItem(report);
338  }
339 
340  public void AddReview(Guid id, Guid entityId)
341  {
342  var report = GetById(id);
343  var entity = _reviewRepository.Get(entityId);
344  if (report.TeacherReportsReviews.Any(u => u.Review.Id == entityId))
345  return;
346 
347  report.TeacherReportsReviews.Add(new TeacherReportsReviews
348  {
349  TeacherReport = report,
350  Review = entity
351  });
352  UpdateItem(report);
353  }
354 
355  public void RemoveReview(Guid id, Guid entityId)
356  {
357  var report = _teacherReportRepository.Get(id);
358  if (report.TeacherReportsReviews.All(u => u.Review.Id != entityId))
359  return;
360 
361 
362  report.TeacherReportsReviews = report.TeacherReportsReviews
363  .Where(u => u.Review.Id != entityId).ToList();
364  UpdateItem(report);
365  }
366 
367  public void AddOpposition(Guid id, Guid entityId)
368  {
369  var report = GetById(id);
370  var entity = _oppositionRepository.Get(entityId);
371  if (report.TeacherReportsOppositions.Any(u => u.Opposition.Id == entityId))
372  return;
373 
374  report.TeacherReportsOppositions.Add(new TeacherReportsOppositions
375  {
376  TeacherReport = report,
377  Opposition = entity
378  });
379  UpdateItem(report);
380  }
381 
382  public void RemoveOpposition(Guid id, Guid entityId)
383  {
384  var report = _teacherReportRepository.Get(id);
385  if (report.TeacherReportsOppositions.All(u => u.Opposition.Id != entityId))
386  return;
387 
388 
389  report.TeacherReportsOppositions = report.TeacherReportsOppositions
390  .Where(u => u.Opposition.Id != entityId).ToList();
391  UpdateItem(report);
392  }
393 
394  public void AddPatent(Guid id, Guid entityId)
395  {
396  var report = GetById(id);
397  var entity = _patentRepository.Get(entityId);
398  if (report.TeacherReportsPatents.Any(u => u.Patent.Id == entityId))
399  return;
400 
401  report.TeacherReportsPatents.Add(new TeacherReportsPatents
402  {
403  TeacherReport = report,
404  Patent = entity
405  });
406  UpdateItem(report);
407  }
408 
409  public void RemovePatent(Guid id, Guid entityId)
410  {
411  var report = _teacherReportRepository.Get(id);
412  if (report.TeacherReportsPatents.All(u => u.Patent.Id != entityId))
413  return;
414 
415 
416  report.TeacherReportsPatents = report.TeacherReportsPatents
417  .Where(u => u.Patent.Id != entityId).ToList();
418  UpdateItem(report);
419  }
420 
421  public void AddMembership(Guid id, Guid entityId)
422  {
423  var report = GetById(id);
424  var entity = _membershipRepository.Get(entityId);
425  if (report.TeacherReportsMemberships.Any(u => u.Membership.Id == entityId))
426  return;
427 
428  report.TeacherReportsMemberships.Add(new TeacherReportsMemberships
429  {
430  TeacherReport = report,
431  Membership = entity
432  });
433  UpdateItem(report);
434  }
435 
436  public void RemoveMembership(Guid id, Guid entityId)
437  {
438  var report = _teacherReportRepository.Get(id);
439  if (report.TeacherReportsMemberships.All(u => u.Membership.Id != entityId))
440  return;
441 
442 
443  report.TeacherReportsMemberships = report.TeacherReportsMemberships
444  .Where(u => u.Membership.Id != entityId).ToList();
445  UpdateItem(report);
446  }
447 
448  }
449 }
virtual IEnumerable< TeacherReport > GetAll()
virtual IEnumerable< TeacherReport > GetAllWhere(Func< TeacherReport, bool > predicate)
TeacherReportService(ScientificReportDbContext context)
virtual TeacherReport Get(Func< TeacherReport, bool > predicate)
virtual bool Any(Func< TeacherReport, bool > predicate)
void AddPostgraduateDissertationGuidance(Guid id, Guid entityId)
void RemovePostgraduateDissertationGuidance(Guid id, Guid entityId)