Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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();
     }
 }