public TableesViewModel()
 {
     Stolies          = new ObservableCollection <Models.Tables>();
     StolyDataService = new StolyDataService();
     PutItemsCommand  = new Xamarin.Forms.Command(async() => await PutTask(Stul));
     LoadItemsCommand = new Xamarin.Forms.Command(async() => await GetTask());
 }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new instance of the <see cref="RegistrationViewModel"/> class.
 /// For unit tests.
 /// <param name="tagProfile">The tag profile to work with.</param>
 /// <param name="uiDispatcher">The UI dispatcher for alerts.</param>
 /// <param name="settingsService">The settings service for persisting UI state.</param>
 /// <param name="neuronService">The Neuron service for XMPP communication.</param>
 /// <param name="cryptoService">The service to use for cryptographic operations.</param>
 /// <param name="navigationService">The navigation service to use for app navigation</param>
 /// <param name="networkService">The network and connectivity service.</param>
 /// <param name="logService">The log service.</param>
 /// <param name="imageCacheService">The image cache to use.</param>
 /// </summary>
 protected internal RegistrationViewModel(
     ITagProfile tagProfile,
     IUiDispatcher uiDispatcher,
     ISettingsService settingsService,
     INeuronService neuronService,
     ICryptoService cryptoService,
     INavigationService navigationService,
     INetworkService networkService,
     ILogService logService,
     IImageCacheService imageCacheService)
 {
     this.tagProfile        = tagProfile ?? DependencyService.Resolve <ITagProfile>();
     uiDispatcher           = uiDispatcher ?? DependencyService.Resolve <IUiDispatcher>();
     settingsService        = settingsService ?? DependencyService.Resolve <ISettingsService>();
     neuronService          = neuronService ?? DependencyService.Resolve <INeuronService>();
     cryptoService          = cryptoService ?? DependencyService.Resolve <ICryptoService>();
     this.navigationService = navigationService ?? DependencyService.Resolve <INavigationService>();
     networkService         = networkService ?? DependencyService.Resolve <INetworkService>();
     logService             = logService ?? DependencyService.Resolve <ILogService>();
     imageCacheService      = imageCacheService ?? DependencyService.Resolve <IImageCacheService>();
     GoToPrevCommand        = new Command(GoToPrev, () => (RegistrationStep)CurrentStep > RegistrationStep.Operator);
     RegistrationSteps      = new ObservableCollection <RegistrationStepViewModel>
     {
         this.AddChildViewModel(new ChooseOperatorViewModel(this.tagProfile, uiDispatcher, neuronService, this.navigationService, settingsService, networkService, logService)),
         this.AddChildViewModel(new ChooseAccountViewModel(this.tagProfile, uiDispatcher, neuronService, this.navigationService, settingsService, cryptoService, networkService, logService)),
         this.AddChildViewModel(new RegisterIdentityViewModel(this.tagProfile, uiDispatcher, neuronService, this.navigationService, settingsService, networkService, logService, imageCacheService)),
         this.AddChildViewModel(new ValidateIdentityViewModel(this.tagProfile, uiDispatcher, neuronService, this.navigationService, settingsService, networkService, logService, imageCacheService)),
         this.AddChildViewModel(new DefinePinViewModel(this.tagProfile, uiDispatcher, neuronService, this.navigationService, settingsService, logService))
     };
     SyncTagProfileStep();
     UpdateStepTitle();
 }
Exemplo n.º 3
0
        public UserVM()
        {
            Users = new ObservableCollection <Model.User>();

            CarregarCommand = new Xamarin.Forms.Command(async() =>
            {
                Running = true;
                Log     = "Rodando...";

                var result = await RemoteApi.Api.GetUsersAsync("");

                Users = new ObservableCollection <Model.User>(result);

                Running = false;
                Log     = "#Concluído#";

                /*
                 * Users.Add(new Model.User
                 * {
                 *  Id=Users.Count(),
                 *  Name=$"Anderson {Users.Count()} - {Guid.NewGuid().ToString().Replace("-","")}"
                 * });
                 *
                 * Users.Add(new Model.User
                 * {
                 *  Id = Users.Count(),
                 *  Name = $"Edneia {Users.Count()} - {Guid.NewGuid().ToString().Replace("-","")}"
                 * });
                 */
            });
        }
