-
Notifications
You must be signed in to change notification settings - Fork 11
/
Comment.cs
212 lines (193 loc) · 8.9 KB
/
Comment.cs
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// <copyright file="Comment.cs" company="Engage Software">
// Engage: Publish
// Copyright (c) 2004-2013
// by Engage Software ( http://www.engagesoftware.com )
// </copyright>
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
namespace Engage.Dnn.Publish
{
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Xml.Serialization;
using Engage.Dnn.Publish.Data;
using Engage.Dnn.Publish.Util;
/// <summary>
/// A comment on an item, possibly tied to a <see cref="Rating"/>.
/// </summary>
[XmlRoot(ElementName = "Comment", IsNullable = false)]
public class Comment : UserFeedback.Comment
{
/// <summary>
/// Initializes a new instance of the <see cref="Comment"/> class.
/// </summary>
/// <param name="itemVersionId">The item version id.</param>
/// <param name="userId">The user id, or <c>null</c> is the user is unauthenticated.</param>
/// <param name="commentText">The comment itself.</param>
/// <param name="approvalStatusId">The approval status id.</param>
/// <param name="ratingId">This is not currently implemented. The rating id, or <c>null</c> if the <see cref="Comment"/> is not associated with a <see cref="Rating"/>. This is not currently implemented.</param>
/// <param name="firstName">First name of the commenter. Will be truncated if longer than <see cref="UserFeedback.Comment.NameSizeLimit"/>.</param>
/// <param name="lastName">Last name of the commenter. Will be truncated if longer than <see cref="UserFeedback.Comment.NameSizeLimit"/>.</param>
/// <param name="emailAddress">Email address of the commenter. Will be truncated if longer than <see cref="UserFeedback.Comment.EmailAddressSizeLimit"/>.</param>
/// <param name="url">URL of the commenter</param>
public Comment(
int itemVersionId,
int? userId,
string commentText,
int approvalStatusId,
int? ratingId,
string firstName,
string lastName,
string emailAddress,
string url)
: base(itemVersionId, userId, commentText, approvalStatusId, ratingId, firstName, lastName, emailAddress, url)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Comment"/> class.
/// </summary>
public Comment()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Comment"/> class.
/// </summary>
/// <param name="commentId">The comment id.</param>
/// <param name="itemVersionId">The item version id.</param>
/// <param name="itemVersionId">The item version id.</param>
/// <param name="userId">The user id.</param>
/// <param name="commentText">The comment text.</param>
/// <param name="approvalStatusId">The approval status id.</param>
/// <param name="createdDate">The created date.</param>
/// <param name="lastUpdated">The last updated.</param>
/// <param name="ratingId">This is not currently implemented. The id of the <see cref="Rating"/> associated with this <see cref="Comment"/>.</param>
/// <param name="firstName">First name of the commenter. Will be truncated if longer than <see cref="UserFeedback.Comment.NameSizeLimit"/>.</param>
/// <param name="lastName">Last name of the commenter. Will be truncated if longer than <see cref="UserFeedback.Comment.NameSizeLimit"/>.</param>
/// <param name="emailAddress">Email address of the commenter. Will be truncated if longer than <see cref="UserFeedback.Comment.EmailAddressSizeLimit"/>.</param>
/// <param name="url">URL of the commenter</param>
private Comment(
int commentId,
int itemVersionId,
int? userId,
string commentText,
int approvalStatusId,
DateTime createdDate,
DateTime lastUpdated,
int? ratingId,
string firstName,
string lastName,
string emailAddress,
string url)
: base(
commentId,
itemVersionId,
userId,
commentText,
approvalStatusId,
createdDate,
lastUpdated,
ratingId,
firstName,
lastName,
emailAddress,
url)
{
}
public static int CommentsWaitingForApprovalCount(int portalId, int authorUserId)
{
string cacheKey = Utility.CacheKeyPublishAuthorCommentCount + authorUserId.ToString(CultureInfo.InvariantCulture) + "_" + portalId;
return Utility.GetValueFromCache(
portalId,
cacheKey,
() => DataProvider.Instance().CommentsWaitingForApprovalCount(portalId, authorUserId));
}
/// <summary>
/// Gets all comments for an <see cref="Item"/> of a particular <see cref="ApprovalStatus"/>.
/// </summary>
/// <param name="itemId">The item id.</param>
/// <param name="approvalStatusId">The approval status id.</param>
/// <returns>A <see cref="List{Comment}"/> filled with all Comments of the specified <see cref="ApprovalStatus"/> for the specified <see cref="Item"/></returns>
[SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists", Justification = "Not intended to be a reusable library.")]
public static List<UserFeedback.Comment> GetCommentsByItemId(int itemId, int approvalStatusId)
{
IDataReader dr = DataProvider.Instance().GetComments(itemId, approvalStatusId);
var comments = new List<UserFeedback.Comment>();
while (dr.Read())
{
comments.Add(FillComment(dr));
}
return comments;
}
/// <summary>
/// Deletes this instance.
/// </summary>
public void Delete()
{
this.Delete(DataProvider.ModuleQualifier);
}
/// <summary>
/// Saves this instance.
/// </summary>
public void Save()
{
this.Save(DataProvider.ModuleQualifier);
}
/// <summary>
/// Fills a <see cref="Comment"/> from an <see cref="IDataReader"/>.
/// </summary>
/// <param name="dr">An <see cref="IDataReader"/> filled with information needed to fill a <see cref="Comment"/>.</param>
/// <returns>The instantiated <see cref="Comment"/>.</returns>
private static UserFeedback.Comment FillComment(IDataRecord dr)
{
int? userId = null;
int? ratingId = null;
string firstName = null;
string lastName = null;
string emailAddress = null;
string url = null;
if (!dr.IsDBNull(dr.GetOrdinal("userId")))
{
userId = (int)dr["userId"];
}
if (!dr.IsDBNull(dr.GetOrdinal("ratingId")))
{
ratingId = (int)dr["ratingId"];
}
if (!dr.IsDBNull(dr.GetOrdinal("firstName")))
{
firstName = dr["firstName"].ToString();
}
if (!dr.IsDBNull(dr.GetOrdinal("lastName")))
{
lastName = dr["lastName"].ToString();
}
if (!dr.IsDBNull(dr.GetOrdinal("emailAddress")))
{
emailAddress = dr["emailAddress"].ToString();
}
if (!dr.IsDBNull(dr.GetOrdinal("url")))
{
url = dr["url"].ToString();
}
return new Comment(
(int)dr["commentId"],
(int)dr["itemVersionId"],
userId,
(string)dr["commentText"],
(int)dr["approvalStatusId"],
Convert.ToDateTime(dr["createdDate"], CultureInfo.InvariantCulture),
Convert.ToDateTime(dr["lastUpdated"], CultureInfo.InvariantCulture),
ratingId,
firstName,
lastName,
emailAddress,
url);
}
}
}