Esempio n. 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);
        }
Esempio n. 2
0
        /// <summary>
        ///   Removes from database.
        /// </summary>
        /// <param name="items">The items.</param>
        /// <returns></returns>
        protected async Task <bool> RemoveFromDbAsync(IEnumerable <T> items)
        {
            try
            {
                await _db.RunInTransactionAsync(
                    dbSync =>
                {
                    foreach (T item in items)
                    {
                        dbSync.Delete(item);
                    }
                }).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                LogTo.Error(ex, "RemoveFromDb");

                return(false);
            }

            return(true);
        }