public ActionResult _EditApply(long groupId, string applyReason) { StatusMessageData message = null; GroupEntity group = groupService.Get(groupId); if (group == null) { return(Json(new StatusMessageData(StatusMessageType.Error, "找不到群组!"))); } IUser currentUser = UserContext.CurrentUser; if (currentUser == null) { return(Json(new StatusMessageData(StatusMessageType.Error, "您尚未登录!"))); } if (group.JoinWay != JoinWay.ByApply) { return(Json(new StatusMessageData(StatusMessageType.Error, "当前加入方式不是需要申请"))); } //已修改 bool isApplied = groupService.IsApplied(currentUser.UserId, group.GroupId); if (!isApplied) { GroupMemberApply apply = GroupMemberApply.New(); apply.ApplyReason = applyReason; apply.ApplyStatus = GroupMemberApplyStatus.Pending; apply.GroupId = group.GroupId; apply.UserId = UserContext.CurrentUser.UserId; groupService.CreateGroupMemberApply(apply); message = new StatusMessageData(StatusMessageType.Success, "申请已发出,请等待!"); } else { message = new StatusMessageData(StatusMessageType.Hint, "您已给该群组发送过申请!"); } return(Json(message)); }
/// <summary> /// 通知处理程序 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void GroupMemberApplyNoticeModule_After(GroupMemberApply sender, CommonEventArgs eventArgs) { GroupService groupService = new GroupService(); GroupEntity entity = groupService.Get(sender.GroupId); if (entity == null) { return; } User senderUser = DIContainer.Resolve <IUserService>().GetFullUser(sender.UserId); if (senderUser == null) { return; } InvitationService invitationService = new InvitationService(); Invitation invitation; NoticeService noticeService = DIContainer.Resolve <NoticeService>(); Notice notice; if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { if (sender.ApplyStatus == GroupMemberApplyStatus.Pending) { List <long> toUserIds = new List <long>(); toUserIds.Add(entity.UserId); toUserIds.AddRange(entity.GroupManagers.Select(n => n.UserId)); foreach (var toUserId in toUserIds) { //申请加入群组的请求 if (!groupService.IsMember(sender.GroupId, sender.UserId)) { invitation = Invitation.New(); invitation.ApplicationId = GroupConfig.Instance().ApplicationId; invitation.InvitationTypeKey = InvitationTypeKeys.Instance().ApplyJoinGroup(); invitation.UserId = toUserId; invitation.SenderUserId = sender.UserId; invitation.Sender = senderUser.DisplayName; invitation.SenderUrl = SiteUrls.Instance().SpaceHome(sender.UserId); invitation.RelativeObjectId = sender.GroupId; invitation.RelativeObjectName = entity.GroupName; invitation.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().GroupHome(entity.GroupKey)); invitation.Remark = sender.ApplyReason; invitationService.Create(invitation); } } } } string noticeTemplateName = string.Empty; if (eventArgs.EventOperationType == EventOperationType.Instance().Approved()) { if (sender.ApplyStatus == GroupMemberApplyStatus.Approved) { noticeTemplateName = NoticeTemplateNames.Instance().MemberApplyApproved(); } } else if (eventArgs.EventOperationType == EventOperationType.Instance().Disapproved()) { if (sender.ApplyStatus == GroupMemberApplyStatus.Disapproved) { noticeTemplateName = NoticeTemplateNames.Instance().MemberApplyDisapproved(); } } if (string.IsNullOrEmpty(noticeTemplateName)) { return; } notice = Notice.New(); notice.UserId = sender.UserId; notice.ApplicationId = GroupConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); //notice.LeadingActorUserId = UserContext.CurrentUser.UserId; //notice.LeadingActor = UserContext.CurrentUser.DisplayName; //notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(UserContext.CurrentUser.UserId)); notice.RelativeObjectId = sender.GroupId; notice.RelativeObjectName = StringUtility.Trim(entity.GroupName, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().GroupHome(entity.GroupKey)); notice.TemplateName = noticeTemplateName; noticeService.Create(notice); }