Пример #1
0
        private bool SaveMessageHtml(long messageId, string template, out string error)
        {
            error = string.Empty;
            try
            {
                var messageEntity = DiscussionMessageRepository.GetById(messageId);

                if (messageEntity == null)
                {
                    error = "message entity not found";
                    return(false);
                }

                var original  = messageEntity.Text;
                var html      = original;
                var emailHtml = original;
                //tags
                var tags = DiscussionMessageHashtagViewRepository.GetMany(x => x.MessageId == messageId);

                foreach (var tag in tags)
                {
                    var link = String.Format(template, messageEntity.Uid, tag.HashtagId, eFeedFilterKinds.Hashtag, "#", tag.HashTag);
                    html = html.Replace("#" + tag.HashTag, link);

                    link      = tag.HashTag.String2Html(HASHTAG_URL_TEMPLATE, HASHTAG_HTML_STYLE_UNDERLINE, tag.HashTag.Replace("#", ""));
                    emailHtml = emailHtml.Replace(tag.HashTag, link);
                }

                //users
                var users = DiscussionMessageUserRepository.GetMany(x => x.MessageId == messageId);

                foreach (var row in users)
                {
                    var user = UserRepository.GetById(row.UserId).Entity2TagItemDto();
                    var link = String.Format(template, messageEntity.Uid, user.value, eFeedFilterKinds.User, "@", user.label);
                    html = html.Replace("@" + user.label, link);

                    link      = user.label.String2Html(USER_PROFILE_URL_TEMPLATE, NAME_HTML_STYLE_UNDERLINE, user.value);
                    emailHtml = emailHtml.Replace("@" + user.label, link);
                }

                messageEntity.HtmlMessage      = html;
                messageEntity.HtmlEmailMessage = emailHtml;
                messageEntity.HtmlVersion      = CURRENT_MSG_HTML_VERSION;

                DiscussionMessageRepository.UnitOfWork.CommitAndRefreshChanges();

                return(true);
            }
            catch (Exception ex)
            {
                error = Utils.FormatError(ex);
                Logger.Error("SaveMessageHtml", messageId, ex, CommonEnums.LoggerObjectTypes.Discussion);
                return(false);
            }
        }
Пример #2
0
        private void SaveReplayMessageNotifications(long messageId, long parentId, out string error)
        {
            try
            {
                var userId = DiscussionMessageRepository.GetById(parentId).CreatedBy;

                _SaveNotification(userId, messageId, out error);
            }
            catch (Exception ex)
            {
                error = Utils.FormatError(ex);
                Logger.Error("save replay message notification", messageId, ex, CommonEnums.LoggerObjectTypes.Discussion);
            }
        }