//Method that returns a count of the number of books in the library.
 public int GetCount()
 {
     using (var db = new BiblioContext())
     {
         return(db.Books.ToList().Count());
     }
 }
        public void AddBookTestNewBook()
        {
            int preAddTestBooks   = 0;
            int preAddTestAuthor  = 0;
            int postAddTestBooks  = 0;
            int postAddTestAuthor = 0;

            using (var db = new BiblioContext())
            {
                preAddTestBooks  = db.Books.Count();
                preAddTestAuthor = db.Authors.Count();
            }

            _testBiblio.AddBook(AuthorFirst, AuthorLast, Title, Isbn10, Isbn13, Publisher, PublishedDate, NumOfPages, Description, Review, Read);

            using (var db = new BiblioContext())
            {
                postAddTestBooks  = db.Books.Count();
                postAddTestAuthor = db.Authors.Count();
            }
            Assert.AreEqual(preAddTestBooks, postAddTestBooks - 1);
            Assert.AreEqual(preAddTestAuthor, postAddTestAuthor - 1);
            using (var db = new BiblioContext())
            {
                var removeBook   = db.Books.OrderByDescending(b => b.BookId).First();
                var removeAuthor = db.Authors.OrderByDescending(a => a.AuthorId).First();
                db.Remove(removeBook);
                db.SaveChanges();
                db.Remove(removeAuthor);
                db.SaveChanges();
            }
        }
 //Method that lists all the books ordered by when they were added to the database.
 public List <Books> GetAllBooksByAdded()
 {
     using (var db = new BiblioContext())
     {
         return(db.Books.Include(a => a.Author).OrderBy(b => b.BookId).ToList());
     }
 }
 //Method that lists all the books ordered alphabetically by the surname of the author and then by the title.
 public List <Books> GetAllBooksByAuthor()
 {
     using (var db = new BiblioContext())
     {
         return(db.Books.Include(a => a.Author).OrderBy(a => a.Author.LastName).ThenBy(b => b.Title).ToList());
     }
 }
 //Method that edits books in the database
 //1) Finds the book and author entries in the database
 //2) Updates the data with the inputs on the selected author and book
 public void EditBook(string authorFirst, string authorLast, string bookTitle, string isbn10 = null, string isbn13 = null, string publisher = null, string publishDate = null, int numOfPages = 0, string description = null, int review = 0, bool read = false)
 {
     using (var db = new BiblioContext())
     {
         var authorQuery = db.Authors.Where(a => a.AuthorId == SelectedBook.AuthorId);
         if (authorQuery.Count() != 0)
         {
             var author = authorQuery.First();
             author.FirstName = authorFirst;
             author.LastName  = authorLast;
         }
         db.SaveChanges();
         var bookQuery = db.Books.Where(b => b.BookId == SelectedBook.BookId);
         if (bookQuery.Count() != 0)
         {
             var book = bookQuery.First();
             book.Title         = bookTitle;
             book.Isbn10        = isbn10;
             book.Isbn13        = isbn13;
             book.Publisher     = publisher;
             book.PublishedDate = publishDate;
             book.NumOfPages    = numOfPages;
             book.Description   = description;
             book.Read          = read;
             book.Review        = review;
         }
         db.SaveChanges();
     }
 }
 //Method that uses string.Contains() to search the book titles, author's name (and title) for the input of the search bar and returns the books.
 public List <Books> SearchBooks(string input)
 {
     using (var db = new BiblioContext())
     {
         string       correctInput = input.ToUpper().Trim();
         List <Books> searchResult = db.Books.Include(a => a.Author).Where(b => b.Title.ToUpper().Contains(correctInput) || b.Author.LastName.Contains(correctInput) || b.Author.FirstName.Contains(correctInput) || b.Author.Title.Contains(correctInput)).OrderBy(b => b.Title).ToList();
         return((searchResult.Count() == 0)? null : searchResult);
     }
 }
 //Method that deletes the selected book
 public void DeleteBook(Books selectedBook)
 {
     using (var db = new BiblioContext())
     {
         var bookQuery = db.Books.Where(b => b.BookId == selectedBook.BookId).ToList().First();
         db.Remove(bookQuery);
         db.SaveChanges();
     }
 }
        public void EditBookTest()
        {
            using (var db = new BiblioContext())
            {
                Authors testAuthor = new Authors
                {
                    FirstName = "Aaron A.",
                    LastName  = "Aardvark"
                };
                db.Add(testAuthor);
                db.SaveChanges();
                int   authorId = db.Authors.OrderByDescending(a => a.AuthorId).First().AuthorId;
                Books testBook = new Books
                {
                    Title         = "A Aardvark Attractiveness Album",
                    AuthorId      = authorId,
                    Isbn10        = "0000000000",
                    Isbn13        = "0000000000000",
                    NumOfCopies   = 1,
                    NumOfPages    = 200,
                    Read          = true,
                    Review        = 5,
                    PublishedDate = "2020",
                    Publisher     = "Aardvark 'ardbacks",
                    Description   = "Aardvark attractiveness alternates accorinding to austerity apparentley, as acknowledged by Aardvark 'ardbacks anyway."
                };
                db.Add(testBook);
                db.SaveChanges();
                _testBiblio.SetSelectedBook(testBook);
            }
            string editDescription = "new description";
            int    editReview      = 4;
            bool   editRead        = false;

            _testBiblio.EditBook("Aaron a.", "Aardvark", "An Aardvark Attractiveness Album", "0000000000", "0000000000000", "Aardvark 'ardbacks", "2020", 200, editDescription, editReview, editRead);

            using (var db = new BiblioContext())
            {
                string newDescription = db.Books.OrderByDescending(b => b.BookId).First().Description;
                int    newReview      = db.Books.OrderByDescending(b => b.BookId).First().Review;
                bool   newRead        = db.Books.OrderByDescending(b => b.BookId).First().Read;

                Assert.AreEqual(editDescription, newDescription);
                Assert.AreEqual(editReview, newReview);
                Assert.AreEqual(editRead, newRead);

                var removeBook   = db.Books.OrderByDescending(b => b.BookId).First();
                var removeAuthor = db.Authors.OrderByDescending(a => a.AuthorId).First();
                db.Remove(removeBook);
                db.SaveChanges();
                db.Remove(removeAuthor);
                db.SaveChanges();
            }
        }
