private void OnRemoveCarExecute()
        {
            var carToRemove = SelectedAddedCar;

            Rent.ClassModel.Cars.Remove(carToRemove);
            AddedCars.Remove(carToRemove);
            AvailableCars.Add(carToRemove);
            HasChanges = this.rentRepository.HasChanges();
            ((DelegateCommand)SaveCommand).RaiseCanExecuteChanged();
        }
        private void SetupPicklist()
        {
            var rentCarIds    = Rent.ClassModel.Cars.Select(c => c.Id).ToList();
            var addedCars     = this.allCars.Where(c => rentCarIds.Contains(c.Id)).OrderBy(c => c.Brand);
            var availableCars = this.allCars.Except(addedCars).OrderBy(c => c.Brand);

            AddedCars.Clear();
            AvailableCars.Clear();
            foreach (var addedCar in addedCars)
            {
                AddedCars.Add(addedCar);
            }

            foreach (var availableCar in availableCars)
            {
                AvailableCars.Add(availableCar);
            }
        }
Beispiel #3
0
        private async Task CreateACarAsync()
        {
            using (UserDialogs.Instance.Loading("Loading"))
            {
                SelectedCar.RentId = CurrentRent.Id;
                var json = JsonConvert.SerializeObject(SelectedCar);
                var g    = json.Remove(1, 7);
                App.client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");
                HttpContent httpContent = new StringContent(g, Encoding.UTF8, "application/json");
                var         response    = await App.client.PostAsync(App.API_URL_BASE + "cars", httpContent);

                if (response.IsSuccessStatusCode)
                {
                    UserDialogs.Instance.Alert("Vetura u shtua me sukses", "Sukses", "OK");
                }
                else
                {
                    UserDialogs.Instance.Alert("Vetura nuk u shtua me sukses", "Error", "OK");
                }
                var responseString = await response.Content.ReadAsStringAsync();

                Car addedCar = JsonConvert.DeserializeObject <Car>(responseString);
                if (Cars != null && !Cars.Any())
                {
                    Cars = new ObservableCollection <Car>();
                }
                Cars.Add(addedCar);
                HasCars = Cars.Any();
                OnPropertyChanged("Cars");
                OnPropertyChanged("HasCars");
                HasAvailableCars = true;
                AvailableCars.Add(addedCar);
                OnPropertyChanged("HasAvailableCars");
                OnPropertyChanged("AvailableCars");
            }
        }
Beispiel #4
0
        private async Task KtheVeturenAsync()
        {
            using (UserDialogs.Instance.Loading("Loading"))
            {
                CurrentRentedCar.KohaAktualeEKthimit = DateTime.Now;
                var json = JsonConvert.SerializeObject(CurrentRentedCar);
                App.client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");
                HttpContent httpContent = new StringContent(json, Encoding.UTF8, "application/json");
                var         response    = await App.client.PutAsync(App.API_URL_BASE + "rentedcars/update", httpContent);

                if (response.IsSuccessStatusCode)
                {
                    //UserDialogs.Instance.Alert("Vetura u kthye me sukses", "Sukses", "OK");
                }
                else
                {
                    //UserDialogs.Instance.Alert("Vetura nuk u kthye  me sukses", "Error", "OK");
                    IsSuccess = false;
                    return;
                }
                var responseString = await response.Content.ReadAsStringAsync();

                RentedCar addedCar = JsonConvert.DeserializeObject <RentedCar>(responseString);
                IsSuccessfullRent = addedCar != null ? true : false;
                var page = new PostRentedCarPage();
                page.BindingContext = this;
                IsSuccess           = true;
                var car = TakenCars.FirstOrDefault(x => x.Id == addedCar.CarId);
                LatestTransactionsFinished.Add(addedCar);
                LatestTransactionsOnGoing.Remove(addedCar);
                if (LatestTransactionsFinished.Count > 5)
                {
                    App.instance.DashboardViewModel.LatestTransactions.RemoveAt(0);
                }
                RentedCarsByRentId.Remove(CurrentRentedCar);
                RentedCarsByRentId.Add(addedCar);
                var     teHyrat = RentedCarsByRentId.ToList().FindAll(x => x.IsFinished && x.KohaELeshimit >= DateTime.Now.AddMonths(-1));
                decimal count   = 0.00m;
                foreach (var item in teHyrat)
                {
                    count += (decimal)item.DitetELeshimit * item.CmimiDitor;
                }
                TeHyrat = count;
                OnPropertyChanged("TeHyrat");
                car.Statusi = Car.StatusTypes.Aktiv;
                car.Km      = CurrentRentedCar.KilometrazhiAktual;
                AvailableCars.Add(car);
                TakenCars.Remove(car);
                var ongoing = LatestTransactionsOnGoing.FirstOrDefault(x => x.Id == addedCar.Id);
                if (ongoing != null)
                {
                    LatestTransactionsOnGoing.Remove(ongoing);
                }
                OnPropertyChanged("LatestTransactionsOnGoing");
                HasTakenCars     = TakenCars.Any();
                HasAvailableCars = AvailableCars.Any();
                OnPropertyChanged("HasTakenCars");
                await Task.Delay(500);

                App.instance.ChangeDetailPage(page);
            }
        }