Exemplo n.º 4
0
 public PartUsage()
 {
     IncreaseAmountCommand = new Xamarin.Forms.Command(IncreaseAmount);
     DecreaseAmountCommand = new Xamarin.Forms.Command(DecreaseAmount);
     ShowPartCommand       = new AsyncCommand(ShowPart);
     Keeper = new PartKeeper();
 }
        public LinearAccelerationPageViewModel()
        {
            // Command to start the subscription
            ToggleSubscribeSwitchCommand = new Xamarin.Forms.Command(
                async() =>
            {
                if (IsSubscribeSwitchOn)
                {
                    ConnectionStatusText = "Connecting...";
                    await MovesenseDeviceVM.Connect();
                    ConnectionStatusText = "Subscribing...";

                    subscription = await MovesenseDeviceVM.MovesenseDevice.SubscribeAccelerometerAsync(
                        (d) =>
                    {
                        PlotData(d.Data.Timestamp, d.Data.AccData[0].X, d.Data.AccData[0].Y, d.Data.AccData[0].Z);
                    },
                        26);
                    ConnectionStatusText = "Subscribed";
                }
                else
                {
                    // Unsubscribe
                    subscription.Unsubscribe();
                    ConnectionStatusText = "Unsubscribed";
                    await MovesenseDeviceVM.Disconnect();
                    ConnectionStatusText = "Disconnected";
                }
            }
                , () => (MovesenseDeviceVM != null) // Enable command only if we've got a device
                );

            InitPlotModel();
        }
Exemplo n.º 6
0
 public RelationalItemDetailViewModel(SampleUserModel user = null)
 {
     IsBusy            = false;
     Title             = $"Orders for {user.Id}";
     User              = user;
     Orders            = new ObservableCollection <SampleOrderModel>();
     LoadOrdersCommand = new Command(async() => await ExecuteLoadOrdersCommand());
 }
Exemplo n.º 7
0
 public ToppingSelection(ToppingsPageModel referenceToParentClass)
 {
     parentToppingsPageModel    = referenceToParentClass;
     areWholeHalfColumnsVisible = true;
     AButtonCommand             = new Xamarin.Forms.Command(OnButtonAClick);
     BButtonCommand             = new Xamarin.Forms.Command(OnButtonBClick);
     WButtonCommand             = new Xamarin.Forms.Command(OnButtonWClick);
 }
Exemplo n.º 8
0
 public HomeViewModel()
 {
     CreateEventCommand  = new Xamarin.Forms.Command(OnCreateEventClicked);
     EventClickedCommand = new Xamarin.Forms.Command(OnEventClicked);
     RefreshCommand      = new AsyncCommand(Refresh);
     _eventDetails       = new EventDetailsRepository();
     Events = new ObservableRangeCollection <EventDetails>();
     DisplayEvents();
 }
Exemplo n.º 9
0
 public DoctorPatientReportsViewModel()
 {
     Title             = "Patient Reports";
     Reports           = new ObservableRangeCollection <Report>();
     RefreshCommand    = new AsyncCommand(Refresh);
     SelectedCommand   = new AsyncCommand <object>(Selected);
     GetReportsCommand = new AsyncCommand(GetReports);
     ClearListCommand  = new Xamarin.Forms.Command(ClearList);
 }
