Exemplo n.º 1
0
        public async void GetParkingLists()
        {
            if (BaseView != null && BaseView.CheckInternetConnection())
            {
                if (Latitude == 0 && Longitude == 0 && mCacheService.SearchMode == SearchMode.Later)
                {
                    return;
                }

                if (mCacheService.CurrentLat == 0 && mCacheService.CurrentLng == 0)
                {
                    return;
                }

                //if (mCacheService.SearchMode == SearchMode.Now)
                //{
                Title = "Please choose";
                if (View != null)
                {
                    await Task.Delay(100);

                    View.Stop60sTimer();
                }
                //}

                IsShowParkingLists = false;
                Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true, string.Empty, true));
                long startTimeStamp = DateTime.UtcNow.DateTimeToTimeStamp();
                //long endTimeStamp = DateTime.UtcNow.AddHours(ParkingTime + 1).DateTimeToTimeStamp();
                long endTimeStamp = ValidTime.DateTimeToTimeStamp();

                if (StartTimeStamp != 0)
                {
                    startTimeStamp = StartTimeStamp;
                }


                Vehicle = mCacheService.SelectedVehicle;

                double lat = Latitude != 0 ? Latitude : mCacheService.CurrentLat;
                double lng = Longitude != 0 ? Longitude : mCacheService.CurrentLng;

                ParkingSlots.Clear();
                string maxdistance = string.Empty;
                if (StartTimeStamp == 0)
                {
                    maxdistance = "1000";
                }
                else
                {
                    maxdistance = "10000";
                }
                var parkings = await mApiService.AvaiableParkings(startTimeStamp, endTimeStamp, 2, lat, lng, maxdistance, Vehicle.Type);

                if (parkings != null && parkings.Response.Count != 0)
                {
                    ObservableCollection <ParkingSlotItemViewModel> Tmp = new ObservableCollection <ParkingSlotItemViewModel>();
                    foreach (var parking in parkings.Response)
                    {
                        if (mCacheService.SearchMode == SearchMode.Now && parking.BookingType == "delayed")
                        {
                            continue;
                        }
                        Tmp.Add(new ParkingSlotItemViewModel()
                        {
                            ParkingSpot = parking, IsShowClock = startTimeStamp < Convert.ToInt64(parking.AvailabilityStartTimestamp)
                        });
                    }
                    ParkingSlots = Tmp;
                }
                else
                {
                    Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "No parkings"));
                }

                Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false));
                IsShowParkingLists = true;
            }
            else
            {
                Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText")));
            }
        }
Exemplo n.º 2
0
        private async void GotoBooking(ParkingSlotItemViewModel itemVM)
        {
            /*if (BaseView != null &&  BaseView.CheckInternetConnection())
             * {
             * Mvx.Resolve<IMvxMessenger>().Publish(new ProgressMessage(this, true));
             * var result = await mApiService.CreateBooking("1","parkingId", 1101010101010 , 1010101010101, "carNumber");
             * if (result != null)
             * {
             * //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result + "\n" + result.BookingId));
             * Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result.Equals("success") ? result.Response.Result : string.Format("{0}: {1}", result.Response.Result, result.Response.ErrorCode)));
             * ShowViewModel<BookingViewModel>(new {timeout =  Int32.Parse(result.TimeoutDuration), cost = double.Parse(result.Cost), remainingCredits = Int32.Parse(result.RemainingCredits) });
             * }
             * Mvx.Resolve<IMvxMessenger>().Publish(new ProgressMessage(this, false));
             * }
             * else
             * {
             * Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText")));
             * }*/

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

                //                long startTimeStamp = DateTime.UtcNow.DateTimeToTimeStamp();
                //                long endTimeStamp = DateTime.UtcNow.AddHours(ParkingTime + 1).DateTimeToTimeStamp();

                long   startTimeStamp = ValidTime.AddHours(-(ParkingTime + 1)).DateTimeToTimeStamp();
                long   endTimeStamp   = ValidTime.DateTimeToTimeStamp();
                double toWait         = Math.Round((double)(DateTime.UtcNow.DateTimeToTimeStamp() - startTimeStamp) / 60);

                if (StartTimeStamp != 0)
                {
                    startTimeStamp = StartTimeStamp;
                    endTimeStamp   = startTimeStamp + ((ParkingTime + 1) * 3600);
                    toWait         = Math.Round((double)(startTimeStamp - DateTime.UtcNow.DateTimeToTimeStamp()) / 60);
                }

                if (itemVM.ParkingSpot.BookingType == "immediate")
                {
                    ShowViewModel <BookingViewModel>(new
                    {
                        parkingid        = itemVM.ParkingSpot.ParkingId,
                        distance         = double.Parse(itemVM.ParkingSpot.Distance, CultureInfo.InvariantCulture),
                        cost             = itemVM.ParkingSpot.Cost,
                        remainingCredits = double.Parse(mCacheService.CurrentUser.RemainingCredits, CultureInfo.InvariantCulture),
                        toWait           = toWait,
                        duration         = Math.Round((double)(endTimeStamp - startTimeStamp) / 3600),
                        startTimestamp   = startTimeStamp,
                        endTimestamp     = endTimeStamp
                    });
                }
                else if (itemVM.ParkingSpot.BookingType == "delayed")
                {
                    ShowViewModel <DelayedParkingMapViewModel>(new
                    {
                        parkingid      = itemVM.ParkingSpot.ParkingId,
                        startTimestamp = startTimeStamp,
                        endTimestamp   = endTimeStamp
                    });
                }

                //                var result = await mApiService.CreateBooking(Mvx.Resolve<ICacheService>().CurrentUser.UserId, itemVM.ParkingSpot.ParkingId, startTimeStamp, endTimeStamp, Vehicle.PlateNumber);
                //                if (result != null && result.Response != null)
                //                {
                //                    // Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result + "\n" + result.Response.BookingId));
                //                    //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result.Equals("success") ? result.Response.Result : string.Format("{0}: {1}", result.Response.Result, result.Response.ErrorCode)));
                //                    if (result.Response.Result.Equals("success"))
                //                    {
                //                        Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result));
                //                    }
                //                    else
                //                    {
                //                        Mvx.Resolve<IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Result, result.Response.ErrorCode), "Ok", null));
                //                    }


                //                }
                //                Mvx.Resolve<IMvxMessenger>().Publish(new ProgressMessage(this, false));
                //            }
                //            else
                //            {
                //                Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText")));
                //            }
            }
        }