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); } }
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)); } }
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)); }); }); }