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.

105 lines
3.3 KiB

// See https://aka.ms/new-console-template for more information
using DBEntitiesWithStub;
using EntityFrameworkLib;
using Microsoft.EntityFrameworkCore;
using System.Net;
// 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 imageUrlSkinJaximus = "https://static1.millenium.org/entity_articles/9/18/19/@/1470587-jax-5-full-1.jpg",
imageUrlSkinBatonDivin = "https://static1.millenium.org/entity_articles/9/18/19/@/1470592-jax-10-article_image_d-1.jpg";
byte[] bytesJaximus, bytesBatonDIvin;
using (WebClient client = new WebClient())
{
bytesJaximus = client.DownloadData(imageUrlSkinJaximus);
bytesBatonDIvin = client.DownloadData(imageUrlSkinBatonDivin);
}
string base64ImageSkinJaximus = Convert.ToBase64String(bytesJaximus), base64ImageSkinBatonDivin = Convert.ToBase64String(bytesBatonDIvin);
LargeImageEntity imageSkinJaximus = new LargeImageEntity
{
Base64 = base64ImageSkinJaximus
};
LargeImageEntity imageSkinBatonDivin = new LargeImageEntity
{
Base64 = base64ImageSkinBatonDivin
};
List<SkinEntity> skins = new List<SkinEntity>
{
new SkinEntity
{
Name = "Jaximus",
Description = "Ce skin est sorti en Mai 2011",
Icon = "Icône de Jax",
Price = 975,
Image = imageSkinJaximus
},
new SkinEntity
{
Name = "Jax au Bâton divin",
Description = "Sorti en janvier 2018",
Icon = "Icône de Jax",
Price = 1350,
Image = imageSkinBatonDivin
}
};
List<CharacteristicEntity> characteristic = new List<CharacteristicEntity>
{
new CharacteristicEntity
{
Name = "Attack Speed",
Value = 2
},
new CharacteristicEntity
{
Name = "Armor",
Value = 35
}
};
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 = skins,
Characteristics = characteristic
};
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");
}
}
}