示例#1
0
        public override async Task InitializeAsync(object parameter = null)
        {
            await base.InitializeAsync(parameter);

            var query = new GetActiveNotesQuery();
            var notes = await DispatchQueryAsync <GetActiveNotesQuery, ICollection <Note> >(query);

            foreach (var note in notes)
            {
                Notes.Add(note);
            }
        }
示例#2
0
        public async Task <ICollection <Note> > HandleAsync(GetActiveNotesQuery query)
        {
            using (var context = _factory.CreateContext())
            {
                var list = await context.Notes
                           .Where(x => x.Status == StatusEnum.Normal)
                           .OrderByDescending(x => x.CreatedAt)
                           .Skip(query.Page * query.PageSize)
                           .Take(query.PageSize)
                           .ToListAsync();

                return(_mapper.MapTo <ICollection <Note> >(list));
            }
        }
示例#3
0
        protected NoteViewModel(IViewModelFacade viewModelFacade) : base(viewModelFacade)
        {
            SelectNoteCommand = new Command <Note>(async(x) => await GoToNoteAsync(x));

            _newNotesSubscription = NPublisher.SubscribeIt <NewNotesMessage>(async message =>
            {
                var query = new GetActiveNotesQuery();
                var notes = await DispatchQueryAsync <GetActiveNotesQuery, ICollection <Note> >(query);

                MainThread.BeginInvokeOnMainThread(() =>
                {
                    Notes.Clear();

                    foreach (var note in notes)
                    {
                        Notes.Add(note);
                    }

                    OnPropertyChanged(nameof(Notes));
                    OnPropertyChanged(nameof(Note.CreatedAt));
                    OnPropertyChanged(nameof(Note.Name));
                });
            });
        }