예제 #1
0
파일: Author.cs 프로젝트: Rick1970/library
        //
        public static Author Find(int id)
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT * FROM authors WHERE id = @AuthorId;", conn);
              SqlParameter authorIdParameter = new SqlParameter();
              authorIdParameter.ParameterName = "@AuthorId";
              authorIdParameter.Value = id.ToString();

              cmd.Parameters.Add(authorIdParameter);

              SqlDataReader rdr = cmd.ExecuteReader();

              int foundAuthorId = 0;
              string foundAuthorName = null;

              while (rdr.Read())
              {
            foundAuthorId = rdr.GetInt32(0);
            foundAuthorName = rdr.GetString(1);
              }
              Author foundAuthor = new Author(foundAuthorName, foundAuthorId);

              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return foundAuthor;
        }
예제 #2
0
        public void T12_SearchByAuthor_SearchForBookByAuthor()
        {
            Author testAuthor1 = new Author("Franzen");
              testAuthor1.Save();
              Author testAuthor2 = new Author("Rowling");
              testAuthor2.Save();

              Book testBook1 = new Book("Freedom");
              testBook1.Save();
              Book testBook2 = new Book("Harry Potter and the Deathly Hallows");
              testBook2.Save();
              Book testBook3 = new Book("Harry Potter and the Chamber of Secrets");
              testBook3.Save();

              testBook1.AddAuthor(testAuthor1);
              testBook2.AddAuthor(testAuthor2);
              testBook3.AddAuthor(testAuthor2);

              List<Book> result = Book.SearchByAuthor("Rowling");
              List<Book> testBooks = new List<Book> {testBook2, testBook3};
              // Console.WriteLine(testBooks[0].GetTitle());
              // Console.WriteLine(result[0].GetTitle());
              // Console.WriteLine(testBooks[1].GetTitle());
              // Console.WriteLine(result[1].GetTitle());

              Assert.Equal(testBooks, result);
        }
예제 #3
0
        public EditAuthorWindow(ref IObjectContainer db, Author author)
        {
            InitializeComponent();
            _db = db;
            _author = author;
            Title += _author.LastName;

            // fill form
            LastNameTxtBox.Text = _author.LastName;
            BirthDatepicker.SelectedDate = _author.BirthDate;

            var collection = new ObservableCollection<PublicationEditableGrid>();
            foreach (var item in _db.QueryByExample(new Publication()))
            {
                var itemPub = item as Publication;
                collection.Add(new PublicationEditableGrid()
                {
                    Title = itemPub.Title,
                    Year = itemPub.Year,
                    IsAuthor = _author.Publications.Contains(itemPub)
                });
            }
            publicationsGrid.ItemsSource = collection.OrderBy(x => x.Title);
            publicationsGrid.SelectedItem = null;
        }
예제 #4
0
 private void saveBtn_Click(object sender, RoutedEventArgs e)
 {
     if (LastNameTxtBox.Text.Trim()==String.Empty){
         MessageBox.Show("Pole Nazwisko nie może być puste");
         return;
     }
     var author = new Author();
     author.LastName = LastNameTxtBox.Text.Replace(";","").Trim();
     author.BirthDate = BirthDatepicker.SelectedDate.HasValue ? BirthDatepicker.SelectedDate.Value : DateTime.Now;
     author.Publications = new List<Publication>();
     _db.Store(author);
     var all = _db.Query<Publication>().ToList();
     foreach (var item in publicationsGrid.Items)
     {
         var itemObj = item as PublicationEditableGrid;
         var one = all.Where(x => x.Year == itemObj.Year && x.Title == itemObj.Title).First();
         if (itemObj.IsAuthor)
         {
             author.Publications.Add(one);
             one.Authors.Add(author);
         }
         _db.Store(one.Authors);
     }
     _db.Store(author.Publications);
     isClosedWithSave = true;
     this.Close();
 }
예제 #5
0
        public static Author Find(int searchId)
        {
            Author foundAuthor = new Author(""); //Program needs some value inside a Author object
              SqlConnection conn = DB.Connection();
              conn.Open();
              SqlDataReader rdr = null;

              SqlCommand cmd = new SqlCommand ("SELECT * FROM authors WHERE id = @AuthorId;", conn);

              SqlParameter idParameter = new SqlParameter();
              idParameter.ParameterName = "@AuthorId";
              idParameter.Value = searchId;

              cmd.Parameters.Add(idParameter);

              rdr = cmd.ExecuteReader();

              while (rdr.Read())
              {
            int authorId = rdr.GetInt32(0);
            string authorName = rdr.GetString(1);
            Author newAuthor = new Author(authorName, authorId);
            foundAuthor = newAuthor;
              }
              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return foundAuthor;
        }
예제 #6
0
        public void T2_Equal_ReturnsTrueIfAuthorIsSame()
        {
            Author firstAuthor = new Author("Rowling");
              Author secondAuthor = new Author("Rowling");

              Assert.Equal(firstAuthor, secondAuthor);
        }