示例#9
0
        public void FillOffer()
        {
            using (var context = new BiblioContext())
            {
                var list = new List <Offer>();
                while (_xmlReader.ReadToFollowing(Constant.KeyField))
                {
                    var id    = _xmlReader.GetAttribute("id");
                    var rTree = _xmlReader.ReadSubtree();
                    rTree.MoveToContent();
                    var xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(rTree.ReadOuterXml());
                    var nodes = xmlDoc.SelectNodes(Constant.KeyField);
                    foreach (XmlNode item in nodes)
                    {
                        var      categoryId = item.SelectSingleNode(Field.CategoryId.ToQueryString())?.InnerText;
                        Category category   = null;
                        if (categoryId != null)
                        {
                            category = context.Categories.FirstOrDefault(x => x.CatId.ToString() == categoryId);
                        }

                        var offer = new Offer
                        {
                            Author      = item.SelectSingleNode(Field.Author.ToQueryString())?.InnerText,
                            Description = item.SelectSingleNode(Field.Description.ToQueryString())?.InnerText,
                            Title       = item.SelectSingleNode(Field.Name.ToQueryString())?.InnerText,
                            Year        = item.SelectSingleNode(Field.Year.ToQueryString())?.InnerText,
                            Publisher   = item.SelectSingleNode(Field.Publisher.ToQueryString())?.InnerText,
                            ISBN        = item.SelectSingleNode(Field.ISBN.ToQueryString())?.InnerText,
                            Pages       = item.SelectSingleNode(Field.Page_Extent.ToQueryString())?.InnerText,
                            OfferId     = int.Parse(id),
                            Category    = category
                        };

                        list.Add(offer);
                        if (list.Count > 10000)
                        {
                            context.Offers.AddRange(list);
                            context.SaveChanges();
                            list.Clear();
                        }
                    }
                }
                context.Offers.AddRange(list);
                context.SaveChanges();
            }
        }
