virtual public async Task AddBookReadingEntry(BookReading newBookReading) { var nextLastPriority = await LastPriority() + 1; newBookReading.priority = nextLastPriority; await Collection().InsertOneAsync(newBookReading); }
private async Task <int> LastPriority() { var options = new FindOptions <BookReading> { Limit = 1, Sort = Builders <BookReading> .Sort.Descending(bookReadingEntry => bookReadingEntry.priority) }; BookReading lastPriorityBookReading = (await Collection().FindAsync(FilterDefinition <BookReading> .Empty, options)).FirstOrDefault() ?? new BookReading(); return(lastPriorityBookReading.priority); }