Exemple #1
0
    private static BookHistoryBook GetOrMakeBookRecord(Book book, SQLiteConnection db)
    {
        var bookRecord = GetBookRecord(book, db);

        if (bookRecord == null)
        {
            bookRecord = new BookHistoryBook
            {
                Id = book.ID,
                // TODO: update Name every time because it can change? Add an event if we notice that it changed?
                Name = book.NameBestForUserDisplay
            };
            db.Insert(bookRecord);
        }

        return(bookRecord);
    }
Exemple #2
0
    public static void AddEvent(Book book, BookHistoryEventType eventType, string message = "")
    {
        try
        {
            using (var db = GetConnection(book.FolderPath))
            {
                var bookRecord = db.Table <BookHistoryBook>().FirstOrDefault(b => b.Id == book.ID);
                if (bookRecord == null)
                {
                    bookRecord = new BookHistoryBook
                    {
                        Id = book.ID,
                        // TODO: update Name every time because it can change? Add an event if we notice that it changed?
                        Name = book.TitleBestForUserDisplay
                    };
                    db.Insert(bookRecord);
                }

                var evt = new BookHistoryEvent()
                {
                    BookId   = book.ID,
                    Message  = message,
                    UserId   = TeamCollectionManager.CurrentUser,
                    UserName = TeamCollectionManager.CurrentUserFirstName,
                    Type     = eventType,
                    When     = DateTime.Now
                };

                db.Insert(evt);
                db.Close();
            }
        }
        catch (Exception e)
        {
            NonFatalProblem.Report(ModalIf.None, PassiveIf.All, "Problem writing book history", $"folder={book.FolderPath}",
                                   e);
            // swallow... we don't want to prevent whatever was about to happen.
        }
    }