예제 #7
0
        public void Test_Equal_EntriesMatch()
        {
            Author testAuthor1 = new Author ("Brian Jacques");
              Author testAuthor2 = new Author ("Brian Jacques");

              Assert.Equal(testAuthor1, testAuthor2);
        }
예제 #8
0
        public void T5_Find_FindsAuthorInDatabase()
        {
            Author testAuthor = new Author("Rowling");
              testAuthor.Save();

              Author foundAuthor = Author.Find(testAuthor.GetId());

              Assert.Equal(testAuthor, foundAuthor);
        }
예제 #9
0
        public void Test_Find_FindsAuthorInDatabase()
        {
            Author testAuthor1 = new Author ("Brian Jacques");
              testAuthor1.Save();

              Author result = Author.Find(testAuthor1.GetId());

              Assert.Equal(testAuthor1, result);
        }
예제 #10
0
        public void T3_Save_SavesToDB()
        {
            Author testAuthor = new Author("Rowling");
              testAuthor.Save();

              List<Author> result = Author.GetAll();
              List<Author> testList = new List<Author>{testAuthor};

              Assert.Equal(testList, result);
        }
예제 #11
0
 private void buttonAdd_Click(object sender, EventArgs e)
 {
     LibraryEntities context = new LibraryEntities();
     Author newAuthor = new Author()
     {
         FName = textBoxFName.Text,
         LName = textBoxLName.Text
     };
     context.Author.AddObject(newAuthor);
     context.SaveChanges();
 }
예제 #12
0
        public void T4_Save_AssignsIdToAuthor()
        {
            Author testAuthor = new Author("Rowling");
              testAuthor.Save();

              Author savedAuthor = Author.GetAll()[0];
              int result = savedAuthor.GetId();
              int testId = testAuthor.GetId();

              Assert.Equal(testId, result);
        }
예제 #13
0
        public void Test_GetAuthors()
        {
            Author a = new Author("Allen");
              a.Save();

              Book newbook = new Book("2a", "Sf", "The blob");
              newbook.Save();

              newbook.AddAuthor(a.id);

              Assert.Equal(a.id, newbook.GetAuthors()[0].id);
        }
예제 #14
0
        public void Test_AddBook_AddsBookToAuthor()
        {
            Author newAuthor = new Author ("Brian Jacques");
              newAuthor.Save();
              Book newBook = new Book ("Redwall");
              newBook.Save();
              newAuthor.AddBook(newBook);

              List<Book> testBook = new List<Book> {newBook};
              List<Book> allBooks = newAuthor.GetBooks();

              Assert.Equal(testBook, allBooks);
        }
예제 #15
0
        public void T6_Update_UpdatesAuthorInDB()
        {
            Author testAuthor = new Author("Rowling");
              testAuthor.Save();

              string newName = "Franzen";

              testAuthor.Update(newName);

              string resultName = testAuthor.GetName();

              Assert.Equal(newName, resultName);
        }
예제 #16
0
        public void Test_AddAuthor_AddsAuthorToBook()
        {
            Book newBook = new Book ("Redwall");
              newBook.Save();
              Author newAuthor = new Author ("Brian Jacques");
              newAuthor.Save();
              newBook.AddAuthor(newAuthor);

              List<Author> testAuthor = new List<Author> {newAuthor};
              List<Author> allAuthors = newBook.GetAuthors();

              Assert.Equal(testAuthor, allAuthors);
        }
예제 #17
0
        public void Test_FindByAuthor_FindsBookByAuthor()
        {
            Book testBook = new Book ("Redwall");
              testBook.Save();
              Author newAuthor = new Author ("Brian Jacques");
              newAuthor.Save();

              testBook.AddAuthor(newAuthor);

              List<Book> testBookList = new List<Book> {testBook};
              List<Book> resultBookList = Book.FindByAuthor("Jac.Ques");

              Assert.Equal(testBookList, resultBookList);
        }
예제 #18
0
        public void Test_DeleteOne_DeletesOneAuthor()
        {
            Author newAuthor1 = new Author ("Brian Jacques");
              Author newAuthor2 = new Author ("Anne Rice");
              newAuthor1.Save();
              newAuthor2.Save();
              List<Author> newList = Author.GetAll();

              newAuthor1.DeleteOne();

              List<Author> resultList = Author.GetAll();
              List<Author> testList = new List<Author> {newAuthor2};

              Assert.Equal(testList, resultList);
        }
예제 #19
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            LibraryEntities1 context = new LibraryEntities1();
            if (textBoxLName.Text!="")
            {
                Author newAuthor = new Author()
                {
                    FName = textBoxFName.Text,
                    LName = textBoxLName.Text
                };

                context.Authors.AddObject(newAuthor);
                context.SaveChanges();
                MessageBox.Show("Авторът е добавен.");
            }
            else MessageBox.Show("Грешка! Няма въведени данни.");
        }
