You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.6 KiB

// See https://aka.ms/new-console-template for more information
using DBEntitiesWithStub;
using EntityFrameworkLib;
using Microsoft.EntityFrameworkCore;
using System.Net;
ChampionEntity darius = new ChampionEntity
{
Name = "Darius",
Icon = "icon Darius",
Bio = "bio Darius"
};
ChampionEntity garen = new ChampionEntity
{
Name = "Garen",
Icon = "icon Garen",
Bio = "bio Garen"
};
ChampionEntity veigar = new ChampionEntity
{
Name = "Veigar",
Icon = "icon Veigar",
Bio = "bio Veigar"
};
using (var context = new SQLiteLolContext())
{
Console.WriteLine("Creates and inserts new Champion");
/*context.Add(garen);
context.Add(darius);
context.Add(jax);
context.Add(veigar);*/
context.SaveChanges();
}
using (var context = new SQLiteLolContext())
{
foreach(var n in context.Champions)
{
Console.WriteLine($"{n.Name}");
}
context.SaveChanges();
}
using (LolContext db = new ChampionsDBEntitiesWithStub())
{
Console.WriteLine("Contenu de la base :");
foreach(var n in db.Champions)
{
Console.WriteLine($"\t {n.Name} - {n.Bio} - {n.Icon}");
}
}
string imageUrl = "https://ddragon.leagueoflegends.com/cdn/img/champion/splash/Jax_0.jpg";
byte[] imageBytes;
using (WebClient client = new WebClient())
{
imageBytes = client.DownloadData(imageUrl);
}
string base64Image = Convert.ToBase64String(imageBytes);
LargeImageEntity image = new LargeImageEntity
{
Base64 = base64Image
};
using (var context = new SQLiteLolContext())
{
ChampionEntity jax = new ChampionEntity
{
Name = "Jax",
Icon = "Icon Jax",
Bio = "Saijax Cail-Rynx Icath'un grandit à Icathia, une satrapie de l'empire shurimien. Dès son plus jeune âge, son père lui contait les récits de temps révolus, lorsque leur nation était encore indépendante et fière, avant que l'oppression de Shurima ne vienne les asservir. Il lui parlait des Kohari, les héros protecteurs d'Icathia et du Mage royal. Le Mage royal n'avait pas cédé face à la conquête shurimienne, mais lorsqu'il mourut au combat, ses protecteurs kohari le suivirent à l'aide d'un suicide rituel. L'empereur de Shurima exhiba les corps pourrissants des Kohari à la vue de tous. Le Mage royal, lui, fut empalé au-dessus des portes de la cité, ses os moisissant à l'air libre.",
Image = image
};
context.Add(jax);
context.SaveChanges();
}
public class SQLiteLolContext : LolContext
{
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
if (!options.IsConfigured)
{
options.UseSqlite($"Data Source=projet.Champions.db");
}
}
}