Exemple #1
0
        /// <summary>
        /// 群组成员申请实体
        /// </summary>
        public static GroupMemberApply New()
        {
            GroupMemberApply groupMemberApplie = new GroupMemberApply()
            {
                ApplyReason = string.Empty,
                ApplyDate   = DateTime.UtcNow
            };

            return(groupMemberApplie);
        }
Exemple #2
0
        /// <summary>
        /// 删除群组加入申请
        /// </summary>
        /// <param name="id">申请Id</param>
        public void DeleteGroupMemberApply(long id)
        {
            GroupMemberApply apply = groupMemberApplyRepository.Get(id);

            if (apply == null)
            {
                return;
            }

            int affectCount = groupMemberApplyRepository.Delete(apply);

            if (affectCount > 0)
            {
                EventBus <GroupMemberApply> .Instance().OnAfter(apply, new CommonEventArgs(EventOperationType.Instance().Delete()));
            }
        }
Exemple #3
0
        /// <summary>
        /// 申请加入群组
        /// </summary>
        /// <param name="groupMemberApply">群组加入申请</param>
        public void CreateGroupMemberApply(GroupMemberApply groupMemberApply)
        {
            //设计要点:
            //1、用户对同一个群组不允许有多个待处理的加入申请


            if (groupMemberApply == null)
            {
                return;
            }
            if (IsApplied(groupMemberApply.UserId, groupMemberApply.GroupId))
            {
                return;
            }
            long id = 0;

            long.TryParse(groupMemberApplyRepository.Insert(groupMemberApply).ToString(), out id);

            if (id > 0)
            {
                EventBus <GroupMemberApply> .Instance().OnAfter(groupMemberApply, new CommonEventArgs(EventOperationType.Instance().Create()));
            }
        }
Exemple #4
0
 /// <summary>
 /// 群组成员申请实体
 /// </summary>
 public static GroupMemberApply New()
 {
     GroupMemberApply groupMemberApplie = new GroupMemberApply()
     {
         ApplyReason = string.Empty,
         ApplyDate = DateTime.UtcNow
     };
     return groupMemberApplie;
 }
        /// <summary>
        /// 申请加入群组
        /// </summary>
        /// <param name="groupMemberApply">群组加入申请</param>
        public void CreateGroupMemberApply(GroupMemberApply groupMemberApply)
        {
            //设计要点:
            //1、用户对同一个群组不允许有多个待处理的加入申请


            if (groupMemberApply == null)
                return;
            if (IsApplied(groupMemberApply.UserId, groupMemberApply.GroupId))
                return;
            long id = 0;
            long.TryParse(groupMemberApplyRepository.Insert(groupMemberApply).ToString(), out id);

            if (id > 0)
                EventBus<GroupMemberApply>.Instance().OnAfter(groupMemberApply, new CommonEventArgs(EventOperationType.Instance().Create()));
        }
        /// <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);
        }