コード例 #1
0
        /// <summary>
        ///   Generate a new collection based on specified parameters.
        ///   If a <see cref="AgnosticDatabase.Interfaces.IDatabaseAsync" /> instance is specified, collection will also be saved
        ///   to Database.
        /// </summary>
        /// <param name="db">Database instance.</param>
        /// <returns>
        ///   Generated collection
        /// </returns>
        public async Task <IEnumerable <Note> > GenerateAsync(IDatabaseAsync db)
        {
            if (db == null)
            {
                return(Generate());
            }

            IEnumerable <Note> notes = MakeNotes();

            // Generate notes
            await db.InsertAllAsync(notes).ConfigureAwait(false);

            // Generate cards
            await db.RunInTransactionAsync(dbSync => CreateCards(notes, dbSync));

            return(notes);
        }
コード例 #2
0
 /// <summary>
 ///   Adds to database.
 /// </summary>
 /// <param name="items">The items.</param>
 /// <returns></returns>
 protected async Task <bool> AddToDbAsync(IEnumerable <T> items)
 {
     return(await _db.InsertAllAsync(items).ConfigureAwait(false) > 0);
 }