示例#10
0
        public void OrderByTitleTest()
        {
            using (var db = new BiblioContext())
            {
                Authors testAuthor = new Authors
                {
                    FirstName = "Aaron A.",
                    LastName  = "Aardvark"
                };
                db.Add(testAuthor);
                db.SaveChanges();

                int   authorId = db.Authors.OrderByDescending(a => a.AuthorId).First().AuthorId;
                Books testBook = new Books
                {
                    Title         = "A Aardvark Attractiveness Album",
                    AuthorId      = authorId,
                    Isbn10        = "0000000000",
                    Isbn13        = "0000000000000",
                    NumOfCopies   = 1,
                    NumOfPages    = 200,
                    Read          = true,
                    Review        = 5,
                    PublishedDate = "2020",
                    Publisher     = "Aardvark 'ardbacks",
                    Description   = "Aardvark attractiveness alternates accorinding to austerity apparentley, as acknowledged by Aardvark 'ardbacks anyway."
                };
                db.Add(testBook);
                db.SaveChanges();
            }

            var result = _testBiblio.GetAllBooksByTitle().First();

            Assert.AreEqual(result.Title, "A Aardvark Attractiveness Album");
            Assert.AreEqual(result.Author.FirstName, "Aaron A.");
            Assert.AreEqual(result.Author.LastName, "Aardvark");

            using (var db = new BiblioContext())
            {
                var removeBook   = db.Books.OrderByDescending(b => b.BookId).First();
                var removeAuthor = db.Authors.OrderByDescending(a => a.AuthorId).First();
                db.Remove(removeBook);
                db.SaveChanges();
                db.Remove(removeAuthor);
                db.SaveChanges();
            }
        }
        public void DeleteBookTest()
        {
            Books selectedBook;

            using (var db = new BiblioContext())
            {
                Authors testAuthor = new Authors
                {
                    FirstName = "Aaron A.",
                    LastName  = "Aardvark"
                };
                db.Add(testAuthor);
                db.SaveChanges();
                int   authorId = db.Authors.OrderByDescending(a => a.AuthorId).First().AuthorId;
                Books testBook = new Books
                {
                    Title         = "A Aardvark Attractiveness Album",
                    AuthorId      = authorId,
                    Isbn10        = "0000000000",
                    Isbn13        = "0000000000000",
                    NumOfCopies   = 1,
                    NumOfPages    = 200,
                    Read          = true,
                    Review        = 5,
                    PublishedDate = "2020",
                    Publisher     = "Aardvark 'ardbacks",
                    Description   = "Aardvark attractiveness alternates accorinding to austerity apparentley, as acknowledged by Aardvark 'ardbacks anyway."
                };
                db.Add(testBook);
                db.SaveChanges();
                selectedBook = testBook;
            }
            _testBiblio.DeleteBook(selectedBook);
            using (var db = new BiblioContext())
            {
                int resultBook   = db.Books.Where(b => b.Title == "A Aardvark Attractiveness Album").Count();
                int resultAuthor = db.Authors.Where(a => a.LastName == "Aardvark" && a.FirstName == "Aaron A.").Count();

                Assert.AreEqual(resultBook, 0);
                Assert.AreEqual(resultAuthor, 1);

                var removeAuthor = db.Authors.OrderByDescending(a => a.AuthorId).First();
                db.SaveChanges();
                db.Remove(removeAuthor);
                db.SaveChanges();
            }
        }
示例#12
0
        public BiblioController(BiblioContext context)
        {
            _context = context;
            if (_context.Livres.Count() == 0)
            {
                _context.Livres.Add(new Livre("harry potter", "jk rowling", "poche", 12345, 12));
                _context.Livres.Add(new Livre("lord of the rings", "Tolkien", "ace books", 87452, 6));
                _context.Livres.Add(new Livre("the hobbit", "Tolkien", "ace books", 87450, 6));
                _context.Livres.Add(new Livre("don quixote", "de cervantes", "glenat", 25478, 8));

                _context.Users.Add(new UtilisateurAbonne("ali"));
                _context.Users.Add(new UtilisateurAbonne("tom"));
                _context.Users.Add(new UtilisateurAbonne("tom"));

                _context.Commentaires.Add(new Commentaire(12345, "un commentaire hp"));
                _context.Commentaires.Add(new Commentaire(12345, "un deuxieme commentaire"));

                _context.SaveChanges();
            }
        }
示例#13
0
 public void FillGroup()
 {
     using (var context = new BiblioContext())
     {
         var list = new List <Category>();
         while (_xmlReader.ReadToFollowing(Constant.KeyCategory))
         {
             var id       = _xmlReader.GetAttribute("id");
             var parentId = _xmlReader.GetAttribute("parentId");
             var value    = _xmlReader.ReadElementContentAsString();
             var category = new Category
             {
                 CatId  = int.Parse(id),
                 Parent = parentId == null ? null :
                          list
                          .FirstOrDefault(x => x.Id.ToString() == parentId),
                 Name = value
             };
             list.Add(category);
         }
         context.Categories.AddRange(list);
         context.SaveChanges();
     }
 }
