public void JoinGroup(
            ManagedSecurityContext sec,
            string message)
        {
            ManagedAccountGroup group = new ManagedAccountGroup(Session, mInstance.AccountGroup);

            if (group.Instance.IsPrivate && !group.HasAdministratorAccount(mInstance.Requester.Id))
            {
                TransitAccountGroupAccountRequest t_request = new TransitAccountGroupAccountRequest();
                t_request.AccountGroupId = mInstance.AccountGroup.Id;
                t_request.AccountId      = mInstance.Account.Id;
                t_request.Message        = string.Format("{0} invited {1} to \"{2}\". " +
                                                         "The invitation was accepted and needs to be approved by the group administrator.\n{3}",
                                                         mInstance.Requester.Name, mInstance.Account.Name, mInstance.AccountGroup.Name, message);
                t_request.Submitted = DateTime.UtcNow;

                ManagedAccountGroupAccountRequest m_request = new ManagedAccountGroupAccountRequest(Session);
                m_request.CreateOrUpdate(t_request, sec);
            }
            else
            {
                TransitAccountGroupAccount t_account = new TransitAccountGroupAccount();
                t_account.AccountId      = mInstance.Account.Id;
                t_account.AccountGroupId = mInstance.AccountGroup.Id;
                t_account.Created        = t_account.Modified = DateTime.UtcNow;
                ManagedAccountGroupAccount m_accountgroupaccount = new ManagedAccountGroupAccount(Session);
                m_accountgroupaccount.CreateOrUpdate(t_account, sec);
            }
        }
예제 #2
0
        protected override void Save(ManagedSecurityContext sec)
        {
            mInstance.Modified = DateTime.UtcNow;
            bool fNew = (mInstance.Id == 0);

            if (mInstance.Id == 0)
            {
                mInstance.Created = mInstance.Modified;
            }
            base.Save(sec);
            // create an admin account that owns the group
            if (fNew)
            {
                TransitAccountGroupAccount t_admin = new TransitAccountGroupAccount();
                t_admin.AccountGroupId  = mInstance.Id;
                t_admin.AccountId       = sec.Account.Id;
                t_admin.IsAdministrator = true;
                ManagedAccountGroupAccount m_admin = new ManagedAccountGroupAccount(Session);
                m_admin.CreateOrUpdate(t_admin, ManagedAccount.GetAdminSecurityContext(Session));
                ManagedDiscussion.GetOrCreateDiscussionId(Session, typeof(AccountGroup).Name, mInstance.Id, sec);
            }
        }