public async Task <List <OtherPropertyModel> > SearchOtherPropertyInDBAsync(PropertySearchRequestModel model) { var entities = await _context.OtherProperty .Include(x => x.Distraint) .Where(x => x.Distraint.Any() && x.Identifier.ToLower().Contains(model.Identifier.Trim().ToLower())) .Select(x => x.ToViewModel()) .ToListAsync(); return(entities?.ToList()); }
public async Task <List <VehicleViewModel> > SearchVehicleInDBAsync(PropertySearchRequestModel model) { var entities = await _context.Vehicle .Include(x => x.Distraint) .Include(x => x.VehicleOwner) .Include(x => x.VehicleUser) .Where(x => x.Distraint.Any() && x.RegistrationNumber.ToLower() == model.Identifier.Trim().ToLower()) .Select(x => x.ToViewModel()) .ToListAsync(); return(entities?.ToList()); }
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 <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 <List <AircraftViewModel> > SearchAircraftInDBAsync(PropertySearchRequestModel model) { var entities = await _context.Aircraft .Include(x => x.Distraint) .Include(x => x.AircraftDebt) .Include(x => x.AircraftRegistration) .Include(x => x.AircraftRegistration).ThenInclude(x => x.AircraftRegistrationOwnerPerson) .Include(x => x.AircraftRegistration).ThenInclude(x => x.AircraftRegistrationOwnerEntity) .Include(x => x.AircraftRegistration).ThenInclude(x => x.AircraftRegistrationOperatorPerson) .Include(x => x.AircraftRegistration).ThenInclude(x => x.AircraftRegistrationOperatorEntity) .Where(x => x.Distraint.Any() && x.MsnserialNumber.ToLower() == model.Identifier.Trim().ToLower()) .Select(x => x.ToViewModel()) .ToListAsync(); return(entities?.ToList()); }
public async Task <List <VesselViewModel> > SearchVesselInDBAsync(PropertySearchRequestModel model) { var entities = await _context.Vessel .Include(x => x.VesselEngine) .Include(x => x.VesselRegistrationData) .Include(x => x.VesselRegistrationData).ThenInclude(x => x.StatusNavigation) .Include(x => x.VesselOwner) .Where(x => x.Distraint.Any() && x.VesselOwner.Any() && x.VesselOwner.Where(a => a.Eik.ToLower().Contains(model.Identifier.Trim().ToLower()) || a.Egn.ToLower().Contains(model.Identifier.Trim().ToLower())).Any()) .Select(x => x.ToViewModel()) .ToListAsync(); return(entities?.ToList()); }
private async Task <PropertySearchResultModel> SearchInNAPAsync(PropertySearchRequestModel model) { // TODO: call NAP? return(new PropertySearchResultModel()); }
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); }
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); }
private ServiceRequestData GetServiceRequestData(Shared.Enums.PropertyType propertyType, PropertySearchRequestModel model, RegiXReportModel report) { ServiceRequestData request = null; if (propertyType == Shared.Enums.PropertyType.VEHICLE) { request = GetMotorVehicleRegistrationInfoV3Request(model.Identifier, report); } else if (propertyType == Shared.Enums.PropertyType.AIRCRAFT) { if (String.Equals(model.IdentifierTypeCode.ToUpper(), "MSN")) { request = GetAircraftsByMSNRequest(model.Identifier, report); } else if (String.Equals(model.IdentifierTypeCode.ToUpper(), "OWNER")) { request = GetAircraftsByOwnerRequest(model.Identifier, report); } } else if (propertyType == Shared.Enums.PropertyType.VESSEL) { request = GetVesselsByOwnerRequest(model.Identifier, report); } return(request); }
private async Task <RegiXReportModel> GetRegiXReportForPropertyType(Shared.Enums.PropertyType propertyType, PropertySearchRequestModel searchModel) { RegiXreportToPropertyType reportType = await _context.RegiXreportToPropertyType .Where(x => x.RegiXsearchCriteriaTypeCode == searchModel.IdentifierTypeCode.ToUpper() && x.PropertyTypeCode == propertyType.ToString()) .FirstOrDefaultAsync(); if (reportType == null) { return(null); } RegiXReportModel report = await _context.RegiXreport .Where(x => x.Id == reportType.RegiXreportId) .Select(x => x.ToModel()) .FirstOrDefaultAsync(); return(report); }
public async Task <List <AgriculturalMachineryViewModel> > SearchAgriculturalMachineryInDBAsync(PropertySearchRequestModel model) { var entities = await _context.AgriculturalMachinery .Include(x => x.Distraint) .Include(x => x.Owner) .Include(x => x.Company) .Where(x => x.Distraint.Any() && x.RegistrationNumber.ToLower().Contains(model.Identifier.Trim().ToLower())) .Select(x => x.ToViewModel()) .ToListAsync(); return(entities?.ToList()); }
private async Task <List <Data.Vehicle> > SaveVehicles(MotorVehicleRegistrationResponse vehiclesResponse, long?messageId, PropertySearchRequestModel searchModel, bool useSearchIdentifier) { List <Data.Vehicle> newVehicles = new List <Data.Vehicle>(); List <Data.Vehicle> existingVehicles = new List <Data.Vehicle>(); foreach (RegiX.Client.ResponseModels.Vehicle vehicle in vehiclesResponse.Vehicles) { string regNumberToUse = vehicle.VehicleRegistrationNumber; if (useSearchIdentifier) { regNumberToUse = searchModel.Identifier; } var existing = await _context.Vehicle .Include(x => x.VehicleExtension) .Include(x => x.VehicleOwner) .Where(x => x.RegistrationNumber == regNumberToUse && x.VehicleExtension != null && x.VehicleExtension.Deactivated == false) .ToListAsync(); if (!existing.Any()) { Data.Vehicle entity = vehicle.ToEntity(); entity.RegistrationNumber = regNumberToUse; entity.VehicleExtension = new VehicleExtension { VehicleId = entity.Id, UpdatedAt = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), RequestId = messageId, Deactivated = false }; if (entity != null) { newVehicles.Add(entity); } } else { foreach (Data.Vehicle item in existing) { item.VehicleExtension.Deactivated = true; _context.VehicleOwner.RemoveRange(item.VehicleOwner); } existing[0].UpdateEntity(vehicle); existing[0].RegistrationNumber = regNumberToUse; existing[0].VehicleExtension.Deactivated = false; existing[0].VehicleExtension.UpdatedAt = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); existing[0].VehicleExtension.RequestId = messageId; existingVehicles.AddRange(existing); } } if (newVehicles.Count > 0) { _context.Vehicle.AddRange(newVehicles); } if (existingVehicles.Count > 0) { _context.Vehicle.UpdateRange(existingVehicles); } await _context.SaveChangesAsync(); return(newVehicles.Concat(existingVehicles).ToList()); }
private async Task <List <Data.Aircraft> > SaveAircrafts(AircraftsResponse aircraftsResponse, long?messageId, PropertySearchRequestModel searchModel, bool useSearchIdentifier) { List <Data.Aircraft> newAircrafts = new List <Data.Aircraft>(); List <Data.Aircraft> existingAircrafts = new List <Data.Aircraft>(); for (int i = 0; i < aircraftsResponse.Aircraft.Length; i++) { string msnToUse = aircraftsResponse.Aircraft[i].MSNSerialNumber; if (useSearchIdentifier) { msnToUse = searchModel.IdentifierTypeCode.ToUpper() == "MSN" ? searchModel.Identifier : searchModel.Identifier + "_" + i.ToString(); } var existing = await _context.Aircraft .Include(x => x.AircraftExtension) .Include(x => x.AircraftRegistration) .Include(x => x.AircraftRegistration).ThenInclude(a => a.AircraftRegistrationOperatorEntity) .Include(x => x.AircraftRegistration).ThenInclude(a => a.AircraftRegistrationOperatorPerson) .Include(x => x.AircraftRegistration).ThenInclude(a => a.AircraftRegistrationOwnerEntity) .Include(x => x.AircraftRegistration).ThenInclude(a => a.AircraftRegistrationOwnerPerson) .Include(x => x.AircraftDebt) .Where(x => x.MsnserialNumber == msnToUse && x.AircraftExtension != null && x.AircraftExtension.Deactivated == false) .ToListAsync(); if (!existing.Any()) { Data.Aircraft entity = aircraftsResponse.Aircraft[i].ToEntity(); entity.MsnserialNumber = msnToUse; entity.AircraftExtension = new AircraftExtension { AircraftId = entity.Id, UpdatedAt = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), RequestId = messageId, Deactivated = false }; if (entity != null) { newAircrafts.Add(entity); } } else { foreach (Data.Aircraft item in existing) { item.AircraftExtension.Deactivated = true; foreach (Data.AircraftRegistration reg in item.AircraftRegistration) { _context.AircraftRegistrationOperatorEntity.RemoveRange(reg.AircraftRegistrationOperatorEntity); _context.AircraftRegistrationOperatorPerson.RemoveRange(reg.AircraftRegistrationOperatorPerson); _context.AircraftRegistrationOwnerPerson.RemoveRange(reg.AircraftRegistrationOwnerPerson); _context.AircraftRegistrationOwnerEntity.RemoveRange(reg.AircraftRegistrationOwnerEntity); } _context.AircraftRegistration.RemoveRange(item.AircraftRegistration); _context.AircraftDebt.RemoveRange(item.AircraftDebt); } existing[0].UpdateEntity(aircraftsResponse.Aircraft[i]); existing[0].MsnserialNumber = msnToUse; existing[0].AircraftExtension.Deactivated = false; existing[0].AircraftExtension.UpdatedAt = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); existing[0].AircraftExtension.RequestId = messageId; existingAircrafts.AddRange(existing); } } if (newAircrafts.Count > 0) { _context.Aircraft.AddRange(newAircrafts); } if (existingAircrafts.Count > 0) { _context.Aircraft.UpdateRange(existingAircrafts); } await _context.SaveChangesAsync(); return(newAircrafts.Concat(existingAircrafts).ToList()); }
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); }
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 <IActionResult> SearchInDataAdministrator(string propertyTypeCode, [FromBody] PropertySearchRequestModel model) { try { if (model == null) { Log.Information($"PropertyController/SearchInDataAdministrator/{CurrentUserId}/{CurrentUserUsername} - Missing property search model"); return(BadRequest("Missing property search model")); } if (!Enum.TryParse(propertyTypeCode.ToUpper(), out Shared.Enums.PropertyType propType)) { Log.Information($"PropertyController/SearchInDataAdministrator/{CurrentUserId}/{CurrentUserUsername} - Unrecognized property type"); return(BadRequest("Unrecognized property type")); } var properties = await _propertyService.SearchInDataAdministratorAsync(propType, model); return(Ok(properties)); } catch (Exception ex) { Log.Error(ex, $"ERROR searching for properties in data administrator: {propertyTypeCode} / {model?.Identifier} by user {CurrentUserId}/{CurrentUserUsername}"); return(BadRequest("Error searching for properties in data administrator")); } }
public async Task <IActionResult> SearchInDB(string propertyTypeCode, [FromBody] PropertySearchRequestModel model) { try { if (model == null) { Log.Information($"PropertyController/SearchInDB/{CurrentUserId}/{CurrentUserUsername} - Missing PropertySearchRequestModel"); return(BadRequest("Missing PropertySearchRequestModel")); } if (!Enum.TryParse(propertyTypeCode.ToUpper(), out Shared.Enums.PropertyType propType)) { Log.Information($"PropertyController/SearchInDB/{CurrentUserId}/{CurrentUserUsername} - Unrecognized property type"); return(BadRequest("Unrecognized property type")); } IEnumerable <object> properties = null; switch (propType) { case Shared.Enums.PropertyType.OTHER: properties = await _propertyService.SearchOtherPropertyInDBAsync(model); break; case Shared.Enums.PropertyType.VEHICLE: properties = await _propertyService.SearchVehicleInDBAsync(model); break; case Shared.Enums.PropertyType.AIRCRAFT: properties = await _propertyService.SearchAircraftInDBAsync(model); break; case Shared.Enums.PropertyType.VESSEL: properties = await _propertyService.SearchVesselInDBAsync(model); break; case Shared.Enums.PropertyType.AGRIFORMACHINERY: properties = await _propertyService.SearchAgriculturalMachineryInDBAsync(model); break; case Shared.Enums.PropertyType.REALESTATE: //properties = await _propertyService.SearchInDBAsync(propType, model); break; default: break; } return(Ok(properties)); } catch (Exception ex) { Log.Error(ex, $"ERROR searching for properties in DB: {propertyTypeCode} / {model?.Identifier} by user {CurrentUserId}/{CurrentUserUsername}"); return(BadRequest("Error searching for properties in DB")); } }
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); }