static void Main(string[] args) { IMemento memento; VehicleOption option1 = new VehicleOption("Asientos en cuero"); VehicleOption option2 = new VehicleOption("Reclinables"); VehicleOption option3 = new VehicleOption("Asientos deportivos"); option1.AddIncompatibleOption(option3); option2.AddIncompatibleOption(option3); OptionsCar optionsCar = new OptionsCar(); optionsCar.AddOption(option1); optionsCar.AddOption(option2); optionsCar.Preview(); memento = optionsCar.AddOption(option3); optionsCar.Preview(); optionsCar.Anulate(memento); optionsCar.Preview(); Console.ReadKey(); }
public bool InitTrip(TripOperation trip) { //Địa chỉ đón var from = new AddressInfo() { Address = trip.DiaChiDon, Name = trip.DiaChiDon, LatLng = new LatLng() { Lat = trip.ToaDoDon.Lat, Lng = trip.ToaDoDon.Lng } }; //Địa chỉ trả var to = new AddressInfo { Address = trip.DiaChiTra, Name = trip.DiaChiTra, LatLng = new LatLng() { Lat = trip.ToaDoTra.Lat, Lng = trip.ToaDoTra.Lng } }; // Danh sách xe đề cử var vehicleOptions = new List <VehicleOption>(); if (trip.XeDieuChiDinh != null) { foreach (var s in trip.XeDieuChiDinh) { var vehicle = new VehicleOption(); vehicle.Vehicle = s.VehicleName; // Biển số vehicle.Distance = s.Distance; // Khoảng cách vehicleOptions.Add(vehicle); } } byte carType = 0; if (trip.CarType == "" || trip.CarType.Split(',').Length > 1) { carType = 0; } else { carType = trip.CarType.To <byte>(); } var CurrentLatLng = new LatLng(); return(Service.TryGet( p => p.SendInitTrip(trip.BookId.Value, @from, to, trip.Note, trip.Quantity, carType, trip.CustomerType, trip.Phone, vehicleOptions.ToArray(), CurrentLatLng)).Value); }
public VehicleOption GetOption(string name) { VehicleOption result; if (options.ContainsKey(name)) { result = options[name]; } else { result = new VehicleOption(name); options.Add(name, result); } return(result); }
public IMemento AddOption(VehicleOption option) { MementoImpl memento = new MementoImpl { State = options }; IList <VehicleOption> incompatiblesOptions = option.IncompatiblesOptions; foreach (var item in incompatiblesOptions) { options.Remove(item); } options.Add(option); return(memento); }