public async Task PopAsync(bool animate)
 {
     if (PopupNavigation.Instance.PopupStack.Count > 0)
     {
         await PopupNavigation.Instance.PopAsync(animate);
     }
     else
     {
         await CurrentNavigation.PopModalAsync(animate);
     }
 }
        public async Task NavigateToPopupAsync <TViewModel>(object parameter, bool animate) where TViewModel : ViewModelBase
        {
            var page = CreateAndBindPage(typeof(TViewModel), parameter);

            await(page.BindingContext as ViewModelBase).InitializeAsync(parameter);

            if (page is PopupPage)
            {
                await PopupNavigation.Instance.PushAsync(page as PopupPage, animate);
            }
            else if (page is Page)
            {
                await CurrentNavigation.PushModalAsync(new NavigationPage(page));
            }
            else
            {
                throw new InvalidNavigationException($"The type ${typeof(TViewModel)} its not a Page/PopupPage type");
            }
        }
Beispiel #3
0
        public CreateAffairViewModel()
        {
            conn = DependencyService.Get <Isqlite>().GetConnection();

            SelectType = new Command(async(typeValue) => {
                AffairSubType = (string)typeValue;
                await CurrentNavigation.PopAsync();
            });

            LoadType = new Command(async() => {
                if (AffairType == "Event")
                {
                    await CurrentNavigation.PushAsync(new EventType(referenceEventViewModel));
                }
                else
                {
                    await CurrentNavigation.PushAsync(new ReminderType(referenceReminderViewModel));
                }
            });

            SelectRepeat = new Command(async(repeatValue) => {
                Repeat = (string)repeatValue;
                await CurrentNavigation.PopAsync();
            });

            LoadRepeat = new Command(async() => {
                if (AffairType == "Event")
                {
                    await CurrentNavigation.PushAsync(new Repeat(referenceEventViewModel));
                }
                else
                {
                    await CurrentNavigation.PushAsync(new Repeat(referenceReminderViewModel));
                }
            });

            SelectAlert = new Command(async(alertValue) => {
                Alert = (string)alertValue;
                await CurrentNavigation.PopAsync();
            });

            LoadAlert = new Command(async() => {
                if (AffairType == "Event")
                {
                    await CurrentNavigation.PushAsync(new Alert(referenceEventViewModel));
                }
                else
                {
                    await CurrentNavigation.PushAsync(new Alert(referenceReminderViewModel));
                }
            });

            SaveNote = new Command(async() => {
                List <Page> currentPages = (List <Page>)CurrentNavigation.NavigationStack;

                if (string.IsNullOrEmpty(NoteDescription) && string.IsNullOrEmpty(NoteURL))
                {
                    ErrorAlert("At least one field is required", currentPages[currentPages.Count - 1]);
                }
                else
                {
                    int isSuccess;
                    // Add Custom Note
                    Note newNote = new Note
                    {
                        Description = NoteDescription,
                        URL         = NoteURL
                    };
                    isSuccess = 0;
                    try
                    {
                        isSuccess = conn.Insert(newNote);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    CurrentNoteID = newNote.Id;
                    await CurrentNavigation.PopAsync();
                }
            });

            LoadNote = new Command(async() =>
            {
                if (AffairType == "Event")
                {
                    await CurrentNavigation.PushAsync(new Notes(referenceEventViewModel));
                }
                else
                {
                    await CurrentNavigation.PushAsync(new Notes(referenceReminderViewModel));
                }
            });

            LoadNewProgramme = new Command(() => {
                PopupProgrammeVisible = true;
            });

            SaveNewProgramme = new Command(() => {
                bool validProgramme = true;

                if (string.IsNullOrEmpty(NewProgrammeName))
                {
                    ErrorAlert("New Programme must have Name", CurrentPage);
                    validProgramme = false;
                }
                else if (string.IsNullOrEmpty(NewProgrammeColour))
                {
                    ErrorAlert("New Programme must have Colour", CurrentPage);
                    validProgramme = false;
                }

                if (validProgramme)
                {
                    int isSuccess;
                    // Add Programme
                    string hexCode;
                    switch (NewProgrammeColour)
                    {
                    case "Green":
                        hexCode = "#99ff33";
                        break;

                    case "Blue":
                        hexCode = "#0099ff";
                        break;

                    case "Red":
                        hexCode = "#ff5050";
                        break;

                    case "Orange":
                        hexCode = "#ff9966";
                        break;

                    case "Yellow":
                        hexCode = "#ffff99";
                        break;

                    case "Purple":
                        hexCode = "#993399";
                        break;

                    default:
                        hexCode = "#ffffff";
                        break;
                    }
                    if (AffairType == "Event")
                    {
                        Models.Calendar newCalendar = new Models.Calendar
                        {
                            Name      = NewProgrammeName,
                            HexColour = hexCode
                        };
                        isSuccess = 0;
                        try
                        {
                            isSuccess = conn.Insert(newCalendar);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    else
                    {
                        Models.Subject newSubject = new Models.Subject
                        {
                            Name      = NewProgrammeName,
                            HexColour = hexCode
                        };
                        isSuccess = 0;
                        try
                        {
                            isSuccess = conn.Insert(newSubject);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }

                    NewProgrammeName   = "";
                    NewProgrammeColour = "";
                    CurrentProgrammeID = 0;

                    // Save results to query
                    ProgrammeListView     = new List <ProgrammeViewModel>();
                    PopupProgrammeVisible = false;
                }
            });

            SelectProgramme = new Command((programmeValue) => {
                CurrentProgrammeID = 0;
                CurrentProgrammeID = (int)programmeValue;
                ProgrammeListView  = new List <ProgrammeViewModel>();
            });
        }