|
|
@ -2,26 +2,32 @@
|
|
|
|
using Entities;
|
|
|
|
using Entities;
|
|
|
|
using DbContextLib;
|
|
|
|
using DbContextLib;
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Storage;
|
|
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
|
|
// See https://aka.ms/new-console-template for more information
|
|
|
|
// See https://aka.ms/new-console-template for more information
|
|
|
|
Console.WriteLine("Hello, World!");
|
|
|
|
Console.WriteLine("Hello, World!");
|
|
|
|
|
|
|
|
|
|
|
|
using (var context = new LibraryContext())
|
|
|
|
using (var context = new LibraryContext())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
BookEntity chewie = new BookEntity("B3", "test1", "test1");
|
|
|
|
context.Database.EnsureCreated();
|
|
|
|
BookEntity yoda = new BookEntity ("B4", "test2", "test2");
|
|
|
|
|
|
|
|
BookEntity ewok = new BookEntity ("mistake", "test3", "test3");
|
|
|
|
|
|
|
|
BookEntity the100 = new BookEntity("the100", "test4", "test4");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.BooksSet.Add(chewie);
|
|
|
|
PersonEntity p1 = new PersonEntity() { FirstName = "Tom", LastName = "Rambeau" };
|
|
|
|
context.BooksSet.Add(yoda);
|
|
|
|
PersonEntity p2 = new PersonEntity() { FirstName = "Erwan", LastName = "Manager" };
|
|
|
|
context.BooksSet.Add(ewok);
|
|
|
|
BookEntity chewie = new BookEntity() { Title = "mistake", Author = "test1", Isbn ="test1"};
|
|
|
|
context.BooksSet.Add(the100);
|
|
|
|
BookEntity the100 = new BookEntity() { Title = "the100", Author = "test4", Isbn = "test4", Owner = p1 };
|
|
|
|
|
|
|
|
BookEntity GOT = new BookEntity() { Title = "GOT", Author = "lastTest", Isbn = "lastTest"};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.Add(p1);
|
|
|
|
|
|
|
|
context.Add(p2);
|
|
|
|
|
|
|
|
context.Add(chewie);
|
|
|
|
|
|
|
|
context.Add(GOT);
|
|
|
|
|
|
|
|
context.Add(the100);
|
|
|
|
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
context.SaveChanges();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (var context = new LibraryContext())
|
|
|
|
using (var context = new LibraryContext())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
foreach (var n in context.BooksSet)
|
|
|
|
foreach (var n in context.BooksSet)
|
|
|
@ -48,4 +54,82 @@ using (var context = new LibraryContext())
|
|
|
|
context.Remove(impostor);
|
|
|
|
context.Remove(impostor);
|
|
|
|
context.SaveChanges();
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (var context = new LibraryContext())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine("All people");
|
|
|
|
|
|
|
|
var people = context.PersonSet;
|
|
|
|
|
|
|
|
foreach(var p in people)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine($"firstname: {p.FirstName}, lastname: {p.LastName}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//emprunt
|
|
|
|
|
|
|
|
using (var context = new LibraryContext())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var books = context.BooksSet;
|
|
|
|
|
|
|
|
foreach(var book in books)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (book.Owner == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
book.Owner = context.PersonSet.Where(b => b.FirstName.StartsWith("E")).Include(b => b.Books).First();
|
|
|
|
|
|
|
|
Console.WriteLine($" nouveau propriétaire du livre: {book.Owner.FirstName}");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Rendu
|
|
|
|
|
|
|
|
using (var context = new LibraryContext())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var books = context.BooksSet;
|
|
|
|
|
|
|
|
if (books != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var book in books)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//Console.WriteLine(book.Owner.FirstName);
|
|
|
|
|
|
|
|
if (book.Owner != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine($" propriétaire du livre avant rendu : {book.Owner.FirstName}");
|
|
|
|
|
|
|
|
book.Owner = null;
|
|
|
|
|
|
|
|
Console.WriteLine("propriétaire a rendu le libre");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine("livre sans propriétaire" + book.Title);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//DeleteAllItem
|
|
|
|
|
|
|
|
using (var context = new LibraryContext())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var allBooks = context.BooksSet;
|
|
|
|
|
|
|
|
if ( allBooks != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var book in allBooks)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
context.BooksSet.Remove(book);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var allPeople = context.PersonSet;
|
|
|
|
|
|
|
|
if (allBooks != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var person in allPeople)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
context.PersonSet.Remove(person);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
}
|
|
|
|
}
|