public static Boolean DeleteBook(TempBook book) { using (var context = new EFDtataAccessLibary.DataAccess.GewertsContext()) { var books = context.Böckers.First(a => a.Isbn == book.ISBN); while (context.FörfattareBöckers.Any(a => a.Isbn == book.ISBN)) { var authorBook = context.FörfattareBöckers.First(a => a.Isbn == book.ISBN); context.Remove(authorBook); context.SaveChanges(); } while (context.LagerSaldos.Any(b => b.Isbn == book.ISBN)) { var quantity = context.LagerSaldos.First(a => a.Isbn == book.ISBN); context.Remove(quantity); context.SaveChanges(); } context.Remove(books); context.SaveChanges(); return(true); } }
//Ta bort public static Boolean DeleteAuthor(int id) { using (var context = new EFDtataAccessLibary.DataAccess.GewertsContext()) { var author = context.Författares.FirstOrDefault(a => a.Id == id); context.Remove(author); context.SaveChanges(); return(true); } }