Exemple #1
0
        public void Init(bool isEditMode, string vehicleId, string plateNumber, string type)
        {
            IsEditMode  = isEditMode;
            Title       = isEditMode ? "Edit Event" : "Add Event";
            ButtonTitle = isEditMode ? "Edit" : "Add";

            //demo data
            VehicleTypes.Add(new VehicleTypeItemViewModel()
            {
                Type = "compact",
            });
            VehicleTypes.Add(new VehicleTypeItemViewModel()
            {
                Type = "sedan"
            });

            PlateNumber = !string.IsNullOrEmpty(plateNumber) ? plateNumber : string.Empty;
            if (!string.IsNullOrEmpty(type))
            {
                var vehicleType = VehicleTypes.FirstOrDefault(x => x.Type.Equals(type));
                if (vehicleType != null)
                {
                    vehicleType.IsChecked = true;
                }
            }

            VehicleId = vehicleId;
        }
        private void Done()
        {
            var isChecked = VehicleTypes.FirstOrDefault(x => x.IsChecked == true);

            if (isChecked != null)
            {
                mCacheService.NextStatus = AddSpotStatus.SpotCost;
                mCacheService.CreateParkingRequest.CarType = isChecked.Type;
                Close(this);
            }
            else
            {
                Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, Mvx.Resolve <ICacheService>().TextSource.GetText("PleaseChooseSpotSizeText")));
            }
        }
        private void VehicleItemClick(VehicleTypeItemViewModel item)
        {
            foreach (var vehicleItemViewModel in VehicleTypes)
            {
                vehicleItemViewModel.IsChecked = false;
            }

            item.IsChecked = true;

            //get checked size
            var isChecked = VehicleTypes.FirstOrDefault(x => x.IsChecked == true);

            mCacheService.CreateParkingRequest.CarType = isChecked.Type;
            mCacheService.NextStatus = AddSpotStatus.SpotCost;
            Close(this);
        }
Exemple #4
0
        private async void AddNewVehicle()
        {
            if (BaseView != null && BaseView.CheckInternetConnection())
            {
                var isChecked = VehicleTypes.FirstOrDefault(x => x.IsChecked == true);
                if (isChecked != null && !string.IsNullOrEmpty(PlateNumber))
                {
                    Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true));

                    if (IsEditMode)
                    {
                        var result = await mApiService.PutVehicle(mCacheService.CurrentUser.UserId, VehicleId, isChecked.Type, PlateNumber);

                        if (result != null)
                        {
                            //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result));
                            //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.Status.Equals("success"))
                            {
                                Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status));
                            }
                            else
                            {
                                Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null));
                            }

                            //update user vehicles that has been cached
                            if (result.Response.Status.Equals("success"))
                            {
                                var vehicle = mCacheService.UserVehicles.FirstOrDefault(x => x.VehicleId.Equals(VehicleId));
                                if (vehicle != null)
                                {
                                    vehicle.Type        = isChecked.Type;
                                    vehicle.PlateNumber = PlateNumber;
                                }
                                Mvx.Resolve <IMvxMessenger>().Publish(new UpdateSuccessMessage(this));
                                //save to local database
                                BlobCache.UserAccount.InsertObject <List <Vehicle> >(mCacheService.CurrentUser.UserId, mCacheService.UserVehicles);
                            }

                            Close(this);
                        }
                    }
                    else
                    {
                        var result = await mApiService.CreateVehicle(mCacheService.CurrentUser.UserId, isChecked.Type, PlateNumber);

                        if (result != null)
                        {
                            //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result + "\n" + result.VehicleId));
                            //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.Status.Equals("success"))
                            {
                                Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status));
                            }
                            else
                            {
                                Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null));
                            }
                            if (result.Response.Status.Equals("success"))
                            {
                                var vehicle = new Vehicle()
                                {
                                    VehicleId   = result.Response.VehicleId,
                                    Type        = isChecked.Type,
                                    PlateNumber = PlateNumber
                                };
                                if (!mCacheService.UserVehicles.Contains(vehicle))
                                {
                                    mCacheService.UserVehicles.Add(vehicle);
                                }
                                Mvx.Resolve <IMvxMessenger>().Publish(new UpdateSuccessMessage(this));
                                //save to local database
                                BlobCache.UserAccount.InsertObject <List <Vehicle> >(mCacheService.CurrentUser.UserId, mCacheService.UserVehicles);
                            }

                            Close(this);
                        }
                    }


                    Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false));
                }
                else
                {
                    Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, isChecked != null ? mCacheService.TextSource.GetText("PleaseEnterPlateNumberText") : mCacheService.TextSource.GetText("PleaseChooseVehicleTypeText")));
                }
            }
            else
            {
                Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText")));
            }
        }