private void SaveMessageNotifications(long messageId, int userId, out string error) { error = string.Empty; try { //followers notification //var followers = FollowerRepository.GetMany(x => x.ClassRoomId == roomId && x.FollowerId != userId).ToList(); //foreach (var follower in followers) //{ // _notificationServices.SaveNotification(follower.FollowerId, messageId, out error); //} //message users notifications var users = DiscussionMessageUserRepository.GetMany(x => x.MessageId == messageId).ToList(); foreach (var user in users.Where(user => user.UserId != userId)) { _SaveNotification(user.UserId, messageId, out error); } } catch (Exception ex) { error = Utils.FormatError(ex); Logger.Error("save message notification", messageId, ex, CommonEnums.LoggerObjectTypes.Discussion); } }
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); } }
private bool SaveMessageUsers(IEnumerable <string> names, long messageId, out string error) { error = string.Empty; try { foreach (var name in names.Distinct()) { if (String.IsNullOrEmpty(name) || name.Length == 1) { continue; } var userIdStr = name.Substring(1); int userId; var parsed = int.TryParse(userIdStr, out userId); if (!parsed) { continue; } var entity = UserRepository.GetById(userId); if (entity == null) { continue; } if (DiscussionMessageUserRepository.IsAny(x => x.MessageId == messageId && x.UserId == userId)) { continue; } DiscussionMessageUserRepository.Add(new DSC_MessageUsers { MessageId = messageId , UserId = userId }); } DiscussionMessageUserRepository.UnitOfWork.CommitAndRefreshChanges(); return(true); } catch (Exception ex) { DiscussionMessageUserRepository.UnitOfWork.RollbackChanges(); error = Utils.FormatError(ex); Logger.Error("SaveMessageUsers", messageId, ex, CommonEnums.LoggerObjectTypes.Discussion); return(false); } }