public async Task <PropertySearchResultModel> SearchPropertyAsync(Shared.Enums.PropertyType propertyType, PropertySearchRequestModel model) { PropertySearchResultModel result = new PropertySearchResultModel(); switch (propertyType) { case Shared.Enums.PropertyType.AIRCRAFT: case Shared.Enums.PropertyType.VEHICLE: case Shared.Enums.PropertyType.VESSEL: result = await SearchInRegiXAsync(propertyType, model); break; case Shared.Enums.PropertyType.AGRIFORMACHINERY: result = await SearchInAgriculturalRegisterAsync(model); break; case Shared.Enums.PropertyType.REALESTATE: // TODO: result = await SearchInNAPAsync(model); break; default: break; } // TODO: handle errors return(result); }
public async Task <List <object> > SearchInDataAdministratorAsync(Shared.Enums.PropertyType propertyType, PropertySearchRequestModel searchModel) { PropertySearchResultModel result = await _integrationService.SearchPropertyAsync(propertyType, searchModel); List <object> entities = GetPropertyViewModelsFromResponse(propertyType, result, searchModel); return(entities); }
public async Task <PropertySearchResultModel> TestConnectionToRegiXVessel() { PropertySearchRequestModel searchModel = new PropertySearchRequestModel() { Identifier = "8001010101", IdentifierTypeCode = "OWNER", SuitNumber = "test suit 123" }; Shared.Enums.PropertyType propertyType = Shared.Enums.PropertyType.VESSEL; PropertySearchResultModel result = await SearchInRegiXAsync(propertyType, searchModel); return(result); }
public async Task <PropertySearchResultModel> TestConnectionToRegiXAircraft() { PropertySearchRequestModel searchModel = new PropertySearchRequestModel() { Identifier = "1234567", IdentifierTypeCode = "MSN", SuitNumber = "test suit 123" }; Shared.Enums.PropertyType propertyType = Shared.Enums.PropertyType.AIRCRAFT; PropertySearchResultModel result = await SearchInRegiXAsync(propertyType, searchModel); return(result); }
public async Task <IActionResult> TestConnectionToRegiXAircrafts() { try { PropertySearchResultModel result = await integrationService.TestConnectionToRegiXAircraft(); Log.Information($"IntegrationController/TestConnectionToRegiXAircrafts - tested connection"); return(Ok(result)); } catch (Exception ex) { Log.Error(ex, $"ERROR testing the connection to RegiX Aircrafts"); return(BadRequest("Error testing the connection to RegiX Aircrafts")); } }
private async Task <PropertySearchResultModel> SearchInRegiXAsync(Shared.Enums.PropertyType propertyType, PropertySearchRequestModel searchModel) { if (!_integrationSettings.UseRegiX) { throw new Exception("Integration with RegiX is not configured!"); } if (searchModel == null || String.IsNullOrWhiteSpace(searchModel.IdentifierTypeCode) || String.IsNullOrWhiteSpace(searchModel.Identifier)) { throw new Exception("Property search criteria is missing"); } RegiXReportModel report = await GetRegiXReportForPropertyType(propertyType, searchModel); if (report == null) { throw new Exception("RegiX report configuration not found for property type: " + propertyType); } ServiceRequestData request = GetServiceRequestData(propertyType, searchModel, report); if (request == null) { throw new Exception("Property service request was not created"); } long requestId = await SaveRegiXRequest(request, report); // TODO: is context needed for transfering eAuth and certificate info? CustomCallContext context = new CustomCallContext(); RegiXResponse response = await CallRegiXAsync(context, request); await SaveRegiXResponse(requestId, response, ""); BaseResponse parsedObject = GetResponseObject(propertyType, response); PropertySearchResultModel resultModel = new PropertySearchResultModel { PropertyIdentifier = searchModel.Identifier, RequestId = requestId, ResponseObject = parsedObject }; return(resultModel); }
private async Task <PropertySearchResultModel> SearchInAgriculturalRegisterAsync(PropertySearchRequestModel model) { AgriculturalMachineryCollectionModel list = new AgriculturalMachineryCollectionModel(); var entities = await _context.AgriculturalMachinery .Include(x => x.Owner) .Include(x => x.Company) .Where(x => x.RegistrationNumber.ToLower().Contains(model.Identifier.Trim().ToLower())) .Select(x => x.ToViewModel()) .ToListAsync(); list.Machines = entities?.ToList(); PropertySearchResultModel result = new PropertySearchResultModel(); result.PropertyIdentifier = model.Identifier; result.ResponseObject = list; return(result); }
private async Task <List <BaseProperty> > SaveResponseEntities(Shared.Enums.PropertyType propertyType, PropertySearchResultModel result, PropertySearchRequestModel searchModel, bool useSearchIdentifier) { if (result == null || result.ResponseObject == null) { return(null); } List <BaseProperty> entities = null; switch (propertyType) { case Shared.Enums.PropertyType.AIRCRAFT: AircraftsResponse aircraftsResponse = result.ResponseObject as AircraftsResponse; if (aircraftsResponse == null) { throw new Exception("Could not convert response to AircraftsResponse"); } if (aircraftsResponse.Aircraft != null && aircraftsResponse.Aircraft.Length > 0) { List <Data.Aircraft> aircrafts = await SaveAircrafts(aircraftsResponse, result.RequestId, searchModel, useSearchIdentifier); entities = (aircrafts).Cast <BaseProperty>().ToList(); } break; case Shared.Enums.PropertyType.VEHICLE: MotorVehicleRegistrationResponse vehiclesResponse = result.ResponseObject as MotorVehicleRegistrationResponse; if (vehiclesResponse == null) { throw new Exception("Could not convert response to MotorVehicleRegistrationResponse"); } if (vehiclesResponse.Vehicles != null && vehiclesResponse.Vehicles.Length > 0) { List <Data.Vehicle> vehicles = await SaveVehicles(vehiclesResponse, result.RequestId, searchModel, useSearchIdentifier); entities = (vehicles).Cast <BaseProperty>().ToList(); } //GetMotorVehicleRegistrationInfoV3ResponseTypeResponse vehiclesResponse = result.ResponseObject as GetMotorVehicleRegistrationInfoV3ResponseTypeResponse; //if (vehiclesResponse == null) // throw new Exception("Could not convert response to GetMotorVehicleRegistrationInfoV3ResponseTypeResponse"); //if (vehiclesResponse.Results != null && vehiclesResponse.Results.Length > 0) //{ // List<Data.Vehicle> vehicles = await SaveVehiclesV3(vehiclesResponse, result.RequestId, searchModel, useSearchIdentifier); // entities = (vehicles).Cast<BaseProperty>().ToList(); //} break; default: break; } return(entities); }
private List <object> GetPropertyViewModelsFromResponse(Shared.Enums.PropertyType propertyType, PropertySearchResultModel result, PropertySearchRequestModel searchModel) { if (result == null || result.ResponseObject == null) { return(null); } List <object> entities = null; switch (propertyType) { case Shared.Enums.PropertyType.AIRCRAFT: AircraftsResponse aircraftsResponse = result.ResponseObject as AircraftsResponse; if (aircraftsResponse == null) { throw new Exception("Could not convert response to AircraftsResponse"); } if (aircraftsResponse.Aircraft != null && aircraftsResponse.Aircraft.Length > 0) { //List<AircraftViewModel> aircrafts = SaveAircrafts(aircraftsResponse, result.RequestId, searchModel); List <AircraftViewModel> aircrafts = new List <AircraftViewModel>(); for (int i = 0; i < aircraftsResponse.Aircraft.Length; i++) { AircraftViewModel airViewModel = aircraftsResponse.Aircraft[i].ToViewModel(); airViewModel.ExtensionRequestId = result.RequestId; if (regixCertificateSettings.SaveEntityWithSearchedIdentifier && searchModel.IdentifierTypeCode == "MSN") { airViewModel.MsnserialNumber = searchModel.Identifier; } aircrafts.Add(airViewModel); } entities = (aircrafts).Cast <object>().ToList(); } break; case Shared.Enums.PropertyType.VEHICLE: if (regixCertificateSettings.UseVehicleV3) { GetMotorVehicleRegistrationInfoV3Response vehiclesResponse = result.ResponseObject as GetMotorVehicleRegistrationInfoV3Response; if (vehiclesResponse == null) { throw new Exception("Could not convert response to GetMotorVehicleRegistrationInfoV3Response"); } if (vehiclesResponse.Response != null && vehiclesResponse.Response.Results.Length > 0 && vehiclesResponse.Response.Results[0].VehicleData != null) { List <VehicleViewModel> vehicles = new List <VehicleViewModel>(); VehicleViewModel vehicleViewModel = vehiclesResponse.Response.Results[0].ToViewModel(); vehicleViewModel.ExtensionRequestId = result.RequestId; if (regixCertificateSettings.SaveEntityWithSearchedIdentifier) { vehicleViewModel.RegistrationNumber = searchModel.Identifier; } vehicles.Add(vehicleViewModel); entities = (vehicles).Cast <object>().ToList(); } } else { MotorVehicleRegistrationResponse vehiclesResponse = result.ResponseObject as MotorVehicleRegistrationResponse; if (vehiclesResponse == null) { throw new Exception("Could not convert response to MotorVehicleRegistrationResponse"); } if (vehiclesResponse.Vehicles != null && vehiclesResponse.Vehicles.Length > 0) { //List<Data.Vehicle> vehicles = await SaveVehicles(vehiclesResponse, result.RequestId, searchModel, useSearchIdentifier); List <VehicleViewModel> vehicles = new List <VehicleViewModel>(); foreach (RegiX.Client.ResponseModels.Vehicle vehicle in vehiclesResponse.Vehicles) { VehicleViewModel vehicleViewModel = vehicle.ToViewModel(); vehicleViewModel.ExtensionRequestId = result.RequestId; if (regixCertificateSettings.SaveEntityWithSearchedIdentifier) { vehicleViewModel.RegistrationNumber = searchModel.Identifier; } vehicles.Add(vehicleViewModel); } entities = (vehicles).Cast <object>().ToList(); } } break; case Shared.Enums.PropertyType.VESSEL: RegistrationInfoByOwnerResponse vesselResponse = result.ResponseObject as RegistrationInfoByOwnerResponse; if (vesselResponse == null) { throw new Exception("Could not convert response to RegistrationInfoByOwnerResponse"); } if (vesselResponse.VesselInfo != null) { VesselViewModel vesselViewModel = vesselResponse.VesselInfo.ToViewModel(); vesselViewModel.ExtensionRequestId = result.RequestId; vesselViewModel = SetVesselStatusInModel(vesselViewModel); entities = new List <object>(); entities.Add(vesselViewModel); } break; case Shared.Enums.PropertyType.AGRIFORMACHINERY: AgriculturalMachineryCollectionModel machines = result.ResponseObject as AgriculturalMachineryCollectionModel; entities = (machines.Machines).Cast <object>().ToList(); break; default: break; } return(entities); }