예제 #20
0
        public void T10_AddExistingAuthor()
        {
            Author testAuthor1 = new Author("Franzen");
              testAuthor1.Save();
              Author testAuthor2 = new Author("Franzen");
              testAuthor2.Save();

              Book testBook = new Book("Freedom");
              testBook.Save();
              Book testBook2 = new Book("Example");
              testBook2.Save();

              testBook.AddAuthor(testAuthor1);
              testBook.AddAuthor(testAuthor2);

              int result = testBook.GetAuthors().Count;

              Assert.Equal(1, result);
        }
예제 #21
0
        public HomeModule()
        {
            Get["/"] = _ => {
            Dictionary<string, object> model = new Dictionary<string, object>();
            List<Book> booksByTitle = Book.SearchByTitle("VOID-SEARCH-TO-PREVENT-DATA");
            List<Book> booksByAuthor = Book.SearchByAuthor("VOID-SEARCH-TO-PREVENT-DATA");
            model.Add("booksByTitle", booksByTitle);
            model.Add("booksByAuthor", booksByAuthor);
            return View["index.cshtml", model];
              };

              Get["/librarian"] = _ => {
            return View["librarian.cshtml"];
              };

              Post["/success"] = _ => {
            Book newBook = new Book(Request.Form["title-input"]);
            newBook.Save();

            Author newAuthor = new Author(Request.Form["author-input"]);
            newAuthor.Save();

            newBook.AddAuthor(newAuthor);

            Dictionary<string, object> model = new Dictionary<string, object>();
            model.Add("addedBook", newBook);
            model.Add("addedAuthor", newAuthor);

            return View["success.cshtml", model];
              };

              Post["/results"] = _ => {
            string input = Request.Form["search-input"];
            Dictionary<string, object> model = new Dictionary<string, object>();
            List<Book> booksByTitle = Book.SearchByTitle(input.ToString());
            List<Book> booksByAuthor = Book.SearchByAuthor(input.ToString());
            model.Add("booksByTitle", booksByTitle);
            model.Add("booksByAuthor", booksByAuthor);
            return View["index.cshtml", model];
              };
        }
예제 #22
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Authors EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToAuthors(Author author)
 {
     base.AddObject("Authors", author);
 }
예제 #23
0
        public static List<Author> GetAll()
        {
            List<Author> allAuthors = new List<Author> {};
              SqlConnection conn = DB.Connection();
              conn.Open();
              SqlDataReader rdr = null;

              SqlCommand cmd = new SqlCommand ("SELECT * FROM authors;", conn);

              rdr = cmd.ExecuteReader();

              while (rdr.Read())
              {
            int authorId = rdr.GetInt32(0);
            string authorName = rdr.GetString(1);
            Author newAuthor = new Author (authorName, authorId);
            allAuthors.Add(newAuthor);
              }
              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return allAuthors;
        }
