예제 #1
0
 public int RegisterNewAuthor(Author NewAuthor)
 {
     using (KartotekaModel db = new KartotekaModel())
     {
         AuthorModel authormodel = Mapper.Map <Author, AuthorModel>(NewAuthor);
         db.authors.Add(authormodel);
         db.SaveChanges();
         return(authormodel.Id);
     }
 }
예제 #2
0
 public int RegisterNewBook(Book NewBook)
 {
     using (KartotekaModel db = new KartotekaModel())
     {
         BookModel bookmodel = Mapper.Map <Book, BookModel>(NewBook);
         db.books.Add(bookmodel);
         db.SaveChanges();
         return(bookmodel.Id);
     }
 }
예제 #3
0
 public void DeleteBook(int ID)
 {
     using (KartotekaModel db = new KartotekaModel())
     {
         BookModel book = db.books.Find(ID);
         if (book != null)
         {
             db.books.Remove(book);
         }
         db.SaveChanges();
     }
 }
예제 #4
0
 public void DeleteAuthor(int ID)
 {
     using (KartotekaModel db = new KartotekaModel())
     {
         AuthorModel author = db.authors.Find(ID);
         if (author != null)
         {
             db.authors.Remove(author);
         }
         db.SaveChanges();
     }
 }
예제 #5
0
 public void EditBook(Book BookToEdit)
 {
     using (KartotekaModel db = new KartotekaModel())
     {
         BookModel book = db.books.Find(BookToEdit.Id);
         book.Description = BookToEdit.Description;
         book.Name        = BookToEdit.Name;
         book.Year        = BookToEdit.Year;
         book.authors.Clear();
         if (BookToEdit.authors != null)
         {
             foreach (Author author in BookToEdit.authors)
             {
                 book.authors.Add(db.authors.Find(author.Id));
             }
         }
         db.SaveChanges();
     }
 }
예제 #6
0
 public void EditAuthor(Author AuthorToEdit)
 {
     using (KartotekaModel db = new KartotekaModel())
     {
         AuthorModel author = db.authors.Find(AuthorToEdit.Id);
         author.FirstName  = AuthorToEdit.FirstName;
         author.SecondName = AuthorToEdit.SecondName;
         author.LastName   = AuthorToEdit.LastName;
         author.books.Clear();
         if (AuthorToEdit.books != null)
         {
             foreach (Book book in AuthorToEdit.books)
             {
                 author.books.Add(db.books.Find(book.Id));
             }
         }
         db.SaveChanges();
     }
 }