Esempio n. 1
0
        private async Task <ServiceResult <bool> > VehicleToTollUpdate(TollEventRegistration body, long tollEventId)
        {
            var vehicle = await _tollService.SelectVehicle(body.RegistrationNumber);

            if (vehicle == null)
            {
                var vehicleType = await _tollService.SelectVehicleType(body.VehicleType);

                var vehicleResult = await _tollService.AddVehicle(new Vehicle
                {
                    VehicleType        = vehicleType,
                    RegistrationNumber = body.RegistrationNumber
                });

                //Här vill man självklart ha en riktig lösning
                if (!vehicleResult.IsSuccessStatusCode())
                {
                    return(new ServiceResult <bool>(vehicleResult.Exception));
                }

                vehicle = vehicleResult.Result;
            }

            var updateResult = await _tollService.SetTollEventVehicle(tollEventId, vehicle.Id);

            if (!updateResult.IsSuccessStatusCode())
            {
                return(new ServiceResult <bool>(updateResult.Exception));
            }

            return(new ServiceResult <bool>(true));
        }
Esempio n. 2
0
        public async Task <IActionResult> RegisterTollEvent([FromBody] TollEventRegistration body)
        {
            var insertResult = await _tollService.AddTollEvent(new VehicleTollEvent
            {
                EventTime          = body.EventTime.Value,
                RegistrationNumber = body.RegistrationNumber
            });

            if (!insertResult.IsSuccessStatusCode())
            {
                return(insertResult.ToHttpResult());
            }

            // Här hade man kunnat låta processen fortsätta på annan tråd i bakgrunden.
            var updateResult = await VehicleToTollUpdate(body, insertResult.Result.Id);

            if (!updateResult.IsSuccessStatusCode())
            {
                return(updateResult.ToHttpResult());
            }

            return(Ok(body));
        }