Ejemplo n.º 1
0
        private void getVehicles()
        {
            Vehicles.Clear();
            allVehicles.ToList().ForEach(i => Vehicles.Add(i));

            if (SelectedKit != null)
            {
                List <VehicleModel> tmp = Vehicles.ToList()
                                          .Where(i => i.vehicle.KitFK == selectedKit.Id)
                                          .ToList();

                Vehicles.Clear();
                tmp.ForEach(i => Vehicles.Add(i));
            }

            if (SelectedEngine != null)
            {
                List <VehicleModel> tmp = Vehicles.ToList()
                                          .Where(i => i.vehicle.EngineFK == selectedEngine.Id)
                                          .ToList();

                Vehicles.Clear();
                tmp.ForEach(i => Vehicles.Add(i));
            }

            if (SelectedColor != null)
            {
                List <VehicleModel> tmp = Vehicles.ToList()
                                          .Where(i => i.vehicle.ColorFK == selectedColor.Id)
                                          .ToList();

                Vehicles.Clear();
                tmp.ForEach(i => Vehicles.Add(i));
            }
        }
Ejemplo n.º 2
0
 private void GetVehicles()
 {
     try
     {
         Vehicles.Clear();
         var service = Infrastructure.Container.GetInstance <IVtsWebService>();
         if (LoggedUserContext.LoggedUser == null)
         {
             return;
         }
         foreach (VehicleDto vehicleDto in service.GetVehiclesForUser(
                      LoggedUserContext.LoggedUser.Login,
                      LoggedUserContext.LoggedUser.PasswordHash))
         {
             vehicles.Add(new VehicleViewModel(
                              VehicleAssembler.FromDtoToDomainObject(vehicleDto)));
         }
     }
     catch (Exception e)
     {
         const string message = "Can not get vehicles for current user.";
         Log.Error(e, message);
         ErrorWindow w = new ErrorWindow(e, message);
         w.ShowDialog();
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a vehicle to this drivers list TODO
        /// </summary>
        /// <param name="model"></param>
        /// <param name="removeOld"></param>
        /// <param name="putInDriver"></param>
        public void AddVehicle(uint model, Vector3 position, bool removeOld = true, bool putInDriver = true)
        {
            //Remove all vehicles
            if (removeOld && this.Vehicles.Count > 0)
            {
                foreach (var vehicleObj in this.Vehicles)
                {
                    if (vehicleObj != null)
                    {
                        DeleteVehicle(vehicleObj);
                    }
                }

                Vehicles.Clear();
            }

            Vehicle vehicle = null;

            NAPI.Task.Run(() =>
            {
                vehicle = NAPI.Vehicle.CreateVehicle(model, position, 0f, 0, 0, engine: false);
                vehicle.PrimaryColor     = Rnd.Next(158);
                vehicle.SecondaryColor   = Rnd.Next(158);
                vehicle.NumberPlate      = this.NumberPlate;
                vehicle.NumberPlateStyle = Rnd.Next(6);

                if (putInDriver)
                {
                    NAPI.Player.SetPlayerIntoVehicle(Client, vehicle, -1);
                }

                NAPI.Pools.GetAllVehicles().Add(vehicle);
                this.Vehicles.Add(vehicle);
            });
        }
Ejemplo n.º 4
0
        private async Task InitAsync(Film film)
        {
            IsLoading = true;
            if (film != null)
            {
                Film = film;

                Species.Clear();
                foreach (var specy in film.species)
                {
                    var currentSpecy = await _speciesRepository.GetSpecieAsync(specy) ??
                                       await _dataService.GetSingleByUrl <Specie>(specy);

                    Species.Add(currentSpecy);
                }
                Species = Species.OrderBy(item => item.name).ToObservableCollection();

                Starships.Clear();
                foreach (var starship in film.starships)
                {
                    var currentStarship = await _starshipRepository.GetStarshipAsync(starship) ??
                                          await _dataService.GetSingleByUrl <Starship>(starship);

                    Starships.Add(currentStarship);
                }
                Starships = Starships.OrderBy(item => item.name).ToObservableCollection();

                Vehicles.Clear();
                foreach (var vehicle in film.vehicles)
                {
                    var currentVehicle = await _vehiclesRepository.GetVehicleAsync(vehicle) ??
                                         await _dataService.GetSingleByUrl <Vehicle>(vehicle);

                    Vehicles.Add(currentVehicle);
                }
                Vehicles = Vehicles.OrderBy(item => item.name).ToObservableCollection();

                People.Clear();
                foreach (var character in film.characters)
                {
                    var currentPeople = await _peopleRepository.GetPeopleAsync(character) ??
                                        await _dataService.GetSingleByUrl <People>(character);

                    People.Add(currentPeople);
                }
                People = People.OrderBy(item => item.name).ToObservableCollection();

                Planets.Clear();
                foreach (var planet in film.planets)
                {
                    var currentPlanet = await _planetRepository.GetPlanetAsync(planet) ??
                                        await _dataService.GetSingleByUrl <Planet>(planet);

                    Planets.Add(currentPlanet);
                }
                Planets = Planets.OrderBy(item => item.name).ToObservableCollection();
            }
            IsLoading = false;
        }
Ejemplo n.º 5
0
        public override bool AddVehicle(Vehicle vehicle)
        {
            bool result = false;

            if (CoordInGrid(vehicle.Position))
            {
                Vehicles.Clear();
                Vehicles.Add(vehicle);
                result = true;
            }

            return(result);
        }
        public async void GetVehicles()
        {
            IsEditMode = false;
            SwitchToDefaultMode();

            //load user vehicles from cache
            if (mCacheService.UserVehicles != null)
            {
                Vehicles.Clear();
                foreach (var vehicle in mCacheService.UserVehicles)
                {
                    Vehicles.Add(new VehicleItemViewModel(this)
                    {
                        Vehicle = vehicle
                    });
                }

                return;
            }

            if (BaseView != null && BaseView.CheckInternetConnection())
            {
                Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true));

                var vehicles = await mApiService.GetVehicles(mCacheService.CurrentUser.UserId);

                if (vehicles != null && vehicles.Response.Count > 0)
                {
                    Vehicles.Clear();
                    foreach (var vehicle in vehicles.Response)
                    {
                        Vehicles.Add(new VehicleItemViewModel(this)
                        {
                            Vehicle = vehicle
                        });
                    }

                    //cache all vehicles, to prevent reload the next attempt
                    mCacheService.UserVehicles = vehicles.Response;
                }

                Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false));
            }
            else
            {
                Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText")));
            }
        }