예제 #24
0
        public static void CreateData()
        {
            if (isCalled == true)
            {
                return;
            }

            ReaderCard readerCard1 = new ReaderCard
            {
                Id                 = 1,
                Name               = "Василій",
                Surname            = "Пупкін",
                Age                = 17,
                Email              = "*****@*****.**",
                DateOfRegistration = new DateTime(2018, 10, 2)
            };
            ReaderCard readerCard2 = new ReaderCard
            {
                Id                 = 2,
                Name               = "Анастасія",
                Surname            = "Козаченко",
                Age                = 19,
                Email              = "*****@*****.**",
                DateOfRegistration = new DateTime(2016, 3, 30)
            };
            ReaderCard readerCard3 = new ReaderCard
            {
                Id                 = 3,
                Name               = "Віталій",
                Surname            = "Дзюба",
                Age                = 24,
                Email              = "*****@*****.**",
                DateOfRegistration = new DateTime(2019, 4, 13)
            };

            Reader reader1 = new Reader()
            {
                Id = 1, ReaderCard = readerCard1
            };
            Reader reader2 = new Reader()
            {
                Id = 2, ReaderCard = readerCard2
            };
            Reader reader3 = new Reader()
            {
                Id = 3, ReaderCard = readerCard3
            };

            Book book1 = new Book()
            {
                Id = 1, Name = "Том в Гренландії"
            };
            Book book2 = new Book()
            {
                Id = 2, Name = "Філософія думок"
            };
            Book book3 = new Book()
            {
                Id = 3, Name = "Останній листок"
            };

            Record record1 = new Record
            {
                Id              = 1,
                Book            = book3,
                DateOfReceiving = new DateTime(2019, 10, 24),
                Reader          = reader1
            };
            Record record2 = new Record
            {
                Id              = 2,
                Book            = book1,
                DateOfReceiving = new DateTime(2020, 1, 16),
                Reader          = reader1
            };
            Record record3 = new Record
            {
                Id              = 3,
                Book            = book2,
                DateOfReceiving = new DateTime(2019, 5, 24),
                Reader          = reader2
            };
            Record record4 = new Record
            {
                Id              = 4,
                Book            = book3,
                DateOfReceiving = new DateTime(2019, 9, 4),
                Reader          = reader2
            };
            Record record5 = new Record
            {
                Id              = 5,
                Book            = book1,
                DateOfReceiving = new DateTime(2019, 6, 24),
                Reader          = reader3
            };

            reader1.Records.Add(record1);
            reader1.Records.Add(record2);
            reader2.Records.Add(record3);
            reader2.Records.Add(record4);
            reader3.Records.Add(record5);

            Chapter chapter1 = new Chapter()
            {
                Id = 1, Name = "Вступ", Book = book1
            };
            Chapter chapter2 = new Chapter()
            {
                Id = 2, Name = "Пригоди тома", Book = book1
            };
            Chapter chapter3 = new Chapter()
            {
                Id = 3, Name = "Завершення історії", Book = book1
            };
            Chapter chapter4 = new Chapter()
            {
                Id = 4, Name = "Усе починається з думки", Book = book2
            };
            Chapter chapter5 = new Chapter()
            {
                Id = 5, Name = "Думай серцем", Book = book2
            };
            Chapter chapter6 = new Chapter()
            {
                Id = 6, Name = "Холодна осінь", Book = book3
            };
            Chapter chapter7 = new Chapter()
            {
                Id = 7, Name = "Опале листя", Book = book3
            };

            book1.Chapters.Add(chapter1);
            book1.Chapters.Add(chapter2);
            book1.Chapters.Add(chapter3);
            book2.Chapters.Add(chapter4);
            book2.Chapters.Add(chapter5);
            book3.Chapters.Add(chapter6);
            book3.Chapters.Add(chapter7);

            Author author1 = new Author()
            {
                Id = 1, Name = "Георг", Surname = "Кельвінгтон", BirthDate = new DateTime(1965, 3, 25)
            };
            Author author2 = new Author()
            {
                Id = 2, Name = "Фрідріх", Surname = "Ніцше", BirthDate = new DateTime(1873, 6, 16)
            };
            Author author3 = new Author()
            {
                Id = 3, Name = "Себастьян", Surname = "Крудз", BirthDate = new DateTime(1983, 4, 11)
            };
            Author author4 = new Author()
            {
                Id = 4, Name = "Фредеріка", Surname = "Крудз", BirthDate = new DateTime(1878, 8, 3)
            };

            AuthorBook authorBook1 = new AuthorBook()
            {
                Id = 1, Author = author1, Book = book1
            };
            AuthorBook authorBook2 = new AuthorBook()
            {
                Id = 2, Author = author2, Book = book2
            };
            AuthorBook authorBook3 = new AuthorBook()
            {
                Id = 3, Author = author3, Book = book2
            };
            AuthorBook authorBook4 = new AuthorBook()
            {
                Id = 4, Author = author3, Book = book3
            };
            AuthorBook authorBook5 = new AuthorBook()
            {
                Id = 5, Author = author4, Book = book3
            };

            book1.AuthorBooks.Add(authorBook1);
            book2.AuthorBooks.Add(authorBook2);
            book2.AuthorBooks.Add(authorBook3);
            book3.AuthorBooks.Add(authorBook4);
            book3.AuthorBooks.Add(authorBook5);
            author1.AuthorBooks.Add(authorBook1);
            author2.AuthorBooks.Add(authorBook2);
            author3.AuthorBooks.Add(authorBook3);
            author3.AuthorBooks.Add(authorBook4);
            author4.AuthorBooks.Add(authorBook5);

            Readers.AddRange(new List <Reader>()
            {
                reader1, reader2, reader3
            });
            Books.AddRange(new List <Book>()
            {
                book1, book2, book3
            });
            Authors.AddRange(new List <Author>()
            {
                author1, author2, author3, author4
            });

            isCalled = true;
        }
예제 #25
0
        private void buttonSearch_Click(object sender, EventArgs e)
        {
            if (al == 0)
            {
                LibraryEntities1 context = new LibraryEntities1();
                if (comboBoxSearch.SelectedItem.ToString().Trim() == "Автор")
                {
                    string authorLName = textBoxSearch.Text.Trim();
                    Author author      = context.Authors.FirstOrDefault(p => p.LName == authorLName);

                    if (author != null)
                    {
                        var books = context.Books.ToList();

                        var datasource = (from b in books
                                          where b.Authors.Contains(author)
                                          select b).ToList();

                        dataGridViewBooks.AutoGenerateColumns = false;
                        dataGridViewBooks.DataSource          = datasource;
                    }
                    else
                    {
                        MessageBox.Show("Грешка! Няма автор с това име!");
                    }
                }

                else if (comboBoxSearch.SelectedItem.ToString().Trim() == "Заглавие")
                {
                    var books =
                        from book in context.Books
                        where book.Title.Trim() == textBoxSearch.Text.Trim()
                        select book;
                    if (books != null)
                    {
                        dataGridViewBooks.AutoGenerateColumns = false;
                        dataGridViewBooks.DataSource          = books;
                    }
                    else
                    {
                        MessageBox.Show("Грешка! Няма книга с това заглавие!");
                    }
                }
                else if (comboBoxSearch.SelectedItem.ToString().Trim() == "Инвентарен номер")
                {
                    var books =
                        from book in context.Books
                        where book.InvNum.Trim() == textBoxSearch.Text.Trim()
                        select book;
                    if (books != null)
                    {
                        dataGridViewBooks.AutoGenerateColumns = false;
                        dataGridViewBooks.DataSource          = books;
                    }
                    else
                    {
                        MessageBox.Show("Грешка! Няма книга с този инвентарен номер!");
                    }
                }
                else if (comboBoxSearch.SelectedItem.ToString().Trim() == "ISBN")
                {
                    var books =
                        from book in context.Books
                        where book.ISBN.Trim() == textBoxSearch.Text.Trim()
                        select book;
                    if (books != null)
                    {
                        dataGridViewBooks.AutoGenerateColumns = false;
                        dataGridViewBooks.DataSource          = books;
                    }
                    else
                    {
                        MessageBox.Show("Грешка! Няма книга с този ISBN!");
                    }
                }
            }
        }