Exemplo n.º 10
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="container">Dependency injection container</param>
        public VMExplorePage(IContainer container, Page page)
        {
            Container  = container;
            Page       = page;
            Me         = Container.Resolve <ICharacterService>().GetCharacter();
            VMLocation = new VMLocation(Container, Me.Id);
            VMLocation.OnItemSelected += SelectItem;
            Inventory = new VMInventory(Container);
            Container.Resolve <IImageService>()
            .ReadAsync(new List <Guid>()
            {
                new Guid("a15e4ade-5fbe-4eb1-9d62-f1c1e67a207b")
            })
            .ContinueWith((task) =>
            {
                var image       = task.Result?.FirstOrDefault();
                BackgroundImage = image;
            });
            if (Me.ChildrenIds.Count() > 0)
            {
                Container.Resolve <IMessageService>().SendRequestAsync <CoreReadItemCrudResponse>(new CoreReadItemCrudRequest()
                {
                    ItemIds = Me.ChildrenIds
                }).ContinueWith(messageTask =>
                {
                    Inventory.Add(messageTask.Result.CoreReadItemCrudEvent.Items);
                });
            }
            MessageService = Container.Resolve <IMessageService>();
            IsAdmin        = Me.GetData <AccountData>().Admin;
            VMEmotes       = new VMEmotes(Container);
            var GameService = container.Resolve <IGameService>();

            GameService.OnMessage      += OnMessage;
            GameService.OnMessage      += VMLocation.OnMessage;
            LocationItemTable_OnClicked = new Xamarin.Forms.Command((object itemTableControl) =>
            {
                var control = (ItemTableControl)itemTableControl;
                SelectItem(control?.SelectedItem);
//                control.SetHighlight(SelectedItem);
            });
            ItemDescriptions_ItemOnCommand = new Xamarin.Forms.Command((object itemCommand) =>
            {
                OnItemCommand((ItemCommand)itemCommand);
            });
            ItemDescriptions_ItemOnSelect = new Xamarin.Forms.Command((object itemDescriptionsControl) =>
            {
                var control = (BotItemDescriptionsControl)itemDescriptionsControl;
                SelectItem((control.ItemSelectedLastStatus) ? control.ItemSelectedLast : null);
            });
            VMAdminPicker = new VMAdminPicker(Container, page, VMLocation);
            MessageService.SendRequestAsync <WorldReadLocationSummaryResponse>(new WorldReadLocationSummaryRequest()
            {
            });
        }
Exemplo n.º 11
0
        public JobViewCommonUserControlViewModel(object owner)
        {
            parentViewModel = (BaseViewModel)owner;
            Job selectedJob = null;

            if (parentViewModel is JobViewViewModel)
            {
                var jobViewViewModel = (JobViewViewModel)parentViewModel;
                selectedJob = jobViewViewModel.GetSelectedJob();
            }
            else if (parentViewModel is JobHistoryViewViewModel)
            {
                var jobHistoryViewViewModel = (JobHistoryViewViewModel)parentViewModel;
                selectedJob = jobHistoryViewViewModel.Job;
            }
            else if (parentViewModel is JobAcceptanceViewViewModel)
            {
                var jobAcceptanceViewViewModel = (JobAcceptanceViewViewModel)parentViewModel;
                selectedJob = jobAcceptanceViewViewModel.Job;
            }

            if (selectedJob != null)
            {
                UpdateView(selectedJob);
            }

            PlayRecordedCmd = new Xamarin.Forms.Command(e =>
            {
                PlayRecordedAudio();
            },
                                                        param =>
            {
                if (param == null)
                {
                    return(false);
                }

                var isBusy = (bool)param;
                return(!isBusy);
            });
            StopCmd = new Xamarin.Forms.Command(e =>
            {
                StopPlayingRecordedAudio();
            },
                                                param =>
            {
                if (param == null)
                {
                    return(false);
                }

                var isBusy = (bool)param;
                return(!isBusy);
            });
        }
        public SwitchMasterPage()
        {
            xam.NavigationPage.SetHasNavigationBar(this, false);

            GoBackCommand = new xam.Command(() => GoBack());

            var controlTemplate = (xam.ControlTemplate)xam.Application.Current.Resources["masterPage"];


            this.Effects.Add(xam.Effect.Resolve("Sterling.SafeAreaPaddingEffect"));

            this.Content = PageContent;
        }
 public SelectResidenceViewModel()
 {
     GetPlacesCommand      = new Xamarin.Forms.Command <string>(async param => await GetPlacesByName(param));
     GetPlaceDetailCommand =
         new Xamarin.Forms.Command <GooglePlaceAutoCompletePrediction>(
             async param => await GetPlacesDetail(param));
     Places = new ObservableRangeCollection <GooglePlaceAutoCompletePrediction>();
     GoogleMapsApiService.Initialize("AIzaSyAnMLFzwkR17l4TfHYiBou6ZXmPRsLgpNg");
     ClearSelectedPlaceCommand = new Command(() =>
     {
         SelectedPlace = null;
         PlaceSelected = null;
     });
     ConfirmSelectedPlaceCommand = new AsyncCommand(ConfirmPlace);
 }
