Beispiel #1
0
        /// <summary>
        /// 修改帐号权限
        /// </summary>
        /// <param name="nAccountId"></param>
        /// <param name="listGroup"></param>
        /// <param name="nOpStaffId"></param>
        /// <param name="strOpStaffName"></param>
        /// <param name="strErrText"></param>
        /// <returns></returns>
        public bool UpdateAccountPermissions(long nAccountId, List <SysGroup> listGroup, long nOpStaffId, string strOpStaffName, out string strErrText)
        {
            try
            {
                using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0)))
                {
                    using (PermissionDAO dao = new PermissionDAO())
                    {
                        //删除原帐号权限
                        if (!dao.DeleteAccountPermissions(nAccountId, nOpStaffId, strOpStaffName, out strErrText))
                        {
                            return(false);
                        }

                        //新增岗位权限
                        if (listGroup != null)
                        {
                            foreach (SysGroup g in listGroup)
                            {
                                AccountPermission p = new AccountPermission();
                                p.AccountId = nAccountId;
                                p.GroupId   = g.Id;

                                if (!dao.InsertAccountPermission(p, nOpStaffId, strOpStaffName, out strErrText))
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                    transScope.Complete();
                }
                return(true);
            }
            catch (Exception e)
            {
                strErrText = e.Message;
                return(false);
            }
        }