public virtual List <DriverInCar> GetAllDriversInCars() { if (Assert.IsNullOrEmtpyOrWhitespace(_connectionString)) { return(null); } using (TaxiDataBaseContext taxiDataBaseContext = new TaxiDataBaseContext(new SqlConnection(_connectionString))) { try { List <DriverInCar> driversInCars = taxiDataBaseContext.GetTable <DriverInCar>().ToList <DriverInCar>(); driversInCars.ForEach(dIC => { dIC.Car = GetCar(dIC.CarId); dIC.Driver = GetDriver(dIC.DriverId); }); return(driversInCars); } catch (Exception exc) { Logger.Error(exc); return(null); } } }
public virtual List <Driver> GetAllDrivers() { if (Assert.IsNullOrEmtpyOrWhitespace(_connectionString)) { return(null); } using (TaxiDataBaseContext taxiDataBaseContext = new TaxiDataBaseContext(new SqlConnection(_connectionString))) { try { var drivers = taxiDataBaseContext.GetTable <Driver>().ToList <Driver>(); return(drivers); } catch (Exception exc) { Logger.Error(exc); return(null); } } }
public virtual Car GetCar(int id) { if (Assert.IsNullOrEmtpyOrWhitespace(_connectionString) || !Assert.IsPositive(id)) { return(null); } using (TaxiDataBaseContext taxiDatabaseContext = new TaxiDataBaseContext(new SqlConnection(_connectionString))) { try { Car car = taxiDatabaseContext.GetTable <Car>().First(c => c.Id == id); return(car); } catch (Exception exc) { Logger.Error(exc); return(null); } } }
public virtual Passenger GetPassenger(int id) { if (Assert.IsNullOrEmtpyOrWhitespace(_connectionString) || !Assert.IsPositive(id)) { return(null); } using (TaxiDataBaseContext taxiDataBaseContext = new TaxiDataBaseContext(new SqlConnection(_connectionString))) { try { Passenger passenger = taxiDataBaseContext.GetTable <Passenger>().First <Passenger>(p => p.Id == id); return(passenger); } catch (Exception exc) { Logger.Error(exc); return(null); } } }
public virtual bool AddDriverInCar(DriverInCar driverInCar) { if (Assert.IsNullOrEmtpyOrWhitespace(_connectionString) || Assert.IsNull(driverInCar)) { return(false); } using (TaxiDataBaseContext taxiDataBaseContext = new TaxiDataBaseContext(new SqlConnection(_connectionString))) { try { taxiDataBaseContext.DriversInCars.InsertOnSubmit(driverInCar); taxiDataBaseContext.SubmitChanges(); return(true); } catch (Exception exc) { Logger.Error(exc); return(false); } } }
public virtual List <Order> GetAllOrders() { if (Assert.IsNullOrEmtpyOrWhitespace(_connectionString)) { return(null); } using (TaxiDataBaseContext taxiDataBaseContext = new TaxiDataBaseContext(new SqlConnection(_connectionString))) { try { List <Order> orders = taxiDataBaseContext.GetTable <Order>().ToList <Order>(); orders.ForEach(o => o.Passenger = GetPassenger(o.PassengerId)); return(orders); } catch (Exception exc) { Logger.Error(exc); return(null); } } }
public virtual DriverInCar GetDriverInCar(int id) { if (Assert.IsNullOrEmtpyOrWhitespace(_connectionString) || !Assert.IsPositive(id)) { return(null); } using (TaxiDataBaseContext taxiDataBaseContext = new TaxiDataBaseContext(new SqlConnection(_connectionString))) { try { DriverInCar driverInCar = taxiDataBaseContext.GetTable <DriverInCar>().First <DriverInCar>(d => d.Id == id); driverInCar.Car = GetCar(driverInCar.CarId); driverInCar.Driver = GetDriver(driverInCar.DriverId); return(driverInCar); } catch (Exception exc) { Logger.Error(exc); return(null); } } }