Exemplo n.º 14
0
        public TelaPrincipalViewModel()
        {
            TarefaAtual         = new Tarefa();
            Tarefas             = new ObservableCollection <Tarefa>(new TarefasDataAccess().GetTarefas());
            SalvarTarefaCommand = new Xamarin.Forms.Command(SalvarTarefa); //Falhei na tentativa de implementar um command
            EditarTarefaCommand = new Xamarin.Forms.Command <Tarefa>(EditarTarefa);
            //ModificarTarefaCommand = new Xamarin.Forms.Command<Tarefa>(ModificarTarefa);

            /*
             * Aqui chamamos a classe que ficará responsavel por executar o command
             * Levando a própria classe como parametro atraves do this
             */
            ModificarTarefaCommand = new Command.ModificarTarefaCommand(this);
            ExcluirTarefaCommand   = new Xamarin.Forms.Command <Tarefa>(ExcluirTarefa);
        }
Exemplo n.º 15
0
 private void Networker_MessageAppended(string msg)
 {
     if (messages == "")
     {
         BTNmessageEnabled = true;
         BTNmessageClicked = new Xamarin.Forms.Command(async() =>
         {
             BTNmessageEnabled = false;
             await MyLogger.Alert(String.Join("\r\n", networker.messages));
             BTNmessageEnabled = true;
         });
     }
     messages += msg + "\r\n";
     UpdateStatus(2, msg);
     OnPropertyChanged("BTNmessageEnabled");
 }
Exemplo n.º 16
0
        public ScoreViewModel()
        {
            Title = "ScoreCard";

            Scores = new ObservableRangeCollection <Score>();
            //            OpenWebCommand = new Command(() => Device.OpenUri(new Uri("https://xamarin.com/platform")));

            Scores.CollectionChanged += (sender, args) =>
            {
                Debug.WriteLine($"Item {args.Action}");
            };
            GetScoresCommand = new Xamarin.Forms.Command(async() => await GetScoresAsync());

            BirdieCLickedCommand = new Xamarin.Forms.Command(BirdieClicked);
            ParClickedCommand    = new Xamarin.Forms.Command(ParClicked);
            BogeyClickedCommand  = new Xamarin.Forms.Command(BogeyClicked);
            SubmitClickedCommand = new Xamarin.Forms.Command(SubmitClicked);
            IncreaseCountCommand = new Xamarin.Forms.Command(IncreaseCount);
            PlusClickedCommand   = new Command(PlusClicked);
            MinusClickedCommand  = new Command(MinusClicked);
            HoleNoClickedCommand = new Command(HoleNoClicked);

            WhiteClickedCommand  = new Command(WhiteClicked);
            YellowClickedCommand = new Command(YellowClicked);
            BlueClickedCommand   = new Command(BlueClicked);
            RedClickedCommand    = new Command(RedClicked);
            OrangeClickedCommand = new Command(OrangeClicked);

            Courses = new ObservableCollection <Courses>();
            CourseManager.GetCourses(Courses, 1);
            TeeID = new ObservableCollection <Tee>();
            TeeManager.GetTees(TeeID);
            Players = new ObservableCollection <Player>();
            PlayerManager.GetPlayers(Players);
            Slopes = new ObservableCollection <Slope>();
            SlopeManager.GetSlopes(Slopes);
            Scores = new ObservableRangeCollection <Score>();
            ScoreManager.GetScores(Scores, 1);

            BindigContext = this;
            //            BindigContext = new ScoreViewModel();


            InitPlayerData();
        }
Exemplo n.º 17
0
        public NetworkingItemBarViewModel(CloudFile.Networker _networker)
        {
            networker = _networker;
            LBname    = networker.ToString();
            RegisterNetworker();
            BTNcontrolClicked = new Xamarin.Forms.Command(async() =>
            {
                BTNcontrolEnabled = false;
                switch (networker.Status)
                {
                case CloudFile.Networker.NetworkStatus.Networking:
                    {
                        await networker.PauseAsync();
                    }
                    break;

                case CloudFile.Networker.NetworkStatus.ErrorNeedRestart:
                    {
                        await networker.ResetAsync();
                        await networker.StartAsync();
                    }
                    break;

                case CloudFile.Networker.NetworkStatus.NotStarted:
                    {
                        await networker.StartAsync();
                    }
                    break;

                case CloudFile.Networker.NetworkStatus.Paused:
                    {
                        await networker.StartAsync();
                    }
                    break;

                case CloudFile.Networker.NetworkStatus.Completed:
                    {
                        await MyLogger.Alert("The task is already completed, no action to take");
                    } break;

                default: throw new Exception($"networker.Status: {networker.Status}");
                }
            });
        }
