Пример #1
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);
            }
        }
Пример #2
0
        public async Task <Rent> LoadRentById(int id)
        {
            try
            {
                HttpClient httpClient = new HttpClient();
                var        response   = await App.client.GetAsync(App.API_URL_BASE + "rents/" + id);

                if (response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    UserDialogs.Instance.Alert("Probleme me server, Provoni Perseri", "Error", "Ok");
                    return(null);
                }
                else
                {
                    var responseString = await response.Content.ReadAsStringAsync();

                    var Rent = JsonConvert.DeserializeObject <Rent>(responseString);
                    var responseForRentedCars = await App.client.GetAsync(App.API_URL_BASE + "rentedcars/rent/" + Rent.Id);

                    RentedCarsByRentId = JsonConvert.DeserializeObject <ObservableCollection <RentedCar> >(await responseForRentedCars.Content.ReadAsStringAsync());
                    if (RentedCarsByRentId != null)
                    {
                        var list = RentedCarsByRentId.OrderBy(i => i.DitetELeshimit);
                        foreach (var item in list)
                        {
                            if (LatestTransactions.Count < 5)
                            {
                                LatestTransactions.Add(item);
                            }
                            if (item.KohaEKthimit > DateTime.Now && LatestTransactionsOnGoing.Count < 5 && !item.IsFinished)
                            {
                                LatestTransactionsOnGoing.Add(item);
                            }
                            if (item.KohaEKthimit < DateTime.Now && LatestTransactionsLate.Count < 5)
                            {
                                LatestTransactionsLate.Add(item);
                            }
                            if (item.IsFinished && LatestTransactionsFinished.Count < 5)
                            {
                                LatestTransactionsFinished.Add(item);
                            }
                        }
                        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;
                    }
                    HasLatestTransactions         = LatestTransactions.Any();
                    HasLatestTransactionsFinished = LatestTransactionsFinished.Any();
                    HasLatestTransactionsLate     = LatestTransactionsLate.Any();
                    HasLatestTransactionsOnGoing  = LatestTransactionsOnGoing.Any();
                    OnPropertyChanged("HasLatestTransactions");
                    OnPropertyChanged("HasLatestTransactionsFinished");
                    OnPropertyChanged("HasLatestTransactionsLate");
                    OnPropertyChanged("HasLatestTransactionsOnGoing");

                    return(Rent);
                }
            }
            catch (Exception e)
            {
                return(null);
            }
        }