public async Task <ActionResult <Nhaxe> > CreateGarageAsync(GarageCreateDto garage) { Nhaxe garageModel = _mapper.Map <Nhaxe>(garage); await _garageService.CreateGarageAsync(garageModel); return(CreatedAtRoute(nameof(GetGarageByIdAsync), new { id = garageModel.MaNhaXe }, garageModel)); }
public async Task DeleteGarageAsync(Nhaxe garage) { if (garage == null) { throw new ArgumentNullException(nameof(garage)); } // Find all routes of this route var busRoutes = await _context.Tuyenxes.Where(p => p.MaTuyenXe == garage.MaNhaXe).ToListAsync(); // Find all buses of this route var buses = await _context.Xes.Where(p => p.MaNhaXe == garage.MaNhaXe).ToListAsync(); // Find all trips of these routes foreach (var busRoute in busRoutes) { var busTrips = await _context.Chuyenxes.Where(p => p.MaTuyenXe == busRoute.MaTuyenXe).ToListAsync(); // Find and delete all tickets, seats that relations with those bus trips foreach (var busTrip in busTrips) { var ticketsByBusTrip = await _context.Vexes.Where(p => p.MaChuyenXe == busTrip.MaChuyenXe).ToListAsync(); _context.Vexes.RemoveRange(ticketsByBusTrip); } // Delete all trips that relations with this route _context.Chuyenxes.RemoveRange(busTrips); } _context.Tuyenxes.RemoveRange(busRoutes); _context.Xes.RemoveRange(buses); _context.Nhaxes.Remove(garage); await _context.SaveChangesAsync(); }
public async Task CreateGarageAsync(Nhaxe garage) { if (garage == null) { throw new ArgumentNullException(nameof(garage)); } _context.Nhaxes.Add(garage); await _context.SaveChangesAsync(); }
public async Task UpdateGarageAsync(Nhaxe garage) { await _context.SaveChangesAsync(); }