|
|
@ -0,0 +1,229 @@
|
|
|
|
|
|
|
|
using DbContextLib;
|
|
|
|
|
|
|
|
using StubbedContextLib;
|
|
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Program
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
using (LibraryContext db = new AthleteStubbedContext())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
AthletesTests(db);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Test d'ajout, de modification et de suppression
|
|
|
|
|
|
|
|
// AddUpdateDeleteOperations(db);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Test d'emprunt et de retour de livre
|
|
|
|
|
|
|
|
// BorrowAndReturnBook(db);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine($"Une erreur s'est produite : {ex.Message}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void AthletesTests(LibraryContext db)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine("Accès à tous les athletes :");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Affichage des livres
|
|
|
|
|
|
|
|
Console.WriteLine("Athletes :");
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var athlete in db.AthletesSet)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Accès à l'athlete d'id '2' :");
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------");
|
|
|
|
|
|
|
|
foreach (var athlete in db.AthletesSet.Where(a => a.IdAthlete == 2))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Accès à l'athlete de username 'Doe' :");
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------");
|
|
|
|
|
|
|
|
foreach (var athlete in db.AthletesSet.Where(a => a.Username == "Doe"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Accès à l'athlete de sexe 'F' :");
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------");
|
|
|
|
|
|
|
|
foreach (var athlete in db.AthletesSet.Where(a => a.Sexe == "F"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Accès à l'athlete de email 'bruce.lee@example.com' :");
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------");
|
|
|
|
|
|
|
|
foreach (var athlete in db.AthletesSet.Where(a => a.Email == "bruce.lee@example.com"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Accès à l'athlete de poids '90' :");
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------");
|
|
|
|
|
|
|
|
foreach (var athlete in db.AthletesSet.Where(a => a.Weight == 90))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Accès à l'athlete de taille '1.80' :");
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------");
|
|
|
|
|
|
|
|
foreach (var athlete in db.AthletesSet.Where(a => a.Lenght == 1.80))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ! A revoir !!
|
|
|
|
|
|
|
|
Console.WriteLine("Accès à l'athlete de date de naissance '01/01/2000' :");
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------");
|
|
|
|
|
|
|
|
foreach (var athlete in db.AthletesSet.Where(a => a.DateOfBirth == new DateTime()))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Accès à l'athlete de nom 'Martin' :");
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------");
|
|
|
|
|
|
|
|
foreach (var athlete in db.AthletesSet.Where(a => a.LastName == "Martin"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Accès à l'athlete de prénom 'Anna' :");
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------");
|
|
|
|
|
|
|
|
foreach (var athlete in db.AthletesSet.Where(a => a.FirstName == "Anna"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Accès à l'athlete de nom 'Brown' et de prénom 'Anna' :");
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------");
|
|
|
|
|
|
|
|
foreach (var athlete in db.AthletesSet.Where(a => a.LastName == "Brown" && a.FirstName == "Anna"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Accès au coachs :");
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------");
|
|
|
|
|
|
|
|
foreach (var athlete in db.AthletesSet.Where(a => a.IsCoach == true))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// /// <summary>
|
|
|
|
|
|
|
|
// /// Test d'ajout, de modification et de suppression de livres.
|
|
|
|
|
|
|
|
// /// </summary>
|
|
|
|
|
|
|
|
// /// <param name="db">Contexte de la base de données.</param>
|
|
|
|
|
|
|
|
// static void AddUpdateDeleteOperations(LibraryContext db)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// Console.WriteLine("Test d'ajout, de modification et de suppression :");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Ajout d'un nouveau livre
|
|
|
|
|
|
|
|
// var newBook = new BookEntity { Title = "Comment bien réussir son stage", Author = "Abdelfettah HASBANI", Isbn = "TheBest" };
|
|
|
|
|
|
|
|
// // par defaut, l'Id en long est égale à zero et se mettre par la BDD
|
|
|
|
|
|
|
|
// db.BooksSet.Add(newBook);
|
|
|
|
|
|
|
|
// db.SaveChanges();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Affichage des livres après ajout
|
|
|
|
|
|
|
|
// Console.WriteLine("Livres après ajout :");
|
|
|
|
|
|
|
|
// // .Include pour importer les personnes, ne pas le mettre si pas besoins de personnes
|
|
|
|
|
|
|
|
// foreach (var book in db.BooksSet.Include(b => b.Person))
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// Console.WriteLine($"\t{book.Id}, {book.Title}, {book.Author}, {book.Isbn}, {book.Person?.FirstName} {book.Person?.LastName}");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Modification du titre du nouveau livre
|
|
|
|
|
|
|
|
// newBook.Title = "Mes nouvelles dates de stage";
|
|
|
|
|
|
|
|
// db.SaveChanges();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Affichage des livres après modification
|
|
|
|
|
|
|
|
// Console.WriteLine("Livres après modification :");
|
|
|
|
|
|
|
|
// foreach (var book in db.BooksSet.Include(b => b.Person))
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// Console.WriteLine($"\t{book.Id}, {book.Title}, {book.Author}, {book.Isbn}, {book.Person?.FirstName} {book.Person?.LastName}");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Suppression du nouveau livre
|
|
|
|
|
|
|
|
// db.BooksSet.Remove(newBook);
|
|
|
|
|
|
|
|
// db.SaveChanges();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Affichage des livres après suppression
|
|
|
|
|
|
|
|
// Console.WriteLine("Livres après suppression :");
|
|
|
|
|
|
|
|
// foreach (var book in db.BooksSet.Include(b => b.Person))
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// Console.WriteLine($"\t{book.Id}, {book.Title}, {book.Author}, {book.Isbn}, {book.Person?.FirstName} {book.Person?.LastName}");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// /// <summary>
|
|
|
|
|
|
|
|
// /// Test d'emprunt et de retour de livre.
|
|
|
|
|
|
|
|
// /// </summary>
|
|
|
|
|
|
|
|
// /// <param name="db">Contexte de la base de données.</param>
|
|
|
|
|
|
|
|
// static void BorrowAndReturnBook(LibraryContext db)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// Console.WriteLine("Test d'emprunt et de retour de livre :");
|
|
|
|
|
|
|
|
// var person = db.PersonsSet.FirstOrDefault();
|
|
|
|
|
|
|
|
// var bookToBorrow = db.BooksSet.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Retour du livre 1
|
|
|
|
|
|
|
|
// if (bookToBorrow != null)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// bookToBorrow.Person = null;
|
|
|
|
|
|
|
|
// db.SaveChanges();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Affichage des livres après retour
|
|
|
|
|
|
|
|
// Console.WriteLine("Livres après retour :");
|
|
|
|
|
|
|
|
// foreach (var book in db.BooksSet.Include(b => b.Person))
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// Console.WriteLine($"\t{book.Id}, {book.Title}, {book.Author}, {book.Isbn}, {book.Person?.FirstName} {book.Person?.LastName}");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Emprunt d'un livre par une personne existante
|
|
|
|
|
|
|
|
// if (person != null && bookToBorrow != null)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// bookToBorrow.Person = person;
|
|
|
|
|
|
|
|
// db.SaveChanges();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Affichage des livres après emprunt
|
|
|
|
|
|
|
|
// Console.WriteLine("Livres après emprunt :");
|
|
|
|
|
|
|
|
// foreach (var book in db.BooksSet.Include(b => b.Person))
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// Console.WriteLine($"\t{book.Id}, {book.Title}, {book.Author}, {book.Isbn}, {book.Person?.FirstName} {book.Person?.LastName}");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|