public AssignmentViewModel ()
        {
            recordCommand = new DelegateCommand (async _ => {
                if (Recording)
                    await PauseAsync ();
                else
                    await RecordAsync ();
            }, _ => !IsBusy);

            mapsCommand = new DelegateCommand (_ => Helpers.NavigateTo<MapPage> ());

            assignmentMapsCommand = new DelegateCommand (_ => Helpers.NavigateTo<AssignmentMapPage> ());

            goBackCommand = new DelegateCommand (_ => {
                if (addSignaturePopup != null && addSignaturePopup.IsOpen) {
                    addSignaturePopup.IsOpen = false;
                }
                Helpers.GoBack ();

            }, _ => Helpers.CanGoBack);

            itemsCommand = new DelegateCommand (_ => Helpers.NavigateTo<ItemsPage> ());

            laborCommand = new DelegateCommand (_ => Helpers.NavigateTo<LaborPage> ());

            expensesCommand = new DelegateCommand (_ => Helpers.NavigateTo<ExpensesPage> ());

            confirmationsCommand = new DelegateCommand (_ => Helpers.NavigateTo<ConfirmationsPage> ());

            documentsCommand = new DelegateCommand (_ => Helpers.NavigateTo<DocumentsPage> ());

            historyCommand = new DelegateCommand (_ => Helpers.NavigateTo<AssignmentHistoryPage> ());

            goBackHistoryCommand = new DelegateCommand (_ => {
                Helpers.GoBack ();
                if (SelectedAssignment.IsHistory) {
                    SelectedAssignment = PreviousSelected;
                    PreviousSelected = null;
                }
            });

            cancelAddSignatureCommand = new DelegateCommand (_ => { addSignaturePopup.IsOpen = false; });

            declineCommand = new DelegateCommand (async _ => {
                SelectedAssignment.Status = AssignmentStatus.Declined;
                await SaveAssignmentAsync (SelectedAssignment);
                Helpers.GoBack ();
            });

            acceptCommand = new DelegateCommand (async _ => {
                if (ActiveAssignment == null) {
                    SelectedAssignment.Status = AssignmentStatus.Active;
                } else {
                    SelectedAssignment.Status = AssignmentStatus.Hold;
                }
                await SaveAssignmentAsync (SelectedAssignment);

                //Reload the entire page
                Helpers.GoBack();
                Helpers.NavigateTo<AssignmentPage>();
            });

            addSignatureCommand = new DelegateCommand (_ => {
                if (addSignaturePopup != null && addSignaturePopup.IsOpen) {
                    addSignaturePopup.IsOpen = false;
                }
                addSignaturePopup = new Popup ();
                addSignaturePopup.Height = Window.Current.Bounds.Height;
                addSignaturePopup.Width = Constants.SignaturePopUpWidth;
                AddSignatureFlyoutPanel flyoutpanel = new AddSignatureFlyoutPanel ();
                flyoutpanel.Width = addSignaturePopup.Width;
                flyoutpanel.Height = addSignaturePopup.Height;
                addSignaturePopup.Child = flyoutpanel;
                addSignaturePopup.SetValue (Canvas.LeftProperty, Window.Current.Bounds.Width - Constants.SignaturePopUpWidth);
                addSignaturePopup.SetValue (Canvas.TopProperty, 0);
                addSignaturePopup.IsOpen = true;
            });

            completeCommand = new DelegateCommand (async _ => {
                SelectedAssignment.Status = AssignmentStatus.Complete;
                await SaveAssignmentAsync (SelectedAssignment);

                //Reload the entire page
                Helpers.GoBack ();
                Helpers.NavigateTo<ConfirmationsPage> ();
            });
        }
