Esempio n. 1
0
        public void WithBookTest()
        {
            using (LibraryDb db = LibraryDb.GetDbContext())
            {
                BOOK book = new BOOK {
                    ISBN = "test", COUNT = 0, NAME = "test", PRICE = 0
                };

                using (DbManager <BOOK> manager = new DbManager <BOOK>(new ManagerBook(), book))
                {
                    manager.AddNewRow();
                    BOOK dbBook = db.BOOKS.SingleOrDefault(b => b.ID == book.ID);
                    Assert.IsNotNull(dbBook);

                    //Change book test
                    dbBook.DESCRIPTION = someText;
                    manager.Entity     = dbBook;
                    manager.UpdateRow();
                    dbBook = db.BOOKS.SingleOrDefault(b => b.ID == book.ID);
                    Assert.AreEqual(true, dbBook?.DESCRIPTION == someText);

                    //deleted test book
                    manager.RemoveRow();
                    dbBook = db.BOOKS.SingleOrDefault(b => b.ID == book.ID);
                    Assert.IsNull(dbBook);
                }
            }
        }
Esempio n. 2
0
        public void WithViewerTest()
        {
            using (LibraryDb db = LibraryDb.GetDbContext())
            {
                VIEWER viewer = new VIEWER {
                    ADDRESS = "test", EMAIL = "*****@*****.**", NAME = "test", PHONE = "testtest"
                };

                using (DbManager <VIEWER> manager = new DbManager <VIEWER>(new ManagerViewer(), viewer))
                {
                    //add viewer test
                    manager.AddNewRow();
                    VIEWER dbViewer = db.VIEWERS.SingleOrDefault(v => v.ID == viewer.ID);
                    Assert.IsNotNull(dbViewer);

                    //Change VIEWER test
                    dbViewer.MIDDLE_NAME = someText;
                    manager.Entity       = dbViewer;
                    manager.UpdateRow();
                    dbViewer = db.VIEWERS.SingleOrDefault(b => b.ID == viewer.ID);
                    Assert.AreEqual(true, dbViewer?.MIDDLE_NAME == someText);

                    //deleted test VIEWER
                    manager.RemoveRow();
                    dbViewer = db.VIEWERS.SingleOrDefault(b => b.ID == viewer.ID);
                    Assert.IsNull(dbViewer);
                }
            }
        }
Esempio n. 3
0
        public static void UpdateBook(BOOK book, LibraryDb dbContext = null)
        {
            using (LibraryDb db = LibraryDb.GetDbContext(dbContext))
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    if (book == null)
                    {
                        throw new ArgumentNullException($"book: {nameof(book)}");
                    }

                    BOOK dbBook = db.BOOKS.SingleOrDefault(b => b.ID == book.ID);
                    if (dbBook == null)
                    {
                        throw new Exception($"Книга с {book.ID} не найдена!");
                    }

                    dbBook.ISBN        = book.ISBN;
                    dbBook.NAME        = book.NAME;
                    dbBook.AUTHOR      = book.AUTHOR;
                    dbBook.PUBLISHING  = book.PUBLISHING;
                    dbBook.COUNT       = book.COUNT;
                    dbBook.STATUS      = book.STATUS;
                    dbBook.PRICE       = book.PRICE;
                    dbBook.DESCRIPTION = book.DESCRIPTION;

                    db.SaveChanges();
                    transaction.Complete();
                }
            }
        }
Esempio n. 4
0
        public static void UpdateViewer(VIEWER viewer, LibraryDb dbContext = null)
        {
            using (LibraryDb db = LibraryDb.GetDbContext(dbContext))
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    if (viewer == null)
                    {
                        throw new ArgumentNullException($"book: {nameof(viewer)}");
                    }

                    VIEWER dbViewer = db.VIEWERS.SingleOrDefault(v => v.ID == viewer.ID);
                    if (dbViewer == null)
                    {
                        throw new Exception($"Книга с {viewer.ID} не найдена!");
                    }

                    dbViewer.NAME        = viewer.NAME;
                    dbViewer.SURNAME     = viewer.SURNAME;
                    dbViewer.MIDDLE_NAME = viewer.MIDDLE_NAME;
                    dbViewer.ADDRESS     = viewer.ADDRESS;
                    dbViewer.PHONE       = viewer.PHONE;
                    dbViewer.EMAIL       = viewer.EMAIL;

                    db.SaveChanges();
                    transaction.Complete();
                }
            }
        }
