示例#1
0
 public Book GetBookByID(int ID)
 {
     using (KartotekaModel db = new KartotekaModel())
     {
         BookModel book         = db.books.Find(ID);
         Book      BookToReturn = Mapper.Map <BookModel, Book>(book);
         return(BookToReturn);
     }
 }
示例#2
0
 public Author GetAuthorByID(int ID)
 {
     using (KartotekaModel db = new KartotekaModel())
     {
         AuthorModel author         = db.authors.Find(ID);
         Author      AuthorToReturn = Mapper.Map <AuthorModel, Author>(author);
         return(AuthorToReturn);
     }
 }
示例#3
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);
     }
 }
示例#4
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);
     }
 }
示例#5
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();
     }
 }
示例#6
0
 public List <Author> GetAllAuthors()
 {
     using (KartotekaModel db = new KartotekaModel())
     {
         List <Author> AllAuthors = new List <Author>();
         foreach (AuthorModel aut in db.authors)
         {
             AllAuthors.Add(GetAuthorByID(aut.Id));
         }
         return(AllAuthors);
     }
 }
示例#7
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();
     }
 }
示例#8
0
 public List <Book> GetAllBooks()
 {
     using (KartotekaModel db = new KartotekaModel())
     {
         List <Book> AllBooks = new List <Book>();
         foreach (BookModel bk in db.books)
         {
             AllBooks.Add(GetBookByID(bk.Id));
         }
         return(AllBooks);
     }
 }
示例#9
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();
     }
 }
示例#10
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();
     }
 }