예제 #26
0
        public void Test_Search()
        {
            Author a = new Author("Allen");
              a.Save();

              Book newbook = new Book("2a", "Sf", "The blob");
              newbook.Save();

              newbook.AddAuthor(a.id);

              List<Book> search= Book.Search("Allen", "author");

              Assert.Equal(1,search.Count);
        }
예제 #27
0
파일: Book.cs 프로젝트: Rick1970/library
        public void AddAuthor(Author addedAuthor)
        {
            //Prevents adding author if author is already added to a book
              List<Author> bookAuthors = this.GetAuthors();
              bool isDuplicate = false;
              foreach (var author in bookAuthors)
              {
            if (addedAuthor.GetName() == author.GetName())
            {
              isDuplicate = true;
            }
              }
              if (isDuplicate == false)
              {
            SqlConnection conn = DB.Connection();
            conn.Open();

            SqlCommand cmd = new SqlCommand("INSERT INTO books_authors (author_id, book_id) VALUES (@AuthorId, @BookId);", conn);

            SqlParameter authorIdParameter = new SqlParameter();
            authorIdParameter.ParameterName = "@AuthorId";
            authorIdParameter.Value = addedAuthor.GetId();
            cmd.Parameters.Add(authorIdParameter);

            SqlParameter bookIdParameter = new SqlParameter();
            bookIdParameter.ParameterName = "@BookId";
            bookIdParameter.Value = this.GetId();
            cmd.Parameters.Add(bookIdParameter);

            cmd.ExecuteNonQuery();

            if (conn != null)
            {
              conn.Close();
            }
              }
        }
예제 #28
0
        public void AddAuthor(Author newAuthor)
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand ("INSERT INTO authors_books (author_id, book_id) VALUES (@AuthorId, @BookId);", conn);

              SqlParameter authorIdParameter = new SqlParameter();
              authorIdParameter.ParameterName = "@AuthorId";
              authorIdParameter.Value = newAuthor.GetId();

              SqlParameter bookIdParameter = new SqlParameter();
              bookIdParameter.ParameterName = "@BookId";
              bookIdParameter.Value = this.GetId();

              cmd.Parameters.Add(authorIdParameter);
              cmd.Parameters.Add(bookIdParameter);

              cmd.ExecuteNonQuery();

              if (conn != null)
              {
            conn.Close();
              }
        }
예제 #29
0
 public void Dispose()
 {
     Author.DeleteAll();
     Book.DeleteAll();
 }
예제 #30
0
        public void T13_SearchByAuthor_SearchForBookByAuthor()
        {
            Author testAuthor1 = new Author("Franzen");
              testAuthor1.Save();
              Author testAuthor2 = new Author("J. K. Rowling");
              testAuthor2.Save();
              Author testAuthor3 = new Author("Fred Rowling Jr.");
              testAuthor3.Save();

              Book testBook1 = new Book("Freedom");
              testBook1.Save();
              Book testBook2 = new Book("Harry Potter and the Deathly Hallows");
              testBook2.Save();
              Book testBook3 = new Book("How to Make Pizza");
              testBook3.Save();

              testBook1.AddAuthor(testAuthor1);
              testBook2.AddAuthor(testAuthor2);
              testBook3.AddAuthor(testAuthor3);

              List<Book> result = Book.SearchByAuthor("Rowling");
              List<Book> testBooks = new List<Book> {testBook2, testBook3};

              Assert.Equal(testBooks, result);
        }
예제 #31
0
 public UCAuthorBook(AuthorService aService, BookService bService, BookCopyService bcService, Author author, Book book)
 {
     InitializeComponent();
     pBook            = book;
     pAuthor          = author;
     pAuthorService   = aService;
     pBookService     = bService;
     pBookCopyService = bcService;
     init();
 }
예제 #32
0
 /// <summary>
 /// Create a new Author object.
 /// </summary>
 /// <param name="authorID">Initial value of the AuthorID property.</param>
 /// <param name="lName">Initial value of the LName property.</param>
 public static Author CreateAuthor(global::System.Int32 authorID, global::System.String lName)
 {
     Author author = new Author();
     author.AuthorID = authorID;
     author.LName = lName;
     return author;
 }
