Ejemplo n.º 1
0
        private async void OpenDeleteDialog()
        {
            Func <Task <bool> > f = () => Task.FromResult(false);

            switch (TaskData.Type)
            {
            case TaskType.Global:
                f = async() => await GlobalTaskService.Remove(TaskData.Id);

                break;

            case TaskType.Period:
                f = async() => await PeriodTaskService.Remove(TaskData.Id);

                break;

            case TaskType.Subject:
                f = async() => await SubjectTaskService.Remove(TaskData.Id);

                break;
            }

            var parameters = new DialogParameters
            {
                {
                    "Input",
                    new ConfirmDialogInput
                    {
                        Name           = TaskData.Text,
                        DeleteFunction = f
                    }
                }
            };
            var dialog = DialogService.Show <ConfirmDialog>("Confirm Delete", parameters);
            var result = await dialog.Result;

            if (!result.Cancelled)
            {
                await OnRemove.InvokeAsync();
            }
        }
Ejemplo n.º 2
0
        private async void Save()
        {
            if ((AddType == TaskType.Period || AddType == TaskType.Subject) && SelectedId == 0)
            {
                return;
            }

            if (!TaskContext.Validate())
            {
                return;
            }

            switch (AddType)
            {
            case TaskType.Global when IsEdit:
            {
                var userId = StoreService.Get <StorageUser>("user")?.Id ?? -1;
                if (await GlobalTaskService.Update(TaskData.Id, new GlobalTaskModel(Model, userId)))
                {
                    Dialog.Close(DialogResult.Ok(true));
                }

                break;
            }

            case TaskType.Global:
            {
                var userId = StoreService.Get <StorageUser>("user")?.Id ?? -1;
                if (await GlobalTaskService.Create(new GlobalTaskModel(Model, userId)))
                {
                    Dialog.Close(DialogResult.Ok(true));
                }

                break;
            }

            case TaskType.Period when IsEdit:
            {
                if (await PeriodTaskService.Update(TaskData.Id, new PeriodTaskModel(SelectedId, Model)))
                {
                    Dialog.Close(DialogResult.Ok(true));
                }

                break;
            }

            case TaskType.Period:
            {
                if (await PeriodTaskService.Create(new PeriodTaskModel(SelectedId, Model)))
                {
                    Dialog.Close(DialogResult.Ok(true));
                }

                break;
            }

            case TaskType.Subject when IsEdit:
            {
                if (await SubjectTaskService.Update(TaskData.Id, new SubjectTaskModel(SelectedId, Model)))
                {
                    Dialog.Close(DialogResult.Ok(true));
                }

                break;
            }

            case TaskType.Subject:
            {
                if (await SubjectTaskService.Create(new SubjectTaskModel(SelectedId, Model)))
                {
                    Dialog.Close(DialogResult.Ok(true));
                }

                break;
            }
            }
        }