Esempio n. 1
0
        /// <summary>
        /// 角色編輯使用者
        /// 儲存勾選使用者時的變更
        /// </summary>
        /// <param name="userCheckVO"></param>
        /// <returns></returns>
        public string SaveRoleUserSetting(IEnumerable <UserCheckVO> userCheckVO)
        {
            string result = string.Empty;
            string roleID;

            if (userCheckVO != null && userCheckVO.Any())
            {
                roleID = userCheckVO.First().RoleID.ToString();
                List <RoleUserDTO> roleUserDTOs = new List <RoleUserDTO>();
                foreach (var item in userCheckVO)
                {
                    RoleUserDTO roleUserDTO = new RoleUserDTO();
                    roleUserDTO.RoleID = item.RoleID;
                    roleUserDTO.UserID = item.UserID;
                    roleUserDTOs.Add(roleUserDTO);
                }

                SQLConnTran sqlConnTran = _sqlConnectionHelper.BeginTransaction();

                int deleteResult = _roleUserRepo.DeleteRoleUserByRoleID(roleID, ref sqlConnTran.SqlConn, ref sqlConnTran.SqlTrans);

                if (deleteResult < 0)
                {
                    _sqlConnectionHelper.Rollback();// tran.Rollback();
                    result = "刪除失敗。";
                    return(result);
                }

                int insertResult = 0;
                foreach (var item in roleUserDTOs)
                {
                    insertResult += _roleUserRepo.InsertRoleUser(item, ref sqlConnTran.SqlConn, ref sqlConnTran.SqlTrans);
                }

                _sqlConnectionHelper.Commit();

                if (insertResult < 0)
                {
                    _sqlConnectionHelper.Rollback();// tran.Rollback();
                    result = "設定失敗。";
                }
            }

            return(result);
        }