public NewTodoItemPageViewModel(INavigationService navigationService, IPageDialogService pageDialogService) : base(navigationService)
        {
            _pageDialogService = pageDialogService;

            Title = "New Todo Item";

            CreateCommand = new[] {
                Name.Select(x => string.IsNullOrEmpty(x))
            }.CombineLatestValuesAreAllFalse()
            .ObserveOn(SynchronizationContext.Current)
            .ToAsyncReactiveCommand();

            _ = CreateCommand.Subscribe(async() =>
            {
                var item = new TodoItem
                {
                    Name  = Name.Value,
                    Notes = Notes.Value,
                };

                _ = CrossCloudFirestore.Current
                    .Instance
                    .Collection(TodoItem.CollectionPath)
                    .AddAsync(item)
                    .ContinueWith(t =>
                {
                    System.Diagnostics.Debug.WriteLine(t.Exception);
                }, TaskContinuationOptions.OnlyOnFaulted);

                await navigationService.GoBackAsync(useModalNavigation: true);
            });

            CancelCommand = new ReactiveCommand();
            CancelCommand.Subscribe(() => NavigationService.GoBackAsync(useModalNavigation: true));
        }
예제 #2
0
        public CreateTodoItemVm(ITodoItemsService todoItemsService)
        {
            this.todoItemsService = todoItemsService;

            CreateCommand = ReactiveCommand.CreateAsyncObservable(item =>
            {
                var todoItem         = new TodoItem();
                todoItem.Name        = Name;
                todoItem.Description = Description;
                todoItem.Duration    = Duration;

                return(todoItemsService.Add(todoItem));
            });

            CreateCommand.Subscribe(_ =>
            {
                Name     = Description = null;
                Duration = 1;
            });
        }
예제 #3
0
        public NewTodoItemPageViewModel(INavigationService navigationService, IPageDialogService pageDialogService) : base(navigationService)
        {
            _pageDialogService = pageDialogService;

            Title = "New Todo Item";

            CreateCommand = new[] {
                Name.Select(x => string.IsNullOrEmpty(x))
            }.CombineLatestValuesAreAllFalse()
            .ObserveOn(SynchronizationContext.Current)
            .ToAsyncReactiveCommand();

            CreateCommand.Subscribe(async() =>
            {
                var item = new TodoItem
                {
                    Name      = Name.Value,
                    Notes     = Notes.Value,
                    CreatedAt = DateTime.Now
                };

                CrossCloudFirestore.Current
                .GetCollection(TodoItem.CollectionPath)
                .AddDocument(item, (error) =>
                {
                    if (error != null)
                    {
                        System.Diagnostics.Debug.WriteLine(error);
                    }
                });

                await navigationService.GoBackAsync(useModalNavigation: true);
            });

            CancelCommand = new ReactiveCommand();
            CancelCommand.Subscribe(() => NavigationService.GoBackAsync(useModalNavigation: true));
        }