예제 #33
0
        public HomeModule()
        {
            Get["/"] =_=>{
            return View["index.cshtml"];
              };

              Get["/references"] =_=>{
            List<Book> search = new List<Book> {};
            return View["references.cshtml",search];
              };

              Get["/patrons"]=_=>{
            List<Book> search = new List<Book> {};
            return View["patrons.cshtml",search];
              };

              Get["/books/{id}"] =parameters=> {
            Book b = Book.Find(parameters.id);
            return View["book.cshtml", b];
              };
              Get["/patronview/books/{id}"] =parameters=> {
            Book b = Book.Find(parameters.id);
            return View["patronview-book.cshtml", b];
              };
              Get["/copies/{id}"] =parameters=> {
            Copy c = Copy.Find(parameters.id);
            return View["copy.cshtml", c];
              };
              Get["/patronview/copies/{id}"] =parameters=> {
            Copy c = Copy.Find(parameters.id);
            return View["patronview-copy.cshtml", c];
              };
              Delete["/copies/delete/{id}"] =parameters=> {
            Copy c = Copy.Find(parameters.id);
            c.Delete(new string[] {"checkouts"}, new string[] {"copy_id"});
            return View["book.cshtml", Book.Find(c.book_id)];
              };
              Patch["/books/edit/{id}"] =parameters=> {
            Book b = Book.Find(parameters.id);
            b.Update(new List<string> {"call_number", "collection", "title"}, new List<object> {(string)Request.Form["callNumber"], (string)Request.Form["collection"], (string)Request.Form["title"]});
            b.RemoveAuthors();
            for(int i = 0; i<Request.Form["number-of-authors"]; i++)
            {
              Author a = Author.FindByName(Request.Form["author" + i]);
              if(a==null)
              {
            a = new Author(Request.Form["author" + i]);
            a.Save();
              }
              b.AddAuthor(a.id);
            }
            return View["book.cshtml", b];
              };
              Get["/circulation"] =_=>{
            return View["circulation.cshtml"];
              };
              Post["/patron/new"] =_=> {
            Patron p = new Patron(0, (string)Request.Form["name"], "");
            p.Save();
            return View["patron.cshtml", p];
              };
              Post["/check-out/{id}"] =parameters=> {
            Patron p = Patron.Find(parameters.id);
            Copy c = Copy.Find((int)Request.Form["itemId"]);
            if(c!=null)
            {
              p.Checkout(c.id);
            }
            return View["patron.cshtml", p];
              };
              Get["/check-in"] =_=> {
            return View["check-in.cshtml"];
              };
              Post["/check-in/new"] =_=> {
            int copyId = (int)Request.Form["id"];
            Copy c = Copy.Find(copyId);
            if(c!=null)
            {
              c.Checkin();
            }
            return View["check-in.cshtml"];
              };
              Get["/check-out"] =_=> {
            return View["check-out.cshtml", ""];
              };
              Post["/patron"] =_=> {
            Patron p = Patron.Find((int)Request.Form["patronId"]);
            if(p==null)
            {
              return View["check-out.cshtml", "No Patron Found"];
            }
            else
            {
              return View["patron.cshtml", p];
            }
              };

              Post["/patronview"] =_=> {
            Patron p = Patron.Find((int)Request.Form["patronId"]);
            if(p==null)
            {
              return View["check-out.cshtml", "No Patron Found"];
            }
            else
            {
              return View["patronview.cshtml", p];
            }
              };

              Get["/catalog"] =_=>{
            return View["catalog.cshtml"];
              };
              Post["books/new"] =_=> {
            Book newBook = new Book(Request.Form["callNumber"], Request.Form["collection"], Request.Form["title"]);
            newBook.Save();
            Copy newCopy = new Copy(newBook.id, new DateTime(1900,1,1), 0);
            newCopy.Save();
            for(int i = 0; i<Request.Form["number-of-authors"]; i++)
            {
              Author a = Author.FindByName(Request.Form["author" + i]);
              if(a==null)
              {
            a = new Author(Request.Form["author" + i]);
            a.Save();
              }
              newBook.AddAuthor(a.id);
            }
            return View["book.cshtml", newBook];
              };
              Post["copies/new"] =_=> {
            int bookId = (int)Request.Form["book_id"];
            Copy newCopy = new Copy(bookId, new DateTime(1900,1,1), 0);
            newCopy.Save();
            return View["copy.cshtml", newCopy];
              };

              Post["/search"] =_=> {
            string search = Request.Form["search"];
            string searchType = Request.Form["searchdef"];

            List<Book> booksearch = Book.Search(search,searchType);

            return View["references.cshtml",booksearch];
              };
              Post["/patronview/search"] =_=> {
            string search = Request.Form["search"];
            string searchType = Request.Form["searchdef"];

            List<Book> booksearch = Book.Search(search,searchType);

            return View["patrons.cshtml",booksearch];
              };
              Get["/patron/edit/{id}"]=parameters=>{
            Patron findpatron = Patron.Find(parameters.id);

            return View["updatepatron.cshtml", findpatron];
              };

              Patch["/patron/edit/{id}"]=parameters=>{
            Patron findpatron = Patron.Find(parameters.id);

            findpatron.Update(new List<string>{"name", "notes"}, new List<object>{(string)Request.Form["patronname"], (string)Request.Form["notes"]});

            return View["patron.cshtml", findpatron];
              };
              Patch["/patron/payfines/{id}"]=parameters=> {
            Patron p = Patron.Find(parameters.id);
            p.PayFines(Request.Form["amount"]);
            return View["patron.cshtml", p];
              };

              Get["/overdue"]=_=>
              {
            List<Copy> overDueBooks = Copy.OverdueBooks();
            return View["overdue.cshtml",overDueBooks];
              };

              Get["/patron/{id}"] = parameters => {
            Patron p = Patron.Find(parameters.id);
            return View["patron.cshtml", p];
              };
        }
