Пример #1
0
        public async Task <IActionResult> Post([FromBody] StartRideDto newRide)
        {
            if (newRide == null)
            {
                return(BadRequest("Missing body"));
            }

            var taxi = await DbContext.Taxis.FirstOrDefaultAsync(t => t.ID == newRide.TaxiID);

            if (taxi == null)
            {
                return(NotFound("Taxi with specified ID not found"));
            }

            var driver = await DbContext.Drivers.FirstOrDefaultAsync(t => t.ID == newRide.DriverID);

            if (driver == null)
            {
                return(NotFound("Driver with specified ID not found"));
            }

            var newRideID = await DbContext.StartRideAsync(taxi, driver);

            return(StatusCode(201, await DbContext.Rides.FirstAsync(r => r.ID == newRideID)));
        }
Пример #2
0
        public static async Task <(Taxi Taxi, Driver Driver, int ID)> AddDummyRideAsync(this TaxiDataContext DbContext)
        {
            var newTaxi = await DbContext.AddDummyTaxiAsync();

            var newDriver = await DbContext.AddDummyDriverAsync();

            var newRideID = await DbContext.StartRideAsync(newTaxi.Taxi, newDriver.Driver);

            return(newTaxi.Taxi, newDriver.Driver, newRideID);
        }