Esempio n. 5
0
        public void TestViewer()
        {
            using (LibraryDb db = LibraryDb.GetDbContext())
            {
                var viewers = ViewerBl.GetViewers();

                //add viewer test
                VIEWER viewer = new VIEWER {
                    ADDRESS = "test", EMAIL = "*****@*****.**", NAME = "test", PHONE = "testtest"
                };
                ViewerBl.AddNewViewer(viewer);
                VIEWER dbViewer = db.VIEWERS.SingleOrDefault(v => v.ID == viewer.ID);
                Assert.IsNotNull(dbViewer);

                //Change VIEWER test
                dbViewer.MIDDLE_NAME = someText;
                ViewerBl.UpdateViewer(dbViewer);
                dbViewer = db.VIEWERS.SingleOrDefault(b => b.ID == viewer.ID);
                Assert.AreEqual(true, dbViewer?.MIDDLE_NAME == someText);

                //deleted test VIEWER
                ViewerBl.ViewersRemove(new[] { viewer.ID });
                dbViewer = db.VIEWERS.SingleOrDefault(b => b.ID == viewer.ID);
                Assert.IsNull(dbViewer);
            }
        }
Esempio n. 6
0
        public void TestBook()
        {
            using (LibraryDb db = LibraryDb.GetDbContext())
            {
                var books = BooksBl.GetBooks();

                //add book test
                BOOK book = new BOOK {
                    ISBN = "test", COUNT = 0, NAME = "test", PRICE = 0
                };
                BooksBl.AddNewCard(book);
                BOOK dbBook = db.BOOKS.SingleOrDefault(b => b.ID == book.ID);
                Assert.IsNotNull(dbBook);

                //Change book test
                dbBook.DESCRIPTION = someText;
                BooksBl.UpdateBook(dbBook);
                dbBook = db.BOOKS.SingleOrDefault(b => b.ID == book.ID);
                Assert.AreEqual(true, dbBook?.DESCRIPTION == someText);

                //deleted test book
                BooksBl.BooksRemove(new[] { book.ID });
                dbBook = db.BOOKS.SingleOrDefault(b => b.ID == book.ID);
                Assert.IsNull(dbBook);
            }
        }
Esempio n. 7
0
        public static void AddNewCard(BOOK book, LibraryDb dbContext = null)
        {
            using (LibraryDb db = LibraryDb.GetDbContext(dbContext))
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    db.BOOKS.Add(book);

                    db.SaveChanges();

                    transaction.Complete();
                }
            }
        }
Esempio n. 8
0
        public static void AddNewViewer(VIEWER viewer, LibraryDb dbContext = null)
        {
            using (LibraryDb db = LibraryDb.GetDbContext(dbContext))
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    db.VIEWERS.Add(viewer);

                    db.SaveChanges();

                    transaction.Complete();
                }
            }
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            //using (var db = new LibraryDb())
            //{
            //    db.Database.Initialize(true);
            //    var book = db.BOOKS.ToList();
            //    var viewersve = db.VIEWERS.ToList();
            //}

            using (LibraryDb db = LibraryDb.GetDbContext())
            {
                var qwer = db.Database.ExecuteSqlCommand("SELECT * FROM BOOKs");

                Thread.Sleep(5000);
            }

            Console.ReadKey();
        }
Esempio n. 10
0
        public static void BooksRemove(decimal[] booksId, LibraryDb dbContext = null)
        {
            using (LibraryDb db = LibraryDb.GetDbContext(dbContext))
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    foreach (decimal id in booksId)
                    {
                        BOOK book = db.BOOKS.SingleOrDefault(b => b.ID == id);

                        if (book != null)
                        {
                            db.BOOKS.Remove(book);
                        }
                    }

                    db.SaveChanges();

                    transaction.Complete();
                }
            }
        }
Esempio n. 11
0
        public static void ViewersRemove(decimal[] idViewers, LibraryDb dbContext = null)
        {
            using (LibraryDb db = LibraryDb.GetDbContext(dbContext))
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    foreach (decimal id in idViewers)
                    {
                        VIEWER viewer = db.VIEWERS.SingleOrDefault(b => b.ID == id);

                        if (viewer != null)
                        {
                            db.VIEWERS.Remove(viewer);
                        }
                    }

                    db.SaveChanges();

                    transaction.Complete();
                }
            }
        }
Esempio n. 12
0
 public static IEnumerable <BOOK> GetBooks(LibraryDb dbContext = null)
 {
     using (LibraryDb db = LibraryDb.GetDbContext(dbContext))
         return(db.BOOKS.ToList());
 }
Esempio n. 13
0
 public static IEnumerable <VIEWER> GetViewers(LibraryDb dbContext = null)
 {
     using (LibraryDb db = LibraryDb.GetDbContext(dbContext))
         return(db.VIEWERS.ToList());
 }