示例#14
0
        static int Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("BiblioGrinder <configurationString> <biblioDocument.json>");
                return(1);
            }

            log = new TeeOutput(AbstractOutput.Console);

            configurationString = args[0];
            documentPath        = args[1];

            ReadRecordCommand.ThrowOnVerify = false;

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                AbstractOutput logFile = new FileOutput("grinder.log");
                log.Output.Add(logFile);

                NativeIrbisProvider.Register();

                using (provider = ProviderManager
                                  .GetAndConfigureProvider(configurationString))
                {
                    log.WriteLine
                    (
                        "Connected to database {0}, max MFN={1}",
                        provider.Database,
                        provider.GetMaxMfn()
                    );
                    document = BiblioDocument.LoadFile(documentPath);
                    context  = new BiblioContext(document, provider, log);

                    processor = new BiblioProcessor();
                    processor.Initialize(context);
                    processor.BuildDocument(context);

                    string outputText = processor.Output.Text;

                    // TODO implement properly
                    outputText = Regex.Replace
                                 (
                        outputText,
                        @"\s(-|–|\\u8211.)\sIS[BS]N\s[0-9XxХх-]*\.?",
                        string.Empty
                                 );
                    outputText = Regex.Replace
                                 (
                        outputText,
                        @"([А-Я]\.)\s([А-Я])",
                        "$1\\~$2"
                                 );

                    outputText = Regex.Replace
                                 (
                        outputText,
                        "\\\"([\\w])",
                        "«$1"
                                 );
                    outputText = Regex.Replace
                                 (
                        outputText,
                        "([\\w\\.])\\\"",
                        "$1»"
                                 );

                    outputText = Regex.Replace
                                 (
                        outputText,
                        "\\\"(\\.\\.\\.|\\(|\\[)",
                        "«$1"
                                 );
                    outputText = Regex.Replace
                                 (
                        outputText,
                        "(\\.\\.\\.|\\!|\\?|\\)|\\])\\\"",
                        "$1»"
                                 );

                    outputText = outputText
                                 .Replace(" - ", " \\u8211? ")
                                 .Replace("}- ", "}\\u8211? ")
                                 .Replace(" -}", " \\u8211?}")
                                 .Replace(" -\\", " \\u8211?\\")
                                 .Replace("\\u8470? ", "\u8470?\\~")
                                 .Replace("...", "\\'85")
                                 .Replace("С. ", "С.\\~")
                    ;

                    File.WriteAllText
                    (
                        "output.rtf",
                        outputText,
                        IrbisEncoding.Ansi
                    );

                    stopwatch.Stop();
                    TimeSpan elapsed = stopwatch.Elapsed;
                    log.WriteLine
                    (
                        "Elapsed: {0}",
                        elapsed.ToAutoString()
                    );
                    log.WriteLine
                    (
                        "Finished at: {0}",
                        DateTime.Now
                    );
                }
            }
            catch (Exception exception)
            {
                log.WriteLine
                (
                    "Exception: {0}",
                    exception
                );

                return(1);
            }

            return(0);
        }
        public void AddBookTestExistingBook()
        {
            int preAddTestBooks   = 0;
            int preAddTestAuthor  = 0;
            int preNumCopies      = 0;
            int postAddTestBooks  = 0;
            int postAddTestAuthor = 0;
            int postNumCopies     = 0;

            using (var db = new BiblioContext())
            {
                Authors testAuthor = new Authors
                {
                    FirstName = "Aaron A.",
                    LastName  = "Aardvark"
                };
                db.Add(testAuthor);
                db.SaveChanges();
                int   authorId = db.Authors.OrderByDescending(a => a.AuthorId).First().AuthorId;
                Books testBook = new Books
                {
                    Title         = "A Aardvark Attractiveness Album",
                    AuthorId      = authorId,
                    Isbn10        = "0000000000",
                    Isbn13        = "0000000000000",
                    NumOfCopies   = 1,
                    NumOfPages    = 200,
                    Read          = true,
                    Review        = 5,
                    PublishedDate = "2020",
                    Publisher     = "Aardvark 'ardbacks",
                    Description   = "Aardvark attractiveness alternates accorinding to austerity apparentley, as acknowledged by Aardvark 'ardbacks anyway."
                };
                db.Add(testBook);
                db.SaveChanges();
                preAddTestBooks  = db.Books.Count();
                preAddTestAuthor = db.Authors.Count();
                preNumCopies     = db.Books.Where(b => b.Title == "A Aardvark Attractiveness Album").First().NumOfCopies;
            }

            _testBiblio.AddBook(AuthorFirst, AuthorLast, Title, Isbn10, Isbn13, Publisher, PublishedDate, NumOfPages, Description, Review, Read);

            using (var db = new BiblioContext())
            {
                postAddTestBooks  = db.Books.Count();
                postAddTestAuthor = db.Authors.Count();
                postNumCopies     = db.Books.Where(b => b.Title == "A Aardvark Attractiveness Album").First().NumOfCopies;
            }
            Assert.AreEqual(preAddTestBooks, postAddTestBooks);
            Assert.AreEqual(preAddTestAuthor, postAddTestAuthor);
            Assert.AreEqual(postNumCopies - 1, preNumCopies);
            using (var db = new BiblioContext())
            {
                var removeBook   = db.Books.OrderByDescending(b => b.BookId).First();
                var removeAuthor = db.Authors.OrderByDescending(a => a.AuthorId).First();
                db.Remove(removeBook);
                db.SaveChanges();
                db.Remove(removeAuthor);
                db.SaveChanges();
            }
        }
        //Method that adds books to the database
        //1)    Checks if the author is in the database
        //2a)   If author is in then author Id is set to the inputted author
        //2b)   If author isn't in then the author is added and author Id is set to the latest one in the database
        //2b.1) If the firstname contains Dr. or Prof. then that is separated and added as author Title.
        //3)    Checks if the book is in the database
        //3a)   If book is in then nothing is added
        //3b)   If book isnt then the book is added with inputted data
        public void AddBook(string authorFirst, string authorLast, string bookTitle, string isbn10 = null, string isbn13 = null, string publisher = null, string publishDate = null, int numOfPages = 0, string description = null, int review = 0, bool read = false)
        {
            using (var db = new BiblioContext())
            {
                int authorId;
                var authorQuery = db.Authors.Where(a => a.FirstName.Contains(authorFirst) && a.LastName.Contains(authorLast)).ToList();
                if (authorQuery.Count() == 0)
                {
                    if (authorFirst.ToUpper().Contains("DR."))
                    {
                        Authors author = new Authors
                        {
                            Title     = "Dr.",
                            FirstName = authorFirst.Remove(0, 4),
                            LastName  = authorLast
                        };
                        db.Add(author);
                        authorId = db.Authors.OrderByDescending(a => a.AuthorId).First().AuthorId;
                    }
                    else if (authorFirst.ToUpper().Contains("PROF."))
                    {
                        Authors author = new Authors
                        {
                            Title     = "Prof.",
                            FirstName = authorFirst.Remove(0, 6),
                            LastName  = authorLast
                        };
                        db.Add(author);
                        authorId = db.Authors.OrderByDescending(a => a.AuthorId).First().AuthorId;
                    }
                    else
                    {
                        Authors author = new Authors
                        {
                            Title     = null,
                            FirstName = authorFirst,
                            LastName  = authorLast
                        };
                        db.Add(author);
                    }
                    db.SaveChanges();
                    authorId = db.Authors.OrderByDescending(a => a.AuthorId).First().AuthorId;
                }

                else
                {
                    authorId = authorQuery.First().AuthorId;
                }
                var bookQuery = db.Books.Where(b => b.Title == bookTitle).ToList();
                if (bookQuery.Count() == 0)
                {
                    Books book = new Books
                    {
                        Title         = bookTitle,
                        Isbn10        = isbn10,
                        Isbn13        = isbn13,
                        Publisher     = publisher,
                        PublishedDate = publishDate,
                        NumOfPages    = numOfPages,
                        NumOfCopies   = 1,
                        Description   = description,
                        Read          = read,
                        AuthorId      = authorId,
                        Review        = review
                    };
                    db.Add(book);
                }
                else
                {
                    bookQuery.First().NumOfCopies++;
                }
                db.SaveChanges();
            }
        }