Beispiel #1
0
 public bool AddAuthor(Author author)
 {
     using (LibraryEntities db = new LibraryEntities())
     {
         Author a = db.Authors.Where((x) =>
                                     x.FirstName + " " + x.LastName == author.
                                     FirstName + " " + author.LastName).FirstOrDefault();
         if (a == null)
         {
             db.Authors.Add(author);
             db.SaveChanges();
             MessageBox.Show("New aythor added: "
                             + author.LastName + " " + author.LastName);
             return(true);
         }
         else
         {
             MessageBox.Show(" Cancel the transaction.\n" +
                             " A author with this name:\n" +
                             author.LastName + " " + author.LastName +
                             "/n already exists in the library.");
             return(false);
         }
     }
 }
Beispiel #2
0
 public bool AddPublisher(Publisher publisher)
 {
     using (LibraryEntities db = new LibraryEntities())
     {
         Publisher a = db.Publishers.Where((x) =>
                                           x.PublisherName == publisher.
                                           PublisherName).FirstOrDefault();
         if (a == null)
         {
             db.Publishers.Add(publisher);
             db.SaveChanges();
             MessageBox.Show("New publisher added: " +
                             publisher.PublisherName);
             return(true);
         }
         else
         {
             MessageBox.Show(" Cancel the transaction.\n" +
                             " A publisher with this name:\n" +
                             publisher.PublisherName +
                             "/n already exists in the library.");
             return(false);
         }
     }
 }
Beispiel #3
0
        public bool EdBook(Book book)
        {
            using (LibraryEntities db = new LibraryEntities())
            {
                Book b = db.Books.Where((x) => x.Title ==
                                        book.Title).FirstOrDefault();
                if (b == null)
                {
                    db.Books.Where((x) =>
                                   x.Id == idBookSender).Single().Title = book.Title;
                    db.Books.Where((x) =>
                                   x.Id == idBookSender).Single().IdAuthor = book.IdAuthor;
                    db.Books.Where((x) =>
                                   x.Id == idBookSender).Single().IdPublisher = book.IdPublisher;
                    db.Books.Where((x) =>
                                   x.Id == idBookSender).Single().Pages = book.Pages;
                    db.Books.Where((x) =>
                                   x.Id == idBookSender).Single().Price = book.Price;

                    db.SaveChanges();
                    MessageBox.Show(
                        " The book with the name\n" + book.Title +
                        "\n was successfully edited.");
                    return(true);
                }
                else
                {
                    MessageBox.Show(" Cancel the transaction.\n" +
                                    " A book with this name:\n" + book.Title +
                                    "\n already exists in the library.");
                    return(false);
                }
            }
        }
Beispiel #4
0
 public bool AddBook(Book book)
 {
     using (LibraryEntities db = new LibraryEntities())
     {
         Book a = db.Books.Where((x) => x.Title ==
                                 book.Title).FirstOrDefault();
         if (a == null)
         {
             db.Books.Add(book);
             db.SaveChanges();
             idBookSender = book.Id;
             MessageBox.Show(" New book added:  " + book.Title);
             return(true);
         }
         else
         {
             MessageBox.Show(" Cancel the transaction.\n" +
                             " A book with this name:\n" + book.Title +
                             "\n already exists in the library.");
             return(false);
         }
     }
 }