public PermissionByUserIdModelList SelectPermisionByUserId(UserRequestIdModel userId) { // userRepository ดึงข้อมูล role id, role name โดย ส่ง user id ไปหา ต้อง join กับ table role ด้วยนะ RoleModel roldInfo = _userRepository.SelectRoleIdByUserId(userId); RoleByIdModel roleByIdModel = new RoleByIdModel(); roleByIdModel.roleId = roldInfo.id; // roleByIdModel.roleId = 1; // roleRepository ดึงข้อมูล permision โดยส่ง role id List <int> rolePermission = _rolesRepository.SelectRolePermissionByRoleId(roleByIdModel); PermissionModelList permission = _rolesRepository.SelectPermissionAll(); PermissionByUserIdModelList result = new PermissionByUserIdModelList(); // result.role = "Admin"; result.role = roldInfo.role; result.permissions = new List <PermissionModel>(); foreach (PermissionModel item in permission.Permissiontable) { result.permissions.Add( new PermissionModel() { permissionId = item.permissionId, //PermisdionTbl permissionName = item.permissionName, //PermisdionTbl permissionCheck = rolePermission.IndexOf(item.permissionId) >= 0 ? true : false } ); } return(result); }
public RoleResponseModel DeleteRoleService(RoleByIdModel requestId) { try { RoleResponseModel response = new RoleResponseModel(); var resRolePermission = _rolesRepository.DeleteRolePermission(requestId.roleId); if (resRolePermission > 0) { var resRole = _rolesRepository.DeleteRole(requestId.roleId); if (resRole > 0) { response.success = true; } else { response.success = false; } } else { response.success = false; } return(response); } catch (Exception error) { Console.WriteLine("Error: " + error); return(new RoleResponseModel() { success = false }); } }
public List <int> SelectRolePermissionByRoleId(RoleByIdModel requestId) { var cs = "Server=localhost\\SQLEXPRESS;Database=HospitalDB;Trusted_Connection=True;"; using var con = new SqlConnection(cs); con.Open(); string sql = string.Format(@"SELECT PermissionId FROM RolePermissionTbl WHERE RoleId = {0}", requestId.roleId); using var cmd = new SqlCommand(sql, con); using SqlDataReader rdr = cmd.ExecuteReader(); List <int> output = new List <int>(); while (rdr.Read()) { output.Add( rdr.GetInt32(0) ); } return(output); }
public PermissionByIdModelList SelectPermissionsById(RoleByIdModel requestId) { List <int> rolePermission = _rolesRepository.SelectRolePermissionByRoleId(requestId); PermissionModelList permission = _rolesRepository.SelectPermissionAll(); PermissionByIdModelList result = new PermissionByIdModelList(); result.PermissionIdList = new List <PermissionModel>(); foreach (PermissionModel item in permission.Permissiontable) { result.PermissionIdList.Add( new PermissionModel() { permissionId = item.permissionId, //PermisdionTbl permissionName = item.permissionName, //PermisdionTbl permissionCheck = rolePermission.IndexOf(item.permissionId) >= 0 ? true : false //Search PermissionId(PermissionTbl) on RolePermisdion(RolePermissionTbl) } ); } return(result); }
public RoleResponseModel DeleteRole([FromQuery] RoleByIdModel requestId) { RoleResponseModel result = _rolesService.DeleteRoleService(requestId); return(result); }
public PermissionByIdModelList GetPermissionListById([FromQuery] RoleByIdModel requestId) { PermissionByIdModelList result = _rolesService.SelectPermissionsById(requestId); return(result); }