forked from grandnode/grandnode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTopicTemplateService.cs
More file actions
114 lines (94 loc) · 3.44 KB
/
Copy pathTopicTemplateService.cs
File metadata and controls
114 lines (94 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using Grand.Core.Data;
using Grand.Core.Domain.Topics;
using Grand.Services.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using MediatR;
namespace Grand.Services.Topics
{
/// <summary>
/// Topic template service
/// </summary>
public partial class TopicTemplateService : ITopicTemplateService
{
#region Fields
private readonly IRepository<TopicTemplate> _topicTemplateRepository;
private readonly IMediator _mediator;
#endregion
#region Ctor
/// <summary>
/// Ctor
/// </summary>
/// <param name="topicTemplateRepository">Topic template repository</param>
/// <param name="eventPublisher">Event published</param>
public TopicTemplateService(IRepository<TopicTemplate> topicTemplateRepository,
IMediator mediator)
{
this._topicTemplateRepository = topicTemplateRepository;
this._mediator = mediator;
}
#endregion
#region Methods
/// <summary>
/// Delete topic template
/// </summary>
/// <param name="topicTemplate">Topic template</param>
public virtual async Task DeleteTopicTemplate(TopicTemplate topicTemplate)
{
if (topicTemplate == null)
throw new ArgumentNullException("topicTemplate");
await _topicTemplateRepository.DeleteAsync(topicTemplate);
//event notification
await _mediator.EntityDeleted(topicTemplate);
}
/// <summary>
/// Gets all topic templates
/// </summary>
/// <returns>Topic templates</returns>
public virtual async Task<IList<TopicTemplate>> GetAllTopicTemplates()
{
var query = from pt in _topicTemplateRepository.Table
orderby pt.DisplayOrder
select pt;
return await query.ToListAsync();
}
/// <summary>
/// Gets a topic template
/// </summary>
/// <param name="topicTemplateId">Topic template identifier</param>
/// <returns>Topic template</returns>
public virtual Task<TopicTemplate> GetTopicTemplateById(string topicTemplateId)
{
return _topicTemplateRepository.GetByIdAsync(topicTemplateId);
}
/// <summary>
/// Inserts topic template
/// </summary>
/// <param name="topicTemplate">Topic template</param>
public virtual async Task InsertTopicTemplate(TopicTemplate topicTemplate)
{
if (topicTemplate == null)
throw new ArgumentNullException("topicTemplate");
await _topicTemplateRepository.InsertAsync(topicTemplate);
//event notification
await _mediator.EntityInserted(topicTemplate);
}
/// <summary>
/// Updates the topic template
/// </summary>
/// <param name="topicTemplate">Topic template</param>
public virtual async Task UpdateTopicTemplate(TopicTemplate topicTemplate)
{
if (topicTemplate == null)
throw new ArgumentNullException("topicTemplate");
await _topicTemplateRepository.UpdateAsync(topicTemplate);
//event notification
await _mediator.EntityUpdated(topicTemplate);
}
#endregion
}
}