Esempio n. 1
0
 public IEnumerable <Book> getAll()
 {
     using (var ctx = new BokhyllanBDBContext())
     {
         return(ctx.Books.AsNoTracking().ToList());
     }
 }
Esempio n. 2
0
 public void DeleteBook(int id)
 {
     using (var ctx = new BokhyllanBDBContext())
     {
         var result = ctx.Books.Where(b => b.Id == id).FirstOrDefault();
         ctx.Books.Remove(result);
         ctx.SaveChanges();
     }
 }
Esempio n. 3
0
 public void CreateNewBook()
 {
     using (var ctx = new BokhyllanBDBContext())
     {
         var newBook = new Book {
             Title = "New Title", Author = "New Author"
         };
         ctx.Books.Add(newBook);
         ctx.SaveChanges();
     }
 }
Esempio n. 4
0
 public void UpdateBook(int id, string title, string author, string description)
 {
     using (var ctx = new BokhyllanBDBContext())
     {
         var result = ctx.Books.Where(b => b.Id == id).FirstOrDefault();
         result.Title       = title;
         result.Author      = author;
         result.Description = description;
         ctx.SaveChanges();
     }
 }