Ejemplo n.º 2
0
        public AssignmentViewModel()
        {
            recordCommand = new DelegateCommand (async _ => {
                if (Recording)
                    await PauseAsync ();
                else
                    await RecordAsync ();
            }, _ => !IsBusy);

            mapsCommand = new DelegateCommand (_ => Helpers.NavigateTo<MapPage> ());

            assignmentMapsCommand = new DelegateCommand (_ => Helpers.NavigateTo<AssignmentMapPage> ());

            goBackCommand = new DelegateCommand (_ => {
                if (addSignaturePopup != null && addSignaturePopup.IsOpen) {
                    addSignaturePopup.IsOpen = false;
                }
                Helpers.GoBack ();

            }, _ => Helpers.CanGoBack);

            itemsCommand = new DelegateCommand (_ => Helpers.NavigateTo<ItemsPage> ());

            laborCommand = new DelegateCommand (_ => Helpers.NavigateTo<LaborPage> ());

            expensesCommand = new DelegateCommand (_ => Helpers.NavigateTo<ExpensesPage> ());

            confirmationsCommand = new DelegateCommand (_ => Helpers.NavigateTo<ConfirmationsPage> ());

            documentsCommand = new DelegateCommand (_ => Helpers.NavigateTo<DocumentsPage> ());

            historyCommand = new DelegateCommand (_ => Helpers.NavigateTo<AssignmentHistoryPage> ());

            goBackHistoryCommand = new DelegateCommand (_ => {
                Helpers.GoBack ();
                if (SelectedAssignment.IsHistory) {
                    SelectedAssignment = PreviousSelected;
                    PreviousSelected = null;
                }
            });

            cancelAddSignatureCommand = new DelegateCommand (_ => {
                if (flyoutpanel != null)
                    flyoutpanel.SignaturePad.Clear ();

                addSignaturePopup.IsOpen = false;
            });

            saveAddSignatureCommand = new DelegateCommand(async _ => {
                if (flyoutpanel == null)
                    return;

                using (var signatureStream = await flyoutpanel.SignaturePad.GetSignaturePngStreamAsync ()) {
                    using (var binaryReader = new BinaryReader (signatureStream)) {
                      var signatureBytes = binaryReader.ReadBytes ((int)signatureStream.Length);
                      Signature = new Signature { Image = signatureBytes };
                      await SaveSignatureAsync ();
                      addSignaturePopup.IsOpen = false;
                    }
                }

            });

            clearAddSignatureCommand = new DelegateCommand(_ =>
            {
                if (flyoutpanel != null)
                    flyoutpanel.SignaturePad.Clear();
            });

            declineCommand = new DelegateCommand (async _ => {
                SelectedAssignment.Status = AssignmentStatus.Declined;
                await SaveAssignmentAsync (SelectedAssignment);
                Helpers.GoBack ();
            });

            acceptCommand = new DelegateCommand (async _ => {
                if (ActiveAssignment == null) {
                    SelectedAssignment.Status = AssignmentStatus.Active;
                } else {
                    SelectedAssignment.Status = AssignmentStatus.Hold;
                }
                await SaveAssignmentAsync (SelectedAssignment);

                //Reload the entire page
                Helpers.GoBack();
                Helpers.NavigateTo<AssignmentPage>();
            });

            addSignatureCommand = new DelegateCommand (async _ => {
                if (Signature != null) {
                    await new MessageDialog ("Signature already added").ShowAsync ();
                    return;
                }

                if (addSignaturePopup != null && addSignaturePopup.IsOpen)
                    addSignaturePopup.IsOpen = false;

                addSignaturePopup = new Popup ();
                addSignaturePopup.Height = Window.Current.Bounds.Height;
                addSignaturePopup.Width = Constants.SignaturePopUpWidth;
                flyoutpanel = new AddSignatureFlyoutPanel ();
                flyoutpanel.Width = addSignaturePopup.Width;
                flyoutpanel.Height = addSignaturePopup.Height;
                addSignaturePopup.Child = flyoutpanel;
                addSignaturePopup.SetValue (Canvas.LeftProperty, Window.Current.Bounds.Width - Constants.SignaturePopUpWidth);
                addSignaturePopup.SetValue (Canvas.TopProperty, 0);
                addSignaturePopup.IsOpen = true;
            });

            completeCommand = new DelegateCommand (async _ => {
                SelectedAssignment.Status = AssignmentStatus.Complete;
                await SaveAssignmentAsync (SelectedAssignment);

                //Reload the entire page
                Helpers.GoBack ();
                Helpers.NavigateTo<ConfirmationsPage> ();
            });
        }