public ActionResult FindDriver(String customerId, double Latitude, double Longitude) { DriverStoreReponsitory driverStoreReponsitory = new DriverStoreReponsitory(); List <DriverStore> listDriver = driverStoreReponsitory.GetAll(); if (listDriver.Count == 0) { return(NotFound("Không tìm được tài xế!!!")); } DriverStore minDriver = listDriver.First <DriverStore>(); foreach (var item in listDriver) { DriverStore tempDriver = item; if (Calculate(tempDriver.Latitude, tempDriver.Longitude, Latitude, Longitude) < Calculate(tempDriver.Latitude, tempDriver.Longitude, Latitude, Longitude)) { minDriver = tempDriver; } } Driver driver = _driverService.GetDriverInfo(new LoginRequest(minDriver.Email)); return(Ok(new { driver = driver, driverLocation = minDriver })); }
/* public DriverStore Add<DriverStore>(DriverStore driver) where DriverStore : BaseStore * { * CollectionReference colRef = fireStoreDb.Collection(collectionName); * DocumentReference doc = colRef.AddAsync(driver).GetAwaiter().GetResult(); * driver.DocumentId = doc.Id(); * return driver; * } * public bool Update<DriverStore>(DriverStore driver) where DriverStore : BaseStore * { * DocumentReference driverRef = fireStoreDb.Collection(collectionName).Document(driver.DocumentId); * driverRef.SetAsync(driver, SetOptions.MergeAll).GetAwaiter().GetResult(); * return true; * } * public bool Delete<DriverStore>(DriverStore driver) where DriverStore : BaseStore * { * DocumentReference driverRef = fireStoreDb.Collection(collectionName).Document(driver.DocumentId); * driverRef.DeleteAsync().GetAwaiter().GetResult(); * return true; * } * public DriverStore Get<DriverStore>(DriverStore driver) where DriverStore : BaseStore * { * DocumentReference docRef = fireStoreDb.Collection(collectionName).Document(driver.DocumentId); * DocumentSnapshot snapshot = docRef.GetSnapshotAsync().GetAwaiter().GetResult(); * if (snapshot.Exists) * { * DriverStore usr = snapshot.ConvertDriverStoreo<DriverStore>(); * usr.DocumentId = snapshot.Id; * return usr; * } * else * { * return null; * } * }*/ public List <DriverStore> GetAll() { Query query = fireStoreDb.Collection(collectionName); QuerySnapshot querySnapshot = query.GetSnapshotAsync().GetAwaiter().GetResult(); List <DriverStore> list = new List <DriverStore>(); foreach (DocumentSnapshot documentSnapshot in querySnapshot.Documents) { if (documentSnapshot.Exists) { DriverStore driverStore = new DriverStore(); driverStore.DocumentId = documentSnapshot.Id; driverStore.Latitude = Double.Parse(documentSnapshot.GetValue <string>("Latitude")); driverStore.Longitude = Double.Parse(documentSnapshot.GetValue <string>("Longitude")); driverStore.Status = documentSnapshot.GetValue <string>("Status"); driverStore.Rate = Double.Parse(documentSnapshot.GetValue <string>("Rate")); driverStore.Email = documentSnapshot.GetValue <string>("Email"); if (driverStore.Status == "1") { list.Add(driverStore); } } } return(list); }
private void BuildBus() { if (((BusBuilder)Builder).Car.Driver == null) { Builder.BoardDriver(DriverStore.GetDriver(typeof(BusDriver))); } while (((BusBuilder)Builder).Car.Passengers.Count != ((BusBuilder)Builder).Car.Capacity) { Passenger passenger = PassengerStore.GetPassenger(new HashSet <Type>() { typeof(Adult), typeof(Child), typeof(Preferential) }); switch (passenger) { case Child child: Builder.BoardChild(child); break; case Preferential preferential: Builder.BoardPreferential(preferential); break; case Adult adult: Builder.BoardAdult(adult); break; } } }
public int BoardDriver(DriverStore driverStore, int amount = 1) { if (Car.Driver == null && driverStore.Count(typeof(BusDriver)) != 0) { Car.Driver = driverStore.GetDriver(typeof(BusDriver)); return(amount - 1); } else { return(amount); } }
public DriverViewModel() { Drivers = new ObservableRangeCollection <Driver>(); LoadTrucksCommand = new Command(() => ExecuteLoadTrucksCommand()); DeleteCommand = new Command(() => ExecutedeleteCommand()); MessagingCenter.Subscribe <NewDriverPage, Driver>(this, "AddItem", async(obj, driver) => { var _driver = driver as Driver; Drivers.Add(_driver); await DriverStore.AddDriverAsync(_driver); }); }
public void DriverStore_ShouldAttachFunction_OnAttachActionCalled_WithCorrectParameters() { // arrange var drivers = new List <IWebDriver>(); var driverStore = new DriverStore(drivers); Func <IWebDriver, IWebDriver> action = driver => driver; // act driverStore.AttachAction(action); // assert Assert.AreEqual(driverStore.DriverAction.Method, action.Method); }
async void ExecuteLoadTrucksCommand() { try { Drivers.Clear(); var drivers = await DriverStore.GetDriversAsync(true); Drivers.ReplaceRange(drivers); } catch (Exception ex) { Debug.WriteLine(ex); MessagingCenter.Send(new MessagingCenterAlert { Title = "Error", Message = "Unable to load Trucks.", Cancel = "OK" }, "message"); } }
private void BuildTaxi() { if (((TaxiBuilder)Builder).Car.Driver == null) { Builder.BoardDriver(DriverStore.GetDriver(typeof(TaxiDriver))); } while (((TaxiBuilder)Builder).Car.Passengers.Count != ((TaxiBuilder)Builder).Car.Capacity) { Passenger passenger = PassengerStore.GetPassenger(new HashSet <Type>() { typeof(Adult), typeof(Child) }); switch (passenger) { case Child child: Builder.BoardChild(child); break; case Adult adult: Builder.BoardAdult(adult); break; } } }
async void ExecutedeleteCommand() { await DriverStore.DeleteDriverAsync(deleteDriver); }
public static void Main(string[] args) { List <string> names = new List <string>() { "John", "Jack", "Liz", "Alan", "Ann", "Ire", "Kate", "Mary", "Jane", "Sue", "Bill", "Will", "Hugh", "Alex", "Sandro", "Kris", "Lothar", "Karl", "Ingrid", "Aaron", "Darina", "Bianka", "Dan" }; List <string> surnames = new List <string>() { "Black", "Brown", "Scot", "Ericsson", "Jeferson", "Li", "Martel", "King", "Eir" }; Random rnd = new Random(); DriverStore driverStore = new DriverStore(); for (int i = 0; i < 5; i++) { driverStore.Add(new BusDriver( $"{names[rnd.Next(names.Count)]} {surnames[rnd.Next(surnames.Count)]}") ); driverStore.Add(new TaxiDriver( $"{names[rnd.Next(names.Count)]} {surnames[rnd.Next(surnames.Count)]}") ); } PassengerStore passengerStore = new PassengerStore(); for (int i = 0; i < 240; i++) { passengerStore.Add(new Adult( $"{names[rnd.Next(names.Count)]} {surnames[rnd.Next(surnames.Count)]}") ); passengerStore.Add(new Child( $"{names[rnd.Next(names.Count)]} {surnames[rnd.Next(surnames.Count)]}") ); passengerStore.Add(new Preferential( $"{names[rnd.Next(names.Count)]} {surnames[rnd.Next(surnames.Count)]}") ); } BusBuilder Krukovo = new BusBuilder(); TaxiBuilder Area17 = new TaxiBuilder(); Director director = new Director(Krukovo, driverStore, passengerStore); while (passengerStore.Count() != 0 && driverStore.Count(typeof(BusDriver)) != 0) { director.BuildCar(); Console.WriteLine(Krukovo.GetResult()); } director.Builder = Area17; while (passengerStore.Count() != 0 && driverStore.Count(typeof(TaxiDriver)) != 0) { director.BuildCar(); Console.WriteLine(Area17.GetResult()); } }
public static void Main(string[] args) { List <string> names = new List <string>() { "John", "Jack", "Liz", "Alan", "Ann", "Ire", "Kate", "Mary", "Jane", "Sue", "Bill", "Will", "Hugh", "Alex", "Sandro", "Kris", "Lothar", "Karl", "Ingrid", "Aaron", "Darina", "Bianka", "Dan" }; List <string> surnames = new List <string>() { "Black", "Brown", "Scot", "Ericsson", "Jeferson", "Li", "Martel", "King", "Eir" }; Random rnd = new Random(); DriverStore driverStore = new DriverStore(); for (int i = 0; i < 5; i++) { driverStore.Add(new BusDriver( $"{names[rnd.Next(names.Count)]} {surnames[rnd.Next(surnames.Count)]}") ); driverStore.Add(new TaxiDriver( $"{names[rnd.Next(names.Count)]} {surnames[rnd.Next(surnames.Count)]}") ); } PassengerStore passengerStore = new PassengerStore(); for (int i = 0; i < 140; i++) { passengerStore.Add(new BusPassenger( $"{names[rnd.Next(names.Count)]} {surnames[rnd.Next(surnames.Count)]}", $"ticket-{i}") ); passengerStore.Add(new TaxiPassenger( $"{names[rnd.Next(names.Count)]} {surnames[rnd.Next(surnames.Count)]}", rnd.NextDouble() * 10) ); } BoardBus Krukovo = new BoardBus(); while (passengerStore.Count(typeof(BusPassenger)) != 0 && driverStore.Count(typeof(BusDriver)) != 0) { int x = Krukovo.BoardDriver(driverStore); int y = Krukovo.BoardPassengers(passengerStore, 35); Console.WriteLine($"*{x}*{y}*"); Console.WriteLine(Krukovo.GetCar()); } BoardTaxi Area17 = new BoardTaxi(); while (passengerStore.Count(typeof(TaxiPassenger)) != 0 && driverStore.Count(typeof(TaxiDriver)) != 0) { int x = Area17.BoardDriver(driverStore); int y = Area17.BoardPassengers(passengerStore, 6); Console.WriteLine($"*{x}*{y}*"); Console.WriteLine(Area17.GetCar()); } }
public Director(IBuilder builder, DriverStore driverStore, PassengerStore passengerStore) { Builder = builder; DriverStore = driverStore; PassengerStore = passengerStore; }