Exemplo n.º 1
0
        private void InitializePage(WorkDay workDay, bool isUpdate)
        {
            var localViewModel = new InsertViewViewModel(workDay, isUpdate);

            localViewModel.DeleteWorkItem = new Command(async () =>
            {
                if (!CrossConnectivity.Current.IsConnected)
                {
                    await DisplayAlert("Offline", "Je hebt geen verbinding met het internet!", "Ah, Jammer");
                    return;
                }

                if (await DisplayAlert("Let op!", "Weet je zeker dat je deze datum wilt verwijderen?", "Ja", "Nee"))
                {
                    await App.AppManager.DeleteWorkDay(viewModel.WorkDay);

                    await Navigation.PopAsync();
                }
            });

            localViewModel.SaveWorkItem = new Command(async () =>
            {
                if (!viewModel.IsValid)
                    return;

                if (!CrossConnectivity.Current.IsConnected)
                {
                    await DisplayAlert("Offline", "Je hebt geen verbinding met het internet!", "Ah, Jammer");
                    return;
                }

                bool canUpdate = false;

                if (!viewModel.IsUpdate)
                {
                    var item = await App.AppManager.GetWorkDay(viewModel.WorkDay.StartDateTime.Date);
                    if (item != null)
                    {
                        if(await DisplayAlert ("Let op!", "Deze datum bestaat al. Overschrijven?", "Ja", "Nee"))
                        {
                            canUpdate = true;
                        }
                    }
                }

                if (viewModel.IsUpdate || (!viewModel.IsUpdate && canUpdate))
                {
                    await App.AppManager.UpdateWorkDay(viewModel.WorkDay);
                    await Navigation.PopAsync();

                }
                else
                {
                    await App.AppManager.AddWorkDay(viewModel.WorkDay);
                    await Navigation.PopAsync();
                }
            });

            BindingContext = localViewModel;
        }
Exemplo n.º 2
0
        public InsertView(WorkDay workDay, bool isUpdate)
        {
            InitializeComponent();

            InitializePage(workDay, isUpdate);
        }