Ejemplo n.º 1
0
        public AppointmentDetailViewModel(Cache cache, CalendarProxy proxy, IMapper mapper)
        {
            this.cache  = cache;
            this.proxy  = proxy;
            this.mapper = mapper;

            var titleObs = this.WhenAnyValue(x => x.Dvo.Name)
                           .Select(x => $"Appointment '{x}'")
                           .ObserveOn(RxApp.MainThreadScheduler);

            _Title  = titleObs.ToProperty(this, x => x.Title, "Loading ...");
            _Header = titleObs.ToProperty(this, x => x.Header, "Loading ...");

            RenameCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                var newName = await RenameInteraction.Handle(Dvo.Name);
                if (!string.IsNullOrWhiteSpace(newName))
                {
                    await proxy.RenameToDoTask(Dvo.Id, newName);
                    Dvo.Name = newName;
                }
            });
        }
Ejemplo n.º 2
0
        public AppointmentListViewModel(Cache cache, CalendarProxy proxy, IMapper mapper)
        {
            CreateCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                var id   = Guid.NewGuid();
                var name = await CreateInteraction.Handle(Unit.Default);
                if (name != null)
                {
                    await proxy.AddToDoTask(id, name);
                    var dto = await proxy.GetAppointment(id);
                    var dvo = mapper.Map <AppointmentDvo>(dto);
                    cache.Get <AppointmentDvo>().AddOrUpdate(dvo);
                    MessageBus.Current.OpenAppointment(dvo.Id);
                }
            });
            EditCommand = ReactiveCommand.Create <AppointmentDvo>(
                toDoTask => MessageBus.Current.OpenAppointment(toDoTask.Id),
                this.WhenAnyValue(x => x.SelectedToDoTask).Select(d => d != null));
            DeleteCommand = ReactiveCommand.Create <AppointmentDvo>(async toDoTask =>
            {
                await proxy.DeleteToDoTask(toDoTask.Id);
                cache.Get <AppointmentDvo>().Remove(toDoTask);
                MessageBus.Current.CloseAllPanelsWithKey(toDoTask.Id.ToString());
            }, this.WhenAnyValue(x => x.SelectedToDoTask).Select(d => d != null));
            RefreshCommand = ReactiveCommand.CreateFromTask(async cancellationToken =>
            {
                cache.Get <AppointmentDvo>().EditDiff(
                    mapper.Map <IEnumerable <AppointmentDto>, IList <AppointmentDvo> >(await proxy.GetAppointments()),
                    // TODO - Implementar un mecanismo para detectar los cambios basado en un timestamp o similar
                    (t1, t2) => t1.Name == t2.Name);
            });
            cache.Get <AppointmentDvo>()
            .Connect()
            .OnItemRemoved(toDoTask => MessageBus.Current.CloseAllPanelsWithKey(toDoTask.Id.ToString()))
            .OnItemUpdated((updatedToDoTask, _) => MessageBus.Current.SendMessage(new UpdatePanelMessage(updatedToDoTask)))

            //.AutoRefresh(_ => _.Name)
            .AutoRefresh()

            //.Filter(_ => _.Name != null)

            .Sort(new GenericComparer <AppointmentDvo>((t1, t2) => StringComparer.CurrentCulture.Compare(t1.Name, t2.Name)))
            .Page(this.WhenAnyValue(_ => _.PageRequest))

            .ObserveOnDispatcher()
            .Bind(out var list)
            .DisposeMany()
            .Subscribe();
            ToDoTasks = list;

            cache.Get <AppointmentDvo>()
            .Connect()
            .ObserveOnDispatcher()
            .Bind(out var allList)
            .DisposeMany()
            .Subscribe();
            AllToDoTasks = allList;

            // TODO - Cancel in progress command https://github.com/reactiveui/ReactiveUI/issues/1536
            RefreshCommand.Execute().Subscribe();
            //RefreshCommand.Execute().Subscribe();
        }