private RegixPersonModel GetPersonViewModelFromResponse(PersonSearchResultModel result, string searchIdentifier) { if (result == null || result.ResponseObject == null) { return(null); } ValidPersonResponse personResponse = result.ResponseObject as ValidPersonResponse; if (personResponse == null) { throw new Exception("Could not convert response to ValidPersonResponse"); } RegixPersonModel model = personResponse.ToViewModel(); model.RequestId = result.RequestId; model.Identifier = searchIdentifier; return(model); }
private static BaseResponse ParseResponseToObject <T>(XElement node) { try { if (node == null) { throw new Exception("Node element is null"); } BaseResponse parsedObject = null; if (typeof(T) == typeof(AircraftsResponse)) { parsedObject = new AircraftsResponse(); using (StringReader reader = new StringReader(node.ToString())) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(AircraftsResponse)); parsedObject = (AircraftsResponse)xmlSerializer.Deserialize(reader); return(parsedObject); } } else if (typeof(T) == typeof(MotorVehicleRegistrationResponse)) { parsedObject = new MotorVehicleRegistrationResponse(); using (StringReader reader = new StringReader(node.ToString())) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(MotorVehicleRegistrationResponse)); parsedObject = (MotorVehicleRegistrationResponse)xmlSerializer.Deserialize(reader); return(parsedObject); } } else if (typeof(T) == typeof(GetMotorVehicleRegistrationInfoV3Response)) { parsedObject = new GetMotorVehicleRegistrationInfoV3Response(); using (StringReader reader = new StringReader(node.ToString())) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(GetMotorVehicleRegistrationInfoV3Response)); parsedObject = (GetMotorVehicleRegistrationInfoV3Response)xmlSerializer.Deserialize(reader); return(parsedObject); } } else if (typeof(T) == typeof(ValidPersonResponse)) { parsedObject = new ValidPersonResponse(); using (StringReader reader = new StringReader(node.ToString())) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(ValidPersonResponse)); parsedObject = (ValidPersonResponse)xmlSerializer.Deserialize(reader); return(parsedObject); } } else if (typeof(T) == typeof(ValidUICResponse)) { parsedObject = new ValidUICResponse(); using (StringReader reader = new StringReader(node.ToString())) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(ValidUICResponse)); parsedObject = (ValidUICResponse)xmlSerializer.Deserialize(reader); return(parsedObject); } } else if (typeof(T) == typeof(RegistrationInfoByOwnerResponse)) { parsedObject = new RegistrationInfoByOwnerResponse(); using (StringReader reader = new StringReader(node.ToString())) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(RegistrationInfoByOwnerResponse)); parsedObject = (RegistrationInfoByOwnerResponse)xmlSerializer.Deserialize(reader); return(parsedObject); } } return(null); } catch (Exception ex) { throw new Exception("Error parsing response to object: " + ex.Message); } }