예제 #34
0
        public void T1_DBEmptyAtFirst()
        {
            int result = Author.GetAll().Count;

            Assert.Equal(0, result);
        }
        /// <summary>
        /// Validates the input fields and then if a book has been selected it Saves the changes made to that book, otherwise it creates a new Book.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveChangesBTN_Click(object sender, EventArgs e)
        {
            if (ValidBookInfo()) // Confirms that all input fields are valid before continuing.
            {
                // Reads all author input fields that are open and saves the author names in a string list
                List <string> authorNames   = new List <string>();
                int           authorTBIndex = BookInfoFLP.Controls.IndexOf(editAuthorTB);
                for (int i = 0; i < authorFields; i++)
                {
                    TextBox currentTB = (TextBox)BookInfoFLP.Controls[authorTBIndex + i];
                    authorNames.Add(currentTB.Text);
                }
                bool createNewAuthor = false;


                List <Author> authorlist = new List <Author>();
                foreach (string an in authorNames)
                {
                    Author auth = authorService.GetAuthorByName(an); // Checks to see if author with same name exists, if so, uses that author instead of creating a duplicate.
                    if (auth == null)                                // If no author with the name was found
                    {
                        createNewAuthor = true;
                        auth            = new Author()
                        {
                            Name = an.Trim(' ') // Trim value to remove potential space before and after name
                        };
                    }
                    authorlist.Add(auth);
                }
                // Create new book
                if (lbBooks.SelectedItem == null)
                {
                    string confirmBoxText = createNewAuthor ? "No author that matches your input was found, by continiuing you will create a new Author entry as well as a new book entry." :
                                            "Continuing will add a new book to the database. Please verify that all book information is correct before confirmation.";
                    string confirmBoxTitle = "Confirm addition of new book";
                    if (ConfirmedPopup(confirmBoxText, confirmBoxTitle))
                    {
                        Book newBook = new Book()
                        {
                            Title       = editTitleTB.Text,
                            ISBN        = editISBNTB.Text,
                            Authors     = authorlist,
                            Description = editDescriptionTB.Text
                        };

                        bookService.Add(newBook);
                        UpdateBookList(bookService.All().ToList());
                    }
                }
                else //Update Book
                {
                    string confirmBoxText = "You are about to edit: '" + currentBookDisplay[lbBooks.SelectedIndex].ToString() + "'.\r\n" +
                                            "Please verify that all book information is correct before confirmation.";
                    string confirmBoxTitle = "Confirm Book Info Update";
                    if (ConfirmedPopup(confirmBoxText, confirmBoxTitle))
                    {
                        Book b = lbBooks.SelectedItem as Book;
                        if (b != null)
                        {
                            b.Title       = editTitleTB.Text;
                            b.ISBN        = editISBNTB.Text;
                            b.Authors     = authorlist;
                            b.Description = editDescriptionTB.Text;
                            bookService.Edit(b);
                        }
                    }
                }
            }
            else // If not all input fields were valid entries.
            {
                string confirmBoxText  = "All fields did not contain valid data. Make sure your Author and Title fields are filled out.";
                string confirmBoxTitle = "Invalid book entry";
                InfoPopup(confirmBoxText, confirmBoxTitle);
            }
        }
예제 #36
0
        public List<Author> GetAuthors()
        {
            List<Author> allAuthors = new List<Author> {};
              SqlConnection conn = DB.Connection();
              conn.Open();
              SqlDataReader rdr = null;

              SqlCommand cmd = new SqlCommand ("SELECT authors.* FROM books JOIN authors_books ON (books.id = authors_books.book_id) JOIN authors ON (authors.id = authors_books.author_id) WHERE books.id = @BookId;", conn);

              SqlParameter bookIdParameter = new SqlParameter();
              bookIdParameter.ParameterName = "@BookId";
              bookIdParameter.Value = this.GetId();

              cmd.Parameters.Add(bookIdParameter);

              rdr = cmd.ExecuteReader();

              while (rdr.Read())
              {
            int authorId = rdr.GetInt32(0);
            string authorName = rdr.GetString(1);
            Author newAuthor = new Author (authorName, authorId);
            allAuthors.Add(newAuthor);
              }
              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return allAuthors;
        }