Ejemplo n.º 7
0
        public async Task LoadData(string userId, User userProfile)
        {
            this.userProfile = userProfile;
            currentVehicle   = null;
            Vehicles.Clear();
            bool isAuthenticated       = !string.IsNullOrWhiteSpace(userId) && InternetAccessIsAvailable;
            bool replaceCurrentVehicle = false;
            IMobileServiceTable <Vehicle> vehicleTable = isAuthenticated ? App.MobileService.GetTable <Vehicle>() : null;

            if (isAuthenticated)
            {
                IEnumerable <Vehicle> serverVehicles = await vehicleTable.Where(v => v.UserName == userId).ToEnumerableAsync();

                // If the vehicle is not the default and it does not already exist on the server then insert it
                if (CurrentVehicle != null && CurrentVehicle.Model != DEFAULT_VEHICLE.Model && !serverVehicles.Any(v => v.Key == CurrentVehicle.Key))
                {
                    var vehicleModel = CurrentVehicle.AsModel();
                    await vehicleTable.InsertAsync(vehicleModel);

                    CurrentVehicle.Id = vehicleModel.id;
                    Vehicles.Add(CurrentVehicle);
                }
                else
                {
                    replaceCurrentVehicle = true;
                }
                foreach (var serverVehicle in serverVehicles)
                {
                    Vehicles.Add(serverVehicle.AsViewModel());
                }
            }
            else if (CurrentVehicle != null)
            {
                Vehicles.Add(currentVehicle);
            }

            if (!Vehicles.Any())
            {
                Vehicles.Add(DEFAULT_VEHICLE);
                CurrentVehicle = DEFAULT_VEHICLE;
            }
            else if (CurrentVehicle == null || replaceCurrentVehicle)
            {
                // Either select the first vehicle OR refresh the current vehicle details from the server
                CurrentVehicle = CurrentVehicle == null?Vehicles.First() : Vehicles.SingleOrDefault(v => v.Key == CurrentVehicle.Key) ?? Vehicles.First();
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Disposes of the fleet. Does not dispose of the individual ships; they are removed from the fleet instead.
 /// </summary>
 public void Dispose()
 {
     if (IsDisposed)
     {
         return;
     }
     IsDisposed = true;
     foreach (var v in Vehicles.ExceptSingle(null))
     {
         v.Container = null;
     }
     Vehicles.Clear();
     Galaxy.Current.UnassignID(this);
     Sector = null;
     Orders.Clear();
     if (!IsMemory)
     {
         this.UpdateEmpireMemories();
     }
 }
Ejemplo n.º 9
0
        private async Task InitAsync(Specie specie)
        {
            IsLoading = true;

            if (specie != null)
            {
                Specie = specie;

                Movies.Clear();
                if (specie.films.HasItems())
                {
                    foreach (var film in specie.films)
                    {
                        var currentFilm = await _filmRepository.GetFilmAsync(film) ??
                                          await _dataService.GetSingleByUrl <Film>(film);

                        Movies.Add(currentFilm);
                    }
                    Movies = Movies.OrderBy(item => item.episode_id).ToObservableCollection();
                }
                People.Clear();
                if (specie.people.HasItems())
                {
                    foreach (var person in specie.people)
                    {
                        var currentPerson = await _peopleRepository.GetPeopleAsync(person) ??
                                            await _dataService.GetSingleByUrl <People>(person);

                        People.Add(currentPerson);
                    }
                    People = People.OrderBy(item => item.name).ToObservableCollection();
                }
                Starships.Clear();
                if (specie.starships.HasItems())
                {
                    foreach (var starship in specie.starships)
                    {
                        var currentStarship = await _starshipRepository.GetStarshipAsync(starship) ??
                                              await _dataService.GetSingleByUrl <Starship>(starship);

                        Starships.Add(currentStarship);
                    }
                    Starships = Starships.OrderBy(item => item.name).ToObservableCollection();
                }
                Vehicles.Clear();
                if (specie.vehicles.HasItems())
                {
                    foreach (var vehicle in specie.vehicles)
                    {
                        var currentVehicle = await _vehiclesRepository.GetVehicleAsync(vehicle) ??
                                             await _dataService.GetSingleByUrl <Vehicle>(vehicle);

                        Vehicles.Add(currentVehicle);
                    }
                    Vehicles = Vehicles.OrderBy(item => item.name).ToObservableCollection();
                }

                if (specie.homeworld.IsNeitherNullNorEmpty())
                {
                    HomeWorld = await _planetRepository.GetPlanetAsync(Specie?.homeworld) ??
                                await _dataService.GetSingleByUrl <Planet>(Specie?.homeworld);
                }
            }
            IsLoading = false;
        }
Ejemplo n.º 10
0
 private async Task LoadValues()
 {
     Vehicles.Clear();
     await LoadCurrentVehicles();
 }
Ejemplo n.º 11
0
 private void OnUserLoggedOff(object sender, EventArgs eventArgs)
 {
     Datasets.Clear();
     Vehicles.Clear();
 }
Ejemplo n.º 12
0
        private async Task InitAsync(People person)
        {
            IsLoading = true;

            if (person != null)
            {
                Person = person;

                Species.Clear();
                if (person.species != null && person.species.Count() > 1)
                {
                    foreach (var specy in person.species)
                    {
                        var currentSpecy = await _speciesRepository.GetSpecieAsync(specy) ??
                                           await _dataService.GetSingleByUrl <Specie>(specy);

                        Species.Add(currentSpecy);
                    }
                    Species = Species.OrderBy(item => item.name).ToObservableCollection();
                }
                else
                {
                    var specy = person.species.FirstOrDefault();
                    if (specy != null)
                    {
                        CurrentSpecie = await _speciesRepository.GetSpecieAsync(specy) ??
                                        await _dataService.GetSingleByUrl <Specie>(specy);
                    }
                }

                Starships.Clear();
                foreach (var starship in person.starships)
                {
                    var currentStarship = await _starshipRepository.GetStarshipAsync(starship) ??
                                          await _dataService.GetSingleByUrl <Starship>(starship);

                    Starships.Add(currentStarship);
                }
                Starships = Starships.OrderBy(item => item.name).ToObservableCollection();

                Vehicles.Clear();
                foreach (var vehicle in person.vehicles)
                {
                    var currentVehicle = await _vehiclesRepository.GetVehicleAsync(vehicle) ??
                                         await _dataService.GetSingleByUrl <Vehicle>(vehicle);

                    Vehicles.Add(currentVehicle);
                }
                Vehicles = Vehicles.OrderBy(item => item.name).ToObservableCollection();

                var movies = new ObservableCollection <Film>();
                foreach (var film in person.films)
                {
                    var currentFilm = await _filmRepository.GetFilmAsync(film) ??
                                      await _dataService.GetSingleByUrl <Film>(film);

                    movies.Add(currentFilm);
                }
                Movies = movies.OrderBy(item => item.episode_id).ToObservableCollection();

                HomeWorld = await _planetRepository.GetPlanetAsync(Person?.homeworld) ??
                            await _dataService.GetSingleByUrl <Planet>(Person?.homeworld);
            }
            IsLoading = false;
        }