Example #1
0
        /// <summary>
        /// 删除帐户(同时删除权限以及联盟和邮箱帐号等)
        /// </summary>
        /// <param name="accountID">用户ID</param>
        public void DeleteAccont(string accountID)
        {
            We7Helper.AssertNotNull(Assistant, "AccountHelper.Assistant");
            We7Helper.AssertNotNull(accountID, "DeleteAccont.accountID");

            //利用事务进行帐户的相关权限删除
            //IDatabase db = Assistant.GetDatabases()["We7.CMS.Common"];
            //IConnection ic = Assistant.GetConnections()[db];

            IConnection ic = Assistant.CreateConnetion(typeof(Account), true);//上边连接无效,此方法为重构方法

            //ic.IsTransaction = true;
            try
            {
                //删除Permissions
                Criteria c = new Criteria(CriteriaType.Equals, "OwnerID", accountID);
                Assistant.DeleteList <Permission>(ic, c);
                //删除AccountRole
                Criteria ca = new Criteria(CriteriaType.Equals, "AccountID", accountID);
                Assistant.DeleteList <AccountRole>(ic, ca);
                //最后删除当前帐户
                Account act = new Account();
                act.ID = accountID;
                Assistant.Delete(ic, act);
                OnUserDeleted(act);
                ic.Commit();
            }
            catch (Exception)
            {
                try { ic.Rollback(); }
                catch (Exception)
                { }
            }
            finally { ic.Dispose(); }
        }
Example #2
0
        /// <summary>
        /// 添加一个用户
        /// </summary>
        /// <param name="act">用户对象</param>
        /// <returns>用户对象</returns>
        public Account AddAccount(Account act)
        {
            if (act.LoginName.Length < 3)
            {
                throw new Exception("用户名不能小于3位。");
            }

            if (act.Password.Length < 6)
            {
                throw new Exception("密码不能小于6位。");
            }

            if (GetAccountByLoginName(act.LoginName) != null)
            {
                throw new Exception(string.Format("登录名 {0} 已存在。", act.LoginName));
            }

            if (GetAccountByEmail(act.Email) != null)
            {
                throw new Exception(string.Format("邮件地址 {0} 已被使用。", act.Email));
            }

            We7Helper.AssertNotNull(Assistant, "AccountHelper.Assistant");
            We7Helper.AssertNotNull(act, "AddAccount.act");

            //利用事务进行帐户的相关权限删除
            //IDatabase db = Assistant.GetDatabases()["We7.CMS.Common"];
            //IConnection ic = Assistant.GetConnections()[db];
            //ic.IsTransaction = true;
            IConnection ic = Assistant.CreateConnetion(typeof(Account), true);//上边连接无效,此方法为重构方法

            try
            {
                act.ID      = We7Helper.CreateNewID();
                act.Created = DateTime.Now;
                if (GeneralConfigs.GetConfig().UserRegisterMode == "none")
                {
                    act.State = 1;
                }

                AccountRole ar = new AccountRole();
                ar.AccountID = act.ID;
                ar.RoleID    = "1";
                ar.RoleTitle = "注册用户";
                ar.ID        = We7Helper.CreateNewID();

                OnUserAdded(act);
                UpdateUserPassword(act);

                Assistant.Insert(ic, act, null);
                Assistant.Insert(ic, ar, null);

                ic.Commit();
                ic.Dispose();
                return(act);
            }
            catch (Exception ex)
            {
                ic.Rollback();
                ic.Dispose();
                throw ex;
            }
        }