Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the CommentService class.
 /// </summary>
 /// <param name="contentCommentsRepository">Instance of ContentComments repository</param>
 public CommentService(IContentCommentsRepository contentCommentsRepository, ICommunityCommentRepository communityCommentRepository)
 {
     this._contentCommentsRepository  = contentCommentsRepository;
     this._communityCommentRepository = communityCommentRepository;
 }
        public static EmailRequest UpdateFrom(this EmailRequest thisObject, EntityCommentRequest request)
        {
            if (thisObject == null)
            {
                thisObject = new EmailRequest();
            }

            ICommunityRepository communityRepository = DependencyResolver.Current.GetService(typeof(ICommunityRepository)) as ICommunityRepository;
            IContentRepository   contentRepository   = DependencyResolver.Current.GetService(typeof(IContentRepository)) as IContentRepository;

            IEnumerable <User> contributors = new List <User>();
            IEnumerable <User> commenters   = new List <User>();

            string entityName = string.Empty;

            if (request.EntityType == EntityType.Content)
            {
                Content content = contentRepository.GetItem(c => c.ContentID == request.ID);
                if (content != null)
                {
                    if (content.CommunityContents.Count > 0)
                    {
                        contributors = communityRepository.GetContributors(Enumerable.ElementAt <CommunityContents>(content.CommunityContents, 0).CommunityID);
                    }

                    contributors.Concat(new[] { content.User });
                    entityName = content.Title;
                }

                IContentCommentsRepository contentCommentsRepository = DependencyResolver.Current.GetService(typeof(IContentCommentsRepository)) as IContentCommentsRepository;
                commenters = contentCommentsRepository.GetCommenters(request.ID);
            }
            else
            {
                contributors = communityRepository.GetContributors(request.ID);
                Community community = communityRepository.GetItem(c => c.CommunityID == request.ID);
                if (community != null)
                {
                    entityName = community.Name;
                }

                ICommunityCommentRepository communityCommentRepository = DependencyResolver.Current.GetService(typeof(ICommunityCommentRepository)) as ICommunityCommentRepository;
                commenters = communityCommentRepository.GetCommenters(request.ID);
            }

            List <User> recipients = new List <User>();

            if (contributors != null && contributors.Count() > 0)
            {
                recipients.AddRange(contributors);
            }

            if (commenters != null && commenters.Count() > 0)
            {
                recipients.AddRange(commenters.Where(p => !contributors.Any(x => x.UserID.Equals(p.UserID))));
            }

            foreach (User user in recipients)
            {
                if (user.IsSubscribed && user.UserID != request.UserID)
                {
                    thisObject.Recipients.Add(new MailAddress(user.Email.FixEmailAddress(), user.FirstName + " " + user.LastName));
                }
            }

            IUserRepository userRepository = DependencyResolver.Current.GetService(typeof(IUserRepository)) as IUserRepository;
            User            requestor      = userRepository.GetItem(u => u.UserID == request.UserID);

            thisObject.IsHtml = true;

            // Update the body and the subject.
            thisObject.Subject = string.Format(CultureInfo.CurrentUICulture, "{0} has commented on the Layerscape {1} \"{2}\"", requestor.GetFullName(), request.EntityType.ToString().ToLower(), entityName);

            var replacements = new Dictionary <string, string>
            {
                { "@@RecipientName@@", string.Empty },
                { "@@Type@@", HttpUtility.UrlDecode(request.EntityType.ToString().ToLower()) },
                { "@@Name@@", HttpUtility.UrlDecode(entityName) },
                { "@@Link@@", HttpUtility.UrlDecode(request.Link) },
                { "@@UserName@@", HttpUtility.UrlDecode(requestor.GetFullName()) },
                { "@@UserLink@@", HttpUtility.UrlDecode(request.UserLink) },
                { "@@UserComments@@", HttpUtility.UrlDecode(request.UserComments) },
            };

            thisObject.MessageBody = FormatMailBodyUsingTemplate("entitycommentrequest.html", replacements);

            return(thisObject);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the CommentService class.
 /// </summary>
 /// <param name="contentCommentsRepository">Instance of ContentComments repository</param>
 public CommentService(IContentCommentsRepository contentCommentsRepository, ICommunityCommentRepository communityCommentRepository)
 {
     this._contentCommentsRepository = contentCommentsRepository;
     this._communityCommentRepository = communityCommentRepository;
 }