Пример #1
0
        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);
        }
Пример #2
0
        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);
        }