Exemplo n.º 18
0
        public SignInViewModel()
        {
            IsBusy  = false;
            _signIn = new Xamarin.Forms.Command(async() =>
            {
                string body;

                ShowLoadingScreen(true);

                // Detect if the login is a username or an email
                if (Util.DetectEmail(Login))
                {
                    // Define the body in Json
                    body = " { \"email\": \"" + Login + "\", \"password\": \"" + Password + "\" } ";
                }
                else
                {
                    // Define the body in Json
                    body = " { \"username\": \"" + Login + "\", \"password\": \"" + Password + "\" } ";
                }

                // Execute the request
                App.UserSession = await App.WsHost.ExecutePost <User>("users", "authenticate", null, body);


                if (App.UserSession != null)
                {
                    // Go to main page
                    App.Current.MainPage = new AppShell();

                    // Store the token
                    await SecureStorage.SetAsync("oauth_token", App.UserSession.Token);
                }
                else
                {
                    LoadingState = "Wrong password or username";
                    ShowLoadingScreen(false);
                }
            });

            Login    = "******";
            Password = "******";
        }
Exemplo n.º 19
0
        public MainViewModel()
        {
            try
            {
                memberDatabase = new MemberDatabase();
                var members = memberDatabase.GetUserDetail();

                UserDetail userin = (from blog in members
                                     select blog).FirstOrDefault();

                imageurl1 = "http://elixirct.in/ShopRConservicePublish/Uploads/" + userin.StoreImage1;
                imageurl2 = "http://elixirct.in/ShopRConservicePublish/Uploads/" + userin.StoreImage2;
                imageurl3 = "http://elixirct.in/ShopRConservicePublish/Uploads/" + userin.StoreImage3;

                MyItemsSource = new ObservableCollection <Xamarin.Forms.View>()
                {
                    new CachedImage()
                    {
                        Source = imageurl1, DownsampleToViewSize = true, Aspect = Xamarin.Forms.Aspect.AspectFill
                    },
                    new CachedImage()
                    {
                        Source = imageurl2, DownsampleToViewSize = true, Aspect = Xamarin.Forms.Aspect.AspectFill
                    },
                    new CachedImage()
                    {
                        Source = imageurl3, DownsampleToViewSize = true, Aspect = Xamarin.Forms.Aspect.AspectFill
                    }
                };

                MyCommand = new Xamarin.Forms.Command(() =>
                {
                    Debug.WriteLine("Position selected.");
                });

                //   Bindofr();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
Exemplo n.º 20
0
        public ImageCacheViewModel()
        {
            RefreshCommand = new Command(() =>
            {
                Image = new UriImageSource
                {
                    Uri            = new Uri("https://images.wsdot.wa.gov/sw/005vc00032.jpg"),
                    CachingEnabled = true,
                    CacheValidity  = TimeSpan.FromMinutes(1)
                };
                OnPropertyChanged(nameof(Image));
            });

            RefreshLongCommand = new AsyncCommand(async() =>
            {
                IsBusy = true;
                await Task.Delay(5000);
                IsBusy = false;
            });
        }
Exemplo n.º 21
0
 public RentalOwnerProfileViewModel()
 {
     _rentalService        = DependencyService.Get <IRentalService>();
     ToggleFavoriteCommand = new Xamarin.Forms.Command <Rental>(rental => rental.IsFavorite = !rental.IsFavorite);
     SendEmailCommand      = new AsyncCommand(() => Launcher.TryOpenAsync($"mailto:{Owner.Email}"));
     CallCommand           = new Xamarin.Forms.Command(() =>
     {
         try
         {
             PhoneDialer.Open(Owner.PhoneNumber);
         }
         catch { }
     });
     OpenRentalDetailsCommand = new AsyncCommand <Rental>(async(rental) =>
     {
         await _navigationService.GoToPageAsync <RentalDetailsPage>(new RentalDetailsPage.Args
         {
             Rental = rental
         });
     });
 }
        public UsuarioViewModel()
        {
            Usuarios = new ObservableCollection <Models.UsuarioModel>();

            // Obtem os usuario cadastrados no SQLite
            var listaUsuarios = new UsuarioDao().FindAllUsuario();

            foreach (UsuarioModel user in listaUsuarios)
            {
                Usuarios.Add(user);
            }

            SalvarUsuario = new Xamarin.Forms.Command(() =>
            {
                App app = Application.Current as App;

                UsuarioModel usuarioModel = new UsuarioModel();
                usuarioModel.Id           = 0; // Autoincrement na tabela
                usuarioModel.Nome         = app.NovoUsuario;

                new UsuarioDao().InsertUsuario(usuarioModel);
                Usuarios.Add(usuarioModel);
            });
        }
Exemplo n.º 23
0
 private void OnCommandCanExecuteChanged(object sender, EventArgs eventArgs)
 {
     IsEnabledCore = Command.CanExecute(CommandParameter);
 }
Exemplo n.º 24
0
 public void SendClicked()
 {
     Command?.Execute(CommandParameter);
     Clicked?.Invoke(this, EventArgs.Empty);
 }
Exemplo n.º 25
0
 public TableSelection(TablesPageModel referenceToParentClass)
 {
     parentTablesPageModel = referenceToParentClass;
     InsideTableCommand    = new Xamarin.Forms.Command(OnInsideButtonClicked);
     OutsideTableCommand   = new Xamarin.Forms.Command(OnOutsideButtonClicked);
 }
Exemplo n.º 26
0
        public JobRequestViewModel(object owner)
        {
            var guid = Guid.NewGuid().ToString().Replace("-", "");

            mediaFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), guid + ".3gpp");
            var parentViewModel = (HomeUserControlViewModel)owner;

            this.parentViewModel = parentViewModel;
            if (parentViewModel != null)
            {
                ContractorIcon = Helper.Utilities.GetIconByCategory(parentViewModel.CurrentSelectedCategory);
                JobRequestType = parentViewModel.CurrentSelectedCategory;
                UserProfile    = parentViewModel.UserProfile;
                this.SubscribeMeToThis(parentViewModel);
            }
            jobService            = new JobService();
            locationService       = new LocationService();
            userProfileRepository = new UserProfileRepository();
            PopulateLocations();
            SetInitialTimes();
            ContractorsAvailable  = 0;  //TODO: call api
            SearchLocationCmd     = new SearchLocationCommand(this);
            SubmitJobRequestCmd   = new SubmitJobCommand(this);
            ChangeProfileImageCmd = new Xamarin.Forms.Command(e =>
            {
                ChangeProfileImageAsync();
            }, (param) =>
            {
                return(true);
            });
            RecordVoiceCmd = new Xamarin.Forms.Command(e =>
            {
                Navigator.Instance.OkAlert("Alert", "Begin recording your voice once you tapped OK, and tap on the solid rectangular icon on your right to stop", "OK", () =>
                {
                    //for android
                    BeginRecording();
                },
                                           () =>
                {
                    //for ios
                    BeginRecording();
                });
            }, param =>
            {
                return(true);
            });
            PlayRecordedCmd = new Xamarin.Forms.Command(e =>
            {
                PlayRecordedVoice();
            }, param =>
            {
                return(true);
            });
            StopCmd = new Xamarin.Forms.Command(e =>
            {
                StopMedia();
            }, param =>
            {
                return(true);
            });
            DeleteCmd = new Xamarin.Forms.Command(e =>
            {
                Navigator.Instance.ConfirmationAlert("Alert", "Are you sure you want to delete your voice message?", "Yes", "No", () =>
                {
                    //for android
                    RemoveRecordedVoice();
                },
                                                     () =>
                {
                    //for ios
                    RemoveRecordedVoice();
                });
            }, param =>
            {
                return(true);
            });
            LoadImageUploaderOptions();
            InitializeVoiceButtons();
            SetupMediaPlayer();
            InitializeMinStartAndEndDates();
        }