예제 #37
0
        public HomeModule()
        {
            Get["/"] = _ => {
                // List<Stylist> AllLists = Stylist.GetAll();
                return(View["index.cshtml"]);
            };
            Get["/books"] = _ => {
                var AllBooks = Book.GetAll();
                return(View["books.cshtml", AllBooks]);
            };
            Get["/patrons"] = _ => {
                List <Patron> allPatrons = Patron.GetAll();
                return(View ["patrons.cshtml", allPatrons]);
            };
            Get["/books/new"] = _ => {
                return(View["books_form.cshtml"]);
            };
            Post["/books/new"] = _ => {
                Book newBook = new Book(Request.Form["title"]);
                newBook.Save();
                Copy newCopy = new Copy(newBook.GetId(), Request.Form["number-of"], DateTime.Today);
                newCopy.Save();
                Author newAuthor = new Author(Request.Form["author"]);
                newAuthor.Save();
                newBook.AddAuthor(newAuthor);
                List <Author> allAuthors = Author.GetAll();
                List <Copy>   allCopies  = Copy.GetAll();
                List <Book>   allBooks   = Book.GetAll();
                return(View["success.cshtml"]);
            };
            Get["/books/search"] = _ => {
                return(View["books_search.cshtml"]);
            };
            Get["/books/found"] = _ => {
                List <Author> selectAuthors = new List <Author> {
                };
                List <Book> foundBooks      = new List <Book> {
                };
                string        authorName    = Request.Form["name"];
                List <Author> allAuthors    = Author.GetAll();
                foreach (Author listAuthor in allAuthors)
                {
                    if (listAuthor.GetName() == authorName)
                    {
                        selectAuthors.Add(listAuthor);
                    }
                }
                foreach (Author newAuthor in selectAuthors)
                {
                    foundBooks = newAuthor.GetBooks();
                }
                return(View["/books_found.cshtml", foundBooks]);
            };
            Get["/patrons/new"] = _ => {
                List <Patron> AllPatrons = Patron.GetAll();
                return(View["patrons_form.cshtml", AllPatrons]);
            };

            Post["/patrons/new"] = _ => {
                Patron newPatron = new Patron(Request.Form["name"]);
                newPatron.Save();
                return(View["success.cshtml"]);
            };

            Get["/books/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var           selectedBook        = Book.Find(parameters.id);
                List <Author> author = selectedBook.GetAuthors();
                selectedBook.AddAuthor(author[0]);
                var copies = selectedBook.GetCopies();
                model.Add("book", selectedBook);
                model.Add("author", author);
                model.Add("copies", copies);
                return(View["book.cshtml", model]);
            };

            Get["/patron/{id}"] = parameters => {
                Patron        selectedPatron = Patron.Find(parameters.id);
                List <object> model          = new List <object> {
                };
                List <Book> bookList         = Book.GetAll();
                model.Add(selectedPatron);
                model.Add(bookList);
                return(View["patron.cshtml", model]);
            };
            Get["patron/checkout/{id}"] = parameters => {
                List <Book> bookList  = new List <Book> {
                };
                Patron selectedPatron = Patron.Find(parameters.id);
                Book   newBook        = Book.Find(int.Parse(Request.Form("book")));
                Console.WriteLine(newBook);
                bookList.Add(newBook);
                return(View["patron_checkout.cshtml", bookList]);
            };
            // Patch["patron/checkout/{id}"] = parameters => {
            //   Patron selectedPatron = Patron.Find(parameters.id);
            //   Book newBook = Book.Find(Request.Form("book"));
            //   return View["success.cshtml"];
            // };

            Get["/book/edit/{id}"] = parameters => {
                Book selectedBook = Book.Find(parameters.id);
                return(View["book_edit.cshtml", selectedBook]);
            };
            Patch["/book/edit/{id}"] = parameters => {
                Book selectedBook = Book.Find(parameters.id);
                selectedBook.Update(Request.Form["book-title"]);
                return(View["success.cshtml"]);
            };
            Get["/patron/edit/{id}"] = parameters => {
                Patron selectedPatron = Patron.Find(parameters.id);
                return(View["patron_edit.cshtml", selectedPatron]);
            };
            Patch["/patron/edit/{id}"] = parameters => {
                Patron selectedPatron = Patron.Find(parameters.id);
                selectedPatron.Update(Request.Form["name"]);
                return(View["success.cshtml"]);
            };
            Get["/book/delete/{id}"] = parameters => {
                Book selectedBook = Book.Find(parameters.id);
                return(View["/book_delete.cshtml", selectedBook]);
            };
            Delete["book/delete/{id}"] = parameters => {
                Book selectedBook = Book.Find(parameters.id);
                selectedBook.Delete();
                return(View["success.cshtml"]);
            };
            Get["/patron/delete/{id}"] = parameters => {
                Patron selectedPatron = Patron.Find(parameters.id);
                return(View["/patron_delete.cshtml", selectedPatron]);
            };
            Delete["/patron/delete/{id}"] = parameters => {
                Patron selectedPatron = Patron.Find(parameters.id);
                selectedPatron.Delete();
                return(View["success.cshtml"]);
            };
        }