예제 #1
0
        public static Model.WayBillSearchInfo Convert(Client.WayBillSearchInfo clientSearchInfo)
        {
            if (clientSearchInfo == null)
            {
                throw new ArgumentNullException(nameof(clientSearchInfo));
            }

            var modelSearchInfo = new Model.WayBillSearchInfo
            {
                Offset = clientSearchInfo.Offset,
                Limit  = clientSearchInfo.Limit
            };

            return(modelSearchInfo);
        }
        public async Task <IActionResult> SearchPlacesAsync([FromQuery] Client.WayBillSearchInfo searchInfo,
                                                            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var modelSearchInfo  = WayBillSearchInfoConverter.Convert(searchInfo ?? new Client.WayBillSearchInfo());
            var modelWayBillList = await wayBillRepository.SearchAsync(modelSearchInfo, cancellationToken).ConfigureAwait(false);

            var clientWayBillList = modelWayBillList
                                    .Select(async item =>
            {
                var driver        = await driverRepository.GetAsync(item.Driver, cancellationToken).ConfigureAwait(false);
                var clientDriver  = ModelConverters.Drivers.DriverConverter.Convert(driver);
                var vehicle       = await vehicleRepository.GetAsync(item.Vehicle, cancellationToken).ConfigureAwait(false);
                var clientVehicle = ModelConverters.Vehicles.VehicleConverter.Convert(vehicle);
                var route         = await routeRepository.GetAsync(item.Route, cancellationToken).ConfigureAwait(false);
                var checkpoints   = await checkpointRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
                var clientRoute   = ModelConverters.Routes.RouteConverter.Convert(route, checkpoints);
                var mechanicNote  = await mechanicNoteRepository.GetAsync(item.MechanicNote, cancellationToken)
                                    .ConfigureAwait(false);
                var medicNotesCount = route.Checkpoints.Count + 1;
                var medicNotes      = new Models.MedicNotes.MedicNote[medicNotesCount];

                for (var i = 0; i < medicNotesCount; i++)
                {
                    medicNotes[i] = await medicNoteRepository.CreateAsync(cancellationToken).ConfigureAwait(false);
                }

                var clientMechanicNote = ModelConverters.MechanicNotes.MechanicNoteConverter.Convert(mechanicNote);
                var clientMedicNotes   = medicNotes.Select(ModelConverters.MedicNotes.MedicNoteConverter.Convert);

                return(WayBillConverter.Convert(item, clientDriver, clientVehicle, clientRoute, clientMechanicNote,
                                                clientMedicNotes));
            })
                                    .Select(item => item.Result)
                                    .ToImmutableList();

            return(Ok(clientWayBillList));
        }