Exemplo n.º 27
0
 public TodayViewModel()
 {
     FindLocationsCommand = new Command(FindLocations);
 }
Exemplo n.º 28
0
        public EditJobViewModel(object owner)
        {
            Job selectedJob = null;

            jobService = new JobService();

            if (owner is DashboardUserControlViewModel)
            {
                var dashboardUserControlViewModel = (DashboardUserControlViewModel)owner;
                parentViewModel = dashboardUserControlViewModel;
                selectedJob     = dashboardUserControlViewModel.GetSelectedJob();
                UserProfile     = dashboardUserControlViewModel.UserProfile;
                SubscribeMeToThis(dashboardUserControlViewModel);
            }
            else if (owner is JobViewViewModel)
            {
                var jobViewViewModel = (JobViewViewModel)owner;
                parentViewModel = jobViewViewModel;
                selectedJob     = jobViewViewModel.GetSelectedJob();
                UserProfile     = jobViewViewModel.UserProfile;
                SubscribeMeToThis(jobViewViewModel);
            }

            if (selectedJob != null)
            {
                ContractorIcon    = Helper.Utilities.GetIconByCategory(selectedJob.Category);
                JobRequestType    = selectedJob.Category;
                JobRequestImage   = selectedJob.ImagePath;
                Title             = selectedJob.Title;
                ScopeOfWork       = selectedJob.ScopeOfWork;
                SelectedStartDate = selectedJob.StartDateTime;
                SelectedEndDate   = selectedJob.EndDateTime;
                SelectedStartTime = new TimeSpan(selectedJob.StartDateTime.Hour, selectedJob.StartDateTime.Minute, 0);
                SelectedEndTime   = new TimeSpan(selectedJob.EndDateTime.Hour, selectedJob.EndDateTime.Minute, 0);
                Country           = selectedJob.Country;
                City          = selectedJob.City;
                Location      = selectedJob.Address;
                jobSystemUUID = selectedJob.SystemUUID;
            }

            ChangeProfileImageCmd = new Xamarin.Forms.Command(e =>
            {
                ChangeProfileImageAsync();
            }, (param) =>
            {
                return(true);
            });
            RecordVoiceCmd = new Xamarin.Forms.Command(e =>
            {
                Navigator.Instance.OkAlert("Alert", "Begin recording your voice once you tapped OK, and tap on the solid rectangular icon on your right to stop", "OK", () =>
                {
                    //for android
                    BeginRecording();
                },
                                           () =>
                {
                    //for ios
                    BeginRecording();
                });
            }, param =>
            {
                return(true);
            });
            PlayRecordedCmd = new Xamarin.Forms.Command(e =>
            {
                PlayRecordedVoice();
            }, param =>
            {
                return(true);
            });
            StopCmd = new Xamarin.Forms.Command(e =>
            {
                StopMedia();
            }, param =>
            {
                return(true);
            });
            DeleteCmd = new Xamarin.Forms.Command(e =>
            {
                Navigator.Instance.ConfirmationAlert("Alert", "Are you sure you want to delete your voice message?", "Yes", "No", () =>
                {
                    //for android
                    RemoveRecordedVoice();
                },
                                                     () =>
                {
                    //for ios
                    RemoveRecordedVoice();
                });
            }, param =>
            {
                return(true);
            });
            SubmitJobRequestCmd = new Xamarin.Forms.Command(async e =>
            {
                if (e == null)
                {
                    return;
                }

                var updatedJob = (Job)e;

                if (IsBusy)
                {
                    Navigator.Instance.OkAlert("Alert", "The app is currently busy. Please try again later.", "OK", null, null);
                    return;
                }

                Navigator.Instance.ConfirmationAlert("Confirmation", "Update the job now?", "Yes", "No", async() =>
                {
                    await DoUpdateJob(updatedJob);
                }, async() =>
                {
                    await DoUpdateJob(updatedJob);
                });
            },
                                                            parameter =>
            {
                if (parameter == null)
                {
                    return(false);
                }

                var jobRequest = (Job)parameter;

                if (jobRequest == null || jobRequest.StartDateTime == null || jobRequest.EndDateTime == null)
                {
                    return(false);
                }

                bool timeIsValid = jobRequest.EndDateTime > jobRequest.StartDateTime;

                if (!timeIsValid)
                {
                    return(false);
                }

                return(!string.IsNullOrEmpty(jobRequest.Title) &&
                       !string.IsNullOrEmpty(jobRequest.ScopeOfWork) &&
                       !string.IsNullOrEmpty(jobRequest.City) &&
                       !string.IsNullOrEmpty(jobRequest.Country) &&
                       !string.IsNullOrEmpty(jobRequest.Address));
            });

            LoadImageUploaderOptions();

            if (selectedJob != null && !string.IsNullOrEmpty(selectedJob.VoiceNotePath))
            {
                mediaFilePath = selectedJob.VoiceNotePath;
            }

            InitializeVoiceButtons();
            SetupMediaPlayer();
            InitializeMinStartAndEndDates();
        }