/// <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); }
/// <summary> /// 角色編輯功能 /// 儲存勾選功能時的變更 /// </summary> /// <param name="functionCheckVO"></param> /// <returns></returns> public string SaveRoleFunctionSetting(IEnumerable <FunctionCheckVO> functionCheckVO) { string result = string.Empty; string roleID; if (functionCheckVO != null && functionCheckVO.Any()) { roleID = functionCheckVO.First().RoleID.ToString(); List <RoleFunctionDTO> roleFunctionDTOs = new List <RoleFunctionDTO>(); foreach (var item in functionCheckVO) { RoleFunctionDTO roleFunctionDTO = new RoleFunctionDTO(); roleFunctionDTO.RoleID = item.RoleID; roleFunctionDTO.FunctionID = item.FunctionID; roleFunctionDTOs.Add(roleFunctionDTO); } var sqlConnTrans = _sqlConnectionHelper.BeginTransaction(); int deleteResult = _roleFunctionRepo.DeleteRoleFunctionByRoleID(roleID, ref sqlConnTrans.SqlConn, ref sqlConnTrans.SqlTrans); if (deleteResult < 0) { _sqlConnectionHelper.Rollback(); result = "刪除失敗。"; return(result); } int insertResult = 0; foreach (var item in roleFunctionDTOs) { insertResult += _roleFunctionRepo.InsertRoleFunction(item, ref sqlConnTrans.SqlConn, ref sqlConnTrans.SqlTrans); } _sqlConnectionHelper.Commit(); if (insertResult < 0) { _sqlConnectionHelper.Rollback(); result = "設定失敗。"; } } return(result); }