/// <summary> /// 用户解除管制后增加邀请人积分 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> void FreeModeratedUser_After(User sender, CommonEventArgs eventArgs) { if (sender == null || string.IsNullOrEmpty(eventArgs.EventOperationType)) { return; } if (eventArgs.EventOperationType == EventOperationType.Instance().CancelModerateUser() || eventArgs.EventOperationType == EventOperationType.Instance().AutoNoModeratedUser()) { PointService pointService = new PointService(); string pointItemKey = string.Empty; pointItemKey = PointItemKeys.Instance().FreeModeratedUser(); if (sender != null) { InviteFriendRecord invitingUser = inviteFriendService.GetInvitingUserId(sender.UserId); if (invitingUser != null) { if (!invitingUser.InvitingUserHasBeingRewarded) { string userName = UserIdToUserNameDictionary.GetUserName(invitingUser.UserId); string invitedName = UserIdToUserNameDictionary.GetUserName(sender.UserId); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_FreeModeratedUser"), userName, invitedName); pointService.GenerateByRole(invitingUser.UserId, pointItemKey, description); inviteFriendService.RewardingUser(invitingUser.UserId); } } } } }
/// <summary> /// 转换成数据库存储的评论对象 /// </summary> /// <returns></returns> public Comment AsComment() { bool notLogin = UserContext.CurrentUser == null; Comment comment = Comment.New(); comment.ParentId = this.ParentId; comment.CommentedObjectId = this.CommentedObjectId; comment.OwnerId = this.OwnerId; comment.TenantTypeId = this.TenantTypeId; comment.Subject = this.Subject ?? string.Empty; //this.Body = WebUtility.HtmlEncode(this.Body); //comment.Body = new EmotionService().EmoticonTransforms(this.Body); comment.Body = this.Body; comment.IsPrivate = this.IsPrivate; comment.ChildCount = 0; comment.IsAnonymous = notLogin; comment.ToUserDisplayName = this.ToUserId <= 0 ? string.Empty : UserIdToUserNameDictionary.GetUserName(this.ToUserId); comment.ToUserId = this.ToUserId; comment.UserId = notLogin ? 0 : UserContext.CurrentUser.UserId; comment.AuditStatus = AuditStatus.Success; comment.Author = notLogin ? this.Author : UserContext.CurrentUser.DisplayName; comment.Contact = notLogin ? this.Contact : string.Empty; return(comment); }
/// <summary> /// 创建邀请记录之后的方法 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> void CreateInviteFriendRecordEventModule_After(InviteFriendRecord sender, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { PointService pointService = new PointService(); string userName = UserIdToUserNameDictionary.GetUserName(sender.UserId); string invitedName = UserIdToUserNameDictionary.GetUserName(sender.InvitedUserId); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_CreateInviteFriendRecord"), userName, invitedName); pointService.GenerateByRole(sender.UserId, PointItemKeys.Instance().InviteUserRegister(), description, true); } }
/// <summary> /// 删除用户 /// </summary> /// <param name="userId">用户Id</param> /// <param name="takeOverUserName">用于接管删除用户的内容(例如:用户创建的群组)</param> /// <param name="takeOverAll">是否接管被删除用户的所有内容</param> /// <remarks>接管被删除用户的所有内容</remarks> /// <returns></returns> public UserDeleteStatus DeleteUser(long userId, string takeOverUserName, bool takeOverAll) { User user = userRepository.Get(userId); if (user == null) { return(UserDeleteStatus.DeletingUserNotFound); } if (takeOverAll) { long takeOverUserId = userRepository.GetUserIdByUserName(takeOverUserName); User takeOverUser = userRepository.Get(takeOverUserId); if (takeOverUser == null) { return(UserDeleteStatus.InvalidTakeOverUsername); } } if (!user.IsModerated && !user.IsForceModerated) { // 邀请用户被删除时扣除邀请人积分 PointService pointService = new PointService(); string pointItemKey = string.Empty; pointItemKey = PointItemKeys.Instance().DeleteInvitedUser(); InviteFriendRecord invitingUser = new InviteFriendService().GetInvitingUserId(user.UserId); if (invitingUser != null) { string userName = UserIdToUserNameDictionary.GetUserName(invitingUser.UserId); string invitedName = UserIdToUserNameDictionary.GetUserName(user.UserId); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_DeleteInvitedUser"), userName, invitedName); pointService.GenerateByRole(invitingUser.UserId, pointItemKey, description); } } EventBus <User, DeleteUserEventArgs> .Instance().OnBefore(user, new DeleteUserEventArgs(takeOverUserName, takeOverAll)); int affectCount = userRepository.Delete(user); if (affectCount > 0) { UserIdToUserNameDictionary.RemoveUserId(userId); UserIdToUserNameDictionary.RemoveUserName(user.UserName); EventBus <User, DeleteUserEventArgs> .Instance().OnAfter(user, new DeleteUserEventArgs(takeOverUserName, takeOverAll)); return(UserDeleteStatus.Deleted); } return(UserDeleteStatus.UnknownFailure); }
/// <summary> /// 处理地址 /// </summary> /// <param name="userId"></param> /// <returns></returns> public string GetProcessUrl(long userId) { return(SiteUrls.FullUrl(SiteUrls.Instance().ListMessageSessions(UserIdToUserNameDictionary.GetUserName(userId), null))); }
/// <summary> /// 通知处理 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> void CommentNoticeEventModule_After(Comment sender, AuditEventArgs eventArgs) { AuditService auditService = new AuditService(); bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) { var urlGetter = CommentUrlGetterFactory.Get(sender.TenantTypeId); var commentedObject = urlGetter.GetCommentedObject(sender.CommentedObjectId); var senderUser = sender.User(); if (urlGetter == null || commentedObject == null) { return; } //文章有新评论时,自动通知原作者 var toUserIds = new List <long>(); //评论相关的atuserid List <long> userids = new AtUserService(TenantTypeIds.Instance().Comment()).GetAtUserIds(sender.Id); if (!userids.Contains(commentedObject.UserId)) { toUserIds.Add(commentedObject.UserId); } if (sender.ParentId > 0 && !userids.Contains(sender.ToUserId)) { toUserIds.Add(sender.ToUserId); } foreach (var toUserId in toUserIds) { //通知的对象排除掉自己 if (toUserId == sender.UserId) { continue; } Notice notice = Notice.New(); notice.UserId = toUserId; notice.ApplicationId = 0; notice.TypeId = NoticeTypeIds.Instance().Reply(); notice.LeadingActor = senderUser != null ? senderUser.DisplayName : "匿名用户"; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(UserIdToUserNameDictionary.GetUserName(sender.UserId))); notice.RelativeObjectName = StringUtility.Trim(commentedObject.Name, 60); notice.RelativeObjectId = sender.Id; notice.RelativeObjectUrl = SiteUrls.FullUrl(urlGetter.GetCommentDetailUrl(sender.CommentedObjectId, sender.Id, commentedObject.UserId)) ?? string.Empty; notice.TemplateName = sender.ParentId > 0 ? NoticeTemplateNames.Instance().NewReply() : NoticeTemplateNames.Instance().NewComment(); new NoticeService().Create(notice); } } }
/// <summary> /// 处理地址 /// </summary> /// <param name="userId"></param> /// <returns></returns> public string GetProcessUrl(long userId) { return(SiteUrls.FullUrl(SiteUrls.Instance().ListNotices(UserIdToUserNameDictionary.GetUserName(userId), NoticeStatus.Unhandled, null))); }