2009-11-19 23:59:24 +00:00
|
|
|
|
using System.Collections.Generic;
|
2009-11-19 21:58:48 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Orchard.Comments.Models;
|
|
|
|
|
using Orchard.Data;
|
|
|
|
|
using Orchard.Logging;
|
2009-11-21 03:53:55 +00:00
|
|
|
|
using Orchard.Models;
|
2009-11-19 23:59:24 +00:00
|
|
|
|
using Orchard.Security;
|
|
|
|
|
using Orchard.Settings;
|
|
|
|
|
using Orchard.UI.Notify;
|
2009-11-19 21:58:48 +00:00
|
|
|
|
|
|
|
|
|
namespace Orchard.Comments.Services {
|
|
|
|
|
public interface ICommentService : IDependency {
|
|
|
|
|
IEnumerable<Comment> GetComments();
|
|
|
|
|
IEnumerable<Comment> GetComments(CommentStatus status);
|
|
|
|
|
Comment GetComment(int id);
|
2009-11-21 03:53:55 +00:00
|
|
|
|
IContentItemDisplay GetDisplayForCommentedContent(int id);
|
2009-11-19 23:59:24 +00:00
|
|
|
|
void CreateComment(Comment comment);
|
2009-11-19 21:58:48 +00:00
|
|
|
|
void MarkCommentAsSpam(int commentId);
|
|
|
|
|
void DeleteComment(int commentId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class CommentService : ICommentService {
|
|
|
|
|
private readonly IRepository<Comment> _commentRepository;
|
2009-11-19 23:59:24 +00:00
|
|
|
|
private readonly ICommentValidator _commentValidator;
|
2009-11-21 03:53:55 +00:00
|
|
|
|
private readonly IContentManager _contentManager;
|
2009-11-19 23:59:24 +00:00
|
|
|
|
private readonly IAuthorizer _authorizer;
|
|
|
|
|
private readonly INotifier _notifier;
|
2009-11-19 21:58:48 +00:00
|
|
|
|
|
2009-11-21 03:53:55 +00:00
|
|
|
|
public CommentService(IRepository<Comment> commentRepository,
|
|
|
|
|
ICommentValidator commentValidator,
|
|
|
|
|
IContentManager contentManager,
|
|
|
|
|
IAuthorizer authorizer,
|
|
|
|
|
INotifier notifier) {
|
2009-11-19 21:58:48 +00:00
|
|
|
|
_commentRepository = commentRepository;
|
2009-11-19 23:59:24 +00:00
|
|
|
|
_commentValidator = commentValidator;
|
2009-11-21 03:53:55 +00:00
|
|
|
|
_contentManager = contentManager;
|
2009-11-19 23:59:24 +00:00
|
|
|
|
_authorizer = authorizer;
|
|
|
|
|
_notifier = notifier;
|
2009-11-19 21:58:48 +00:00
|
|
|
|
Logger = NullLogger.Instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ILogger Logger { get; set; }
|
2009-11-19 23:59:24 +00:00
|
|
|
|
public ISite CurrentSite { get; set; }
|
2009-11-19 21:58:48 +00:00
|
|
|
|
|
|
|
|
|
#region Implementation of ICommentService
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Comment> GetComments() {
|
|
|
|
|
return from comment in _commentRepository.Table.ToList() select comment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Comment> GetComments(CommentStatus status) {
|
2009-11-19 23:59:24 +00:00
|
|
|
|
return from comment in _commentRepository.Table.ToList() where comment.Status == status select comment;
|
2009-11-19 21:58:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Comment GetComment(int id) {
|
|
|
|
|
return _commentRepository.Get(id);
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-21 03:53:55 +00:00
|
|
|
|
public IContentItemDisplay GetDisplayForCommentedContent(int id) {
|
|
|
|
|
return _contentManager.Get(id).As<IContentItemDisplay>();
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-19 23:59:24 +00:00
|
|
|
|
public void CreateComment(Comment comment) {
|
|
|
|
|
comment.Status = _commentValidator.ValidateComment(comment) ? CommentStatus.Approved : CommentStatus.Spam;
|
|
|
|
|
_commentRepository.Create(comment);
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-19 21:58:48 +00:00
|
|
|
|
public void MarkCommentAsSpam(int commentId) {
|
|
|
|
|
Comment comment = GetComment(commentId);
|
|
|
|
|
comment.Status = CommentStatus.Spam;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DeleteComment(int commentId) {
|
|
|
|
|
_commentRepository.Delete(GetComment(commentId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|