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.

119 lines
3.3 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}");
}
}
// Test d'ajout d'image dans la BDD d'un Champion avec son image
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
};
string imageUrlSkin = "https://static1.millenium.org/entity_articles/9/18/19/@/1470587-jax-5-full-1.jpg";
byte[] bytes;
using (WebClient client = new WebClient())
{
bytes = client.DownloadData(imageUrlSkin);
}
string base64ImageSkin = Convert.ToBase64String(bytes);
LargeImageEntity imageSkin = new LargeImageEntity
{
Base64 = base64ImageSkin
};
SkinEntity skin = new SkinEntity
{
Name = "Jaximus",
Description = "Ce skin est sorti en Mai 2011",
Icon = "Icône de Jax",
Price = 975,
Image = imageSkin
};
using (var context = new SQLiteLolContext())
{
ChampionEntity jax = new ChampionEntity
{
Name = "Jax",
Icon = "Icône de 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.",
Class = Model.ChampionClass.Fighter,
Image = image,
Skins = new List<SkinEntity>() { skin }
};
context.Champions.Add(jax);
context.SaveChanges();
}
public class SQLiteLolContext : LolContext
{
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
if (!options.IsConfigured)
{
options.UseSqlite($"Data Source=projet.Champions.db");
}
}
}