DbSet de toutes les tables dont il y a besoin

pull/1/head
Théo DUPIN 2 years ago
parent d7d65965ce
commit 0c02ac49f5

@ -7,6 +7,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Web_Api\Web_Api.csproj" />
</ItemGroup>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Key0" value="0" />
<add key="Key1" value="1" />
<add key="Key2" value="2" />
</appSettings>
</configuration>

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
</ItemGroup>
</Project>

@ -0,0 +1,26 @@
using System;
using System.Configuration;
using System.Collections.Specialized;
namespace ConsoleConfig
{
class Program
{
static void Main(string[] args)
{
string sAttr;
// Read a particular key from the config file
sAttr = ConfigurationManager.AppSettings.Get("Key0");
Console.WriteLine("The value of Key0: " + sAttr);
// Read all the keys from the config file
NameValueCollection sAll;
sAll = ConfigurationManager.AppSettings;
foreach (string s in sAll.AllKeys)
Console.WriteLine("Key: " + s + " Value: " + sAll.Get(s));
Console.ReadLine();
}
}
}

@ -9,6 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.2">
<PrivateAssets>all</PrivateAssets>

@ -47,11 +47,7 @@ namespace DBDataManager
async Task<IEnumerable<Champion?>> IGenericDataManager<Champion?>.GetItems(int index, int count, string? orderingPropertyName, bool descending)
{
IEnumerable<Champion> champions = context.Champions.Skip(index * count)
.Take(count)
.OrderBy(champions => orderingPropertyName)
.Select(champions => champions.toModel());
return champions;
return (IEnumerable<Champion?>)context.Champions.GetItemsWithFilterAndOrdering(c => true, index, count, orderingPropertyName, descending);
}
private Func<Champion, string, bool> filterByCharacteristic = (champ, charName) => champ.Characteristics.Keys.Any(k => k.Contains(charName, StringComparison.InvariantCultureIgnoreCase));
@ -126,8 +122,8 @@ namespace DBDataManager
Task<Champion?> IGenericDataManager<Champion?>.UpdateItem(Champion? oldItem, Champion? newItem)
{
throw new NotImplementedException();
throw new Exception();
}
//=> context.Champions.toPocos().UpdateItem(oldItem, newItem);
//=> (IList<Champion>)context.Champions.toPocos().UpdateItem(oldItem, newItem);
}
}

@ -6,6 +6,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EntityFrameworkLib\EntityFrameworkLib.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />

@ -0,0 +1,76 @@
using EntityFrameworkLib;
using EntityFrameworkLib.Mappers;
using Model;
using Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DBDataManager
{
public class DBSkinManager : ISkinsManager
{
private readonly LolContext context;
public DBSkinManager()
{
}
public DBSkinManager(LolContext context)
{
this.context = context;
}
async Task<Skin?> IGenericDataManager<Skin?>.AddItem(Skin? item)
{
if(item == null)
{
return null;
}
var additem = await context.AddAsync<Skin?>(item);
await context.SaveChangesAsync();
return additem.Entity;
}
async Task<bool> IGenericDataManager<Skin?>.DeleteItem(Skin? item)
{
if(item == null)
{
return false;
}
context.Remove<Skin>(item);
await context.SaveChangesAsync();
return true;
}
Task<IEnumerable<Skin?>> IGenericDataManager<Skin?>.GetItems(int index, int count, string? orderingPropertyName, bool descending)
=> context.Skins.toPocos().GetItemsWithFilterAndOrdering(s => true, index, count, orderingPropertyName, descending);
private static Func<Skin, Champion?, bool> filterByChampion = (skin, champion) => champion != null && skin.Champion.Equals(champion!);
Task<IEnumerable<Skin?>> ISkinsManager.GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName, bool descending)
=> context.Skins.toPocos().GetItemsWithFilterAndOrdering(skin => filterByChampion(skin, champion), index, count, orderingPropertyName, descending);
private static Func<Skin, string, bool> filterByName = (skin, substring) => skin.Name.Contains(substring, StringComparison.InvariantCultureIgnoreCase);
Task<IEnumerable<Skin?>> IGenericDataManager<Skin?>.GetItemsByName(string substring, int index, int count, string? orderingPropertyName, bool descending)
=> context.Skins.toPocos().GetItemsWithFilterAndOrdering(skin => filterByName(skin, substring), index, count, orderingPropertyName, descending);
Task<int> IGenericDataManager<Skin?>.GetNbItems()
=> context.Skins.GetNbItemsWithFilter(s => true);
Task<int> ISkinsManager.GetNbItemsByChampion(Champion? champion)
=> context.Skins.toPocos().GetNbItemsWithFilter(skin => filterByChampion(skin, champion));
Task<int> IGenericDataManager<Skin?>.GetNbItemsByName(string substring)
=> context.Skins.toPocos().GetNbItemsWithFilter(skin => filterByName(skin, substring));
Task<Skin?> IGenericDataManager<Skin?>.UpdateItem(Skin? oldItem, Skin? newItem)
{
throw new Exception();
}
// => (IList<Champion>)context.Skins.toPocos().UpdateItem(oldItem, newItem);
}
}

@ -38,23 +38,33 @@ namespace DBDataManager
return result;
}
public static IEnumerable<Skin> toPocos(this IEnumerable<SkinEntity> skins)
{
List<Skin> result = new List<Skin>();
foreach(SkinEntity skin in skins)
{
result.Add(skin.toModel());
}
return result;
}
internal static Task<int> GetNbItemsWithFilter<T>(this IEnumerable<T> collection, Func<T, bool> filter)
{
return Task.FromResult(collection.Count(item => filter(item)));
}
internal static Task<T?> UpdateItem<T>(this IList<T> collection, T? oldItem, T? newItem)
internal static Task<Champion?> UpdateItem<Champion>(this IList<Champion> collection, Champion? oldItem, Champion? newItem)
{
if (oldItem == null || newItem == null) return Task.FromResult<T?>(default(T));
if (oldItem == null || newItem == null) return Task.FromResult<Champion?>(default(Champion));
if (!collection.Contains(oldItem))
{
return Task.FromResult<T?>(default(T));
return Task.FromResult<Champion?>(default(Champion));
}
collection.Remove(oldItem!);
collection.Add(newItem!);
return Task.FromResult<T?>(newItem);
return Task.FromResult<Champion?>(newItem);
}
}
}

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
</ItemGroup>

@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Design;
@ -11,11 +13,20 @@ namespace EntityFrameworkLib
{
public class ChampionEntity
{
public int Id { get; set; }
[Key]
[MaxLength(256)]
public string Name { get; set; }
[MaxLength(500)]
public string Bio { get; set; }
public string Icon { get; set; }
//public LargeImage Image { get; set; }
//public ChampionClass Class { get; set; }
[Required]
public ChampionClass Class { get; set; }
public ICollection<SkillEntity> Skills { get; set; }
public ICollection<CharacteristicEntity> Characteristics { get; set; }
public ICollection<RunePageEntity> RunePages { get; set; }
public int? ImageId { get; set; }
[ForeignKey("ImageId")]
public LargeImageEntity? Image { get; set; }
}
}

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameworkLib
{
public class CharacteristicEntity
{
[Key]
[MaxLength(256)]
public string Name { get; set; }
[Required]
public int Value { get; set; }
[Required]
public string ChampionForeignKey { get; set; }
[ForeignKey("ChampionForeignKey")]
public ChampionEntity Champion { get; set; }
}
}

@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.2">
<PrivateAssets>all</PrivateAssets>

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameworkLib
{
public enum EnumChampionClass
{
Unknown,
Assassin,
Fighter,
Mage,
Marksman,
Support,
Tank
}
}

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameworkLib
{
[Table("t_LargeImage")]
public class LargeImageEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required]
public string Base64 { get; set; }
}
}

@ -8,8 +8,15 @@ namespace EntityFrameworkLib
public class LolContext : DbContext
{
public DbSet<ChampionEntity> Champions { get; set; }
public DbSet<CharacteristicEntity> Characteristics { get; set; }
public DbSet<SkinEntity> Skins { get; set; }
public DbSet<SkillEntity> Skills { get; set; }
public DbSet<LargeImageEntity> Images { get; set; }
public DbSet<RuneEntity> Runes { get; set; }
public DbSet<RunePageEntity> RunesPage { get; set; }
public DbSet<RunePageRuneEntity> RunePageRunes { get; set; }
public LolContext() { }
public LolContext(DbContextOptions<LolContext> options)
public LolContext(DbContextOptions<LolContext> options)
: base(options) { }
protected override void OnConfiguring(DbContextOptionsBuilder options)
@ -20,13 +27,17 @@ namespace EntityFrameworkLib
}
}
/*protected override void OnModelCreating(ModelBuilder modelBuilder)
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<LargeImageEntity>().Property(l => l.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<CharacteristicEntity>().HasKey(c => new { c.Name, c.ChampionForeignKey });
modelBuilder.Entity<RunePageRuneEntity>().HasKey(c => new { c.RunePageName, c.RuneName });
modelBuilder.Entity<ChampionEntity>()
.Property(c => c.Image)
.IsRequired(false);
modelBuilder.Entity<LargeImage>()
.HasKey(li => li.Base64);
}*/
.HasMany(c => c.RunePages)
.WithMany(r => r.Champions);
}
}
}

@ -9,21 +9,43 @@ namespace EntityFrameworkLib.Mappers
{
public static class ChampionChanger
{
public static Champion toModel(this ChampionEntity championEntity)
public static ChampionEntity toEntity(this Champion champion, LolContext context)
{
return new Champion(championEntity.Name, championEntity.Bio, championEntity.Icon /*championEntity.Image, championEntity.Class*/);
ChampionEntity? championEntity = context.Champions.Find(champion.Name);
if (championEntity == null)
{
championEntity = new()
{
Name = champion.Name,
Bio = champion.Bio,
Icon = champion.Icon,
Class = champion.Class,
Image = new() { Base64 = champion.Image.Base64 }
};
championEntity.Skills = champion.Skills.Select(s => s.toEntity(championEntity, context)).ToList();
championEntity.Characteristics = champion.Characteristics.Select(c => c.toEntity(championEntity, context)).ToList();
}
return championEntity;
}
public static ChampionEntity toEntity(this Champion champion)
public static Champion toModel(this ChampionEntity championEntity)
{
return new ChampionEntity
var champion = new Champion(championEntity.Name, championEntity.Class, championEntity.Icon, "", championEntity.Bio);
if(championEntity.Skills != null)
{
foreach(var s in championEntity.Skills)
{
champion.AddSkill(s.toModel());
}
}
if(championEntity.Characteristics != null)
{
Name = champion.Name,
Bio = champion.Bio,
Icon = champion.Icon,
//Image = champion.Image,
//Class = champion.Class,
};
foreach(var c in championEntity.Characteristics)
{
champion.AddCharacteristics(c.toModel());
}
}
return champion;
}
}
}

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameworkLib.Mappers
{
public static class CharacteristicChanger
{
public static CharacteristicEntity toEntity(this KeyValuePair<string, int> item, ChampionEntity championEntity, LolContext context)
{
var characteristicEntity = new CharacteristicEntity();
if(characteristicEntity == null)
{
return new()
{
Name = item.Key,
Value = item.Value,
ChampionForeignKey = championEntity.Name
};
}
return characteristicEntity;
}
public static Tuple<string, int> toModel(this CharacteristicEntity characteristicEntity)
=> new(characteristicEntity.Name, characteristicEntity.Value);
}
}

@ -0,0 +1,28 @@
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameworkLib.Mappers
{
public static class LargeImageChanger
{
public static int Id { get; private set; }
public static LargeImage toModel(this LargeImageEntity imageEntity)
{
return new LargeImage(imageEntity.Base64) { Id = imageEntity.Id };
}
public static LargeImageEntity toEntity(this LargeImage image)
{
return new LargeImageEntity
{
Id = image.Id,
Base64 = image.Base64
};
}
}
}

@ -0,0 +1,33 @@
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameworkLib.Mappers
{
public static class SkillChanger
{
public static SkillEntity toEntity(this Skill skill, ChampionEntity championEntity, LolContext context)
{
var skillEntity = context.Skills.Find(skill.Name);
if (skillEntity == null)
{
return new()
{
Name = skill.Name,
Description = skill.Description,
Type = skill.Type,
Champions = new List<ChampionEntity>() { championEntity }
};
}
skillEntity!.Champions?.Add(championEntity);
return skillEntity;
}
public static Skill toModel(this SkillEntity skillEntity)
=> new(skillEntity.Name, skillEntity.Type, skillEntity.Description);
}
}

@ -0,0 +1,30 @@
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameworkLib.Mappers
{
public static class SkinChanger
{
public static Skin toModel(this SkinEntity skinEntity)
{
return new Skin(skinEntity.Name, skinEntity.Description, skinEntity.Icon, skinEntity.Price /*championEntity.Image, championEntity.Class*/);
}
public static SkinEntity toEntity(this Skin skin)
{
return new SkinEntity
{
Name = skin.Name,
Description = skin.Description,
Icon = skin.Icon,
Price = skin.Price
//Image = champion.Image,
//Class = champion.Class,
};
}
}
}

@ -1,47 +0,0 @@
// <auto-generated />
using EntityFrameworkLib;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFrameworkLib.Migrations
{
[DbContext(typeof(LolContext))]
[Migration("20230201082358_myFirstMigration")]
partial class myFirstMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFrameworkLib.ChampionEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Bio")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Champions");
});
#pragma warning restore 612, 618
}
}
}

@ -1,36 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFrameworkLib.Migrations
{
/// <inheritdoc />
public partial class myFirstMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Champions",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
Bio = table.Column<string>(type: "TEXT", nullable: false),
Icon = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Champions", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Champions");
}
}
}

@ -1,47 +0,0 @@
// <auto-generated />
using EntityFrameworkLib;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFrameworkLib.Migrations
{
[DbContext(typeof(LolContext))]
[Migration("20230201084126_projet_SQLite")]
partial class projetSQLite
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFrameworkLib.ChampionEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Bio")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Champions");
});
#pragma warning restore 612, 618
}
}
}

@ -1,22 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFrameworkLib.Migrations
{
/// <inheritdoc />
public partial class projetSQLite : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

@ -1,47 +0,0 @@
// <auto-generated />
using EntityFrameworkLib;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFrameworkLib.Migrations
{
[DbContext(typeof(LolContext))]
[Migration("20230201103421_migration_projet")]
partial class migrationprojet
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFrameworkLib.ChampionEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Bio")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Champions");
});
#pragma warning restore 612, 618
}
}
}

@ -1,22 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFrameworkLib.Migrations
{
/// <inheritdoc />
public partial class migrationprojet : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

@ -0,0 +1,333 @@
// <auto-generated />
using System;
using EntityFrameworkLib;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFrameworkLib.Migrations
{
[DbContext(typeof(LolContext))]
[Migration("20230325144614_AllMigrations")]
partial class AllMigrations
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("ChampionEntityRunePageEntity", b =>
{
b.Property<string>("ChampionsName")
.HasColumnType("TEXT");
b.Property<string>("RunePagesName")
.HasColumnType("TEXT");
b.HasKey("ChampionsName", "RunePagesName");
b.HasIndex("RunePagesName");
b.ToTable("ChampionEntityRunePageEntity");
});
modelBuilder.Entity("ChampionEntitySkillEntity", b =>
{
b.Property<string>("ChampionsName")
.HasColumnType("TEXT");
b.Property<string>("SkillsName")
.HasColumnType("TEXT");
b.HasKey("ChampionsName", "SkillsName");
b.HasIndex("SkillsName");
b.ToTable("ChampionEntitySkillEntity");
});
modelBuilder.Entity("EntityFrameworkLib.ChampionEntity", b =>
{
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("Bio")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<int>("Class")
.HasColumnType("INTEGER");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int?>("ImageId")
.HasColumnType("INTEGER");
b.HasKey("Name");
b.HasIndex("ImageId");
b.ToTable("Champions");
});
modelBuilder.Entity("EntityFrameworkLib.CharacteristicEntity", b =>
{
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("ChampionForeignKey")
.HasColumnType("TEXT");
b.Property<int>("Value")
.HasColumnType("INTEGER");
b.HasKey("Name", "ChampionForeignKey");
b.HasIndex("ChampionForeignKey");
b.ToTable("Characteristics");
});
modelBuilder.Entity("EntityFrameworkLib.LargeImageEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Base64")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("t_LargeImage");
});
modelBuilder.Entity("EntityFrameworkLib.RuneEntity", b =>
{
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<int?>("ImageId")
.HasColumnType("INTEGER");
b.Property<int>("RuneFamily")
.HasColumnType("INTEGER");
b.HasKey("Name");
b.HasIndex("ImageId");
b.ToTable("Runes");
});
modelBuilder.Entity("EntityFrameworkLib.RunePageEntity", b =>
{
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("RunesPage");
});
modelBuilder.Entity("EntityFrameworkLib.RunePageRuneEntity", b =>
{
b.Property<string>("RunePageName")
.HasColumnType("TEXT");
b.Property<string>("RuneName")
.HasColumnType("TEXT");
b.Property<int>("Category")
.HasColumnType("INTEGER");
b.HasKey("RunePageName", "RuneName");
b.HasIndex("RuneName");
b.ToTable("RunePageRunes");
});
modelBuilder.Entity("EntityFrameworkLib.SkillEntity", b =>
{
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("Name");
b.ToTable("Skills");
});
modelBuilder.Entity("EntityFrameworkLib.SkinEntity", b =>
{
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("ChampionForeignKey")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int?>("ImageId")
.HasColumnType("INTEGER");
b.Property<float>("Price")
.HasColumnType("REAL");
b.HasKey("Name");
b.HasIndex("ChampionForeignKey");
b.HasIndex("ImageId");
b.ToTable("Skins");
});
modelBuilder.Entity("ChampionEntityRunePageEntity", b =>
{
b.HasOne("EntityFrameworkLib.ChampionEntity", null)
.WithMany()
.HasForeignKey("ChampionsName")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("EntityFrameworkLib.RunePageEntity", null)
.WithMany()
.HasForeignKey("RunePagesName")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("ChampionEntitySkillEntity", b =>
{
b.HasOne("EntityFrameworkLib.ChampionEntity", null)
.WithMany()
.HasForeignKey("ChampionsName")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("EntityFrameworkLib.SkillEntity", null)
.WithMany()
.HasForeignKey("SkillsName")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("EntityFrameworkLib.ChampionEntity", b =>
{
b.HasOne("EntityFrameworkLib.LargeImageEntity", "Image")
.WithMany()
.HasForeignKey("ImageId");
b.Navigation("Image");
});
modelBuilder.Entity("EntityFrameworkLib.CharacteristicEntity", b =>
{
b.HasOne("EntityFrameworkLib.ChampionEntity", "Champion")
.WithMany("Characteristics")
.HasForeignKey("ChampionForeignKey")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Champion");
});
modelBuilder.Entity("EntityFrameworkLib.RuneEntity", b =>
{
b.HasOne("EntityFrameworkLib.LargeImageEntity", "Image")
.WithMany()
.HasForeignKey("ImageId");
b.Navigation("Image");
});
modelBuilder.Entity("EntityFrameworkLib.RunePageRuneEntity", b =>
{
b.HasOne("EntityFrameworkLib.RuneEntity", "Rune")
.WithMany("RunePages")
.HasForeignKey("RuneName")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("EntityFrameworkLib.RunePageEntity", "RunePage")
.WithMany("Runes")
.HasForeignKey("RunePageName")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Rune");
b.Navigation("RunePage");
});
modelBuilder.Entity("EntityFrameworkLib.SkinEntity", b =>
{
b.HasOne("EntityFrameworkLib.ChampionEntity", "Champion")
.WithMany()
.HasForeignKey("ChampionForeignKey")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("EntityFrameworkLib.LargeImageEntity", "Image")
.WithMany()
.HasForeignKey("ImageId");
b.Navigation("Champion");
b.Navigation("Image");
});
modelBuilder.Entity("EntityFrameworkLib.ChampionEntity", b =>
{
b.Navigation("Characteristics");
});
modelBuilder.Entity("EntityFrameworkLib.RuneEntity", b =>
{
b.Navigation("RunePages");
});
modelBuilder.Entity("EntityFrameworkLib.RunePageEntity", b =>
{
b.Navigation("Runes");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,283 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFrameworkLib.Migrations
{
/// <inheritdoc />
public partial class AllMigrations : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "RunesPage",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_RunesPage", x => x.Name);
});
migrationBuilder.CreateTable(
name: "Skills",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false),
Description = table.Column<string>(type: "TEXT", maxLength: 500, nullable: false),
Type = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Skills", x => x.Name);
});
migrationBuilder.CreateTable(
name: "t_LargeImage",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Base64 = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_t_LargeImage", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Champions",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false),
Bio = table.Column<string>(type: "TEXT", maxLength: 500, nullable: false),
Icon = table.Column<string>(type: "TEXT", nullable: false),
Class = table.Column<int>(type: "INTEGER", nullable: false),
ImageId = table.Column<int>(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Champions", x => x.Name);
table.ForeignKey(
name: "FK_Champions_t_LargeImage_ImageId",
column: x => x.ImageId,
principalTable: "t_LargeImage",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Runes",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false),
Description = table.Column<string>(type: "TEXT", maxLength: 500, nullable: false),
RuneFamily = table.Column<int>(type: "INTEGER", nullable: false),
ImageId = table.Column<int>(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Runes", x => x.Name);
table.ForeignKey(
name: "FK_Runes_t_LargeImage_ImageId",
column: x => x.ImageId,
principalTable: "t_LargeImage",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "ChampionEntityRunePageEntity",
columns: table => new
{
ChampionsName = table.Column<string>(type: "TEXT", nullable: false),
RunePagesName = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ChampionEntityRunePageEntity", x => new { x.ChampionsName, x.RunePagesName });
table.ForeignKey(
name: "FK_ChampionEntityRunePageEntity_Champions_ChampionsName",
column: x => x.ChampionsName,
principalTable: "Champions",
principalColumn: "Name",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ChampionEntityRunePageEntity_RunesPage_RunePagesName",
column: x => x.RunePagesName,
principalTable: "RunesPage",
principalColumn: "Name",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ChampionEntitySkillEntity",
columns: table => new
{
ChampionsName = table.Column<string>(type: "TEXT", nullable: false),
SkillsName = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ChampionEntitySkillEntity", x => new { x.ChampionsName, x.SkillsName });
table.ForeignKey(
name: "FK_ChampionEntitySkillEntity_Champions_ChampionsName",
column: x => x.ChampionsName,
principalTable: "Champions",
principalColumn: "Name",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ChampionEntitySkillEntity_Skills_SkillsName",
column: x => x.SkillsName,
principalTable: "Skills",
principalColumn: "Name",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Characteristics",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false),
ChampionForeignKey = table.Column<string>(type: "TEXT", nullable: false),
Value = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Characteristics", x => new { x.Name, x.ChampionForeignKey });
table.ForeignKey(
name: "FK_Characteristics_Champions_ChampionForeignKey",
column: x => x.ChampionForeignKey,
principalTable: "Champions",
principalColumn: "Name",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Skins",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false),
Description = table.Column<string>(type: "TEXT", maxLength: 500, nullable: false),
Icon = table.Column<string>(type: "TEXT", nullable: false),
Price = table.Column<float>(type: "REAL", nullable: false),
ChampionForeignKey = table.Column<string>(type: "TEXT", nullable: false),
ImageId = table.Column<int>(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Skins", x => x.Name);
table.ForeignKey(
name: "FK_Skins_Champions_ChampionForeignKey",
column: x => x.ChampionForeignKey,
principalTable: "Champions",
principalColumn: "Name",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Skins_t_LargeImage_ImageId",
column: x => x.ImageId,
principalTable: "t_LargeImage",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "RunePageRunes",
columns: table => new
{
RuneName = table.Column<string>(type: "TEXT", nullable: false),
RunePageName = table.Column<string>(type: "TEXT", nullable: false),
Category = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_RunePageRunes", x => new { x.RunePageName, x.RuneName });
table.ForeignKey(
name: "FK_RunePageRunes_RunesPage_RunePageName",
column: x => x.RunePageName,
principalTable: "RunesPage",
principalColumn: "Name",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_RunePageRunes_Runes_RuneName",
column: x => x.RuneName,
principalTable: "Runes",
principalColumn: "Name",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_ChampionEntityRunePageEntity_RunePagesName",
table: "ChampionEntityRunePageEntity",
column: "RunePagesName");
migrationBuilder.CreateIndex(
name: "IX_ChampionEntitySkillEntity_SkillsName",
table: "ChampionEntitySkillEntity",
column: "SkillsName");
migrationBuilder.CreateIndex(
name: "IX_Champions_ImageId",
table: "Champions",
column: "ImageId");
migrationBuilder.CreateIndex(
name: "IX_Characteristics_ChampionForeignKey",
table: "Characteristics",
column: "ChampionForeignKey");
migrationBuilder.CreateIndex(
name: "IX_RunePageRunes_RuneName",
table: "RunePageRunes",
column: "RuneName");
migrationBuilder.CreateIndex(
name: "IX_Runes_ImageId",
table: "Runes",
column: "ImageId");
migrationBuilder.CreateIndex(
name: "IX_Skins_ChampionForeignKey",
table: "Skins",
column: "ChampionForeignKey");
migrationBuilder.CreateIndex(
name: "IX_Skins_ImageId",
table: "Skins",
column: "ImageId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ChampionEntityRunePageEntity");
migrationBuilder.DropTable(
name: "ChampionEntitySkillEntity");
migrationBuilder.DropTable(
name: "Characteristics");
migrationBuilder.DropTable(
name: "RunePageRunes");
migrationBuilder.DropTable(
name: "Skins");
migrationBuilder.DropTable(
name: "Skills");
migrationBuilder.DropTable(
name: "RunesPage");
migrationBuilder.DropTable(
name: "Runes");
migrationBuilder.DropTable(
name: "Champions");
migrationBuilder.DropTable(
name: "t_LargeImage");
}
}
}

@ -1,44 +0,0 @@
// <auto-generated />
using EntityFrameworkLib;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFrameworkLib.Migrations
{
[DbContext(typeof(LolContext))]
partial class ChampionContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFrameworkLib.ChampionEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Bio")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Champions");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,330 @@
// <auto-generated />
using System;
using EntityFrameworkLib;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFrameworkLib.Migrations
{
[DbContext(typeof(LolContext))]
partial class LolContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("ChampionEntityRunePageEntity", b =>
{
b.Property<string>("ChampionsName")
.HasColumnType("TEXT");
b.Property<string>("RunePagesName")
.HasColumnType("TEXT");
b.HasKey("ChampionsName", "RunePagesName");
b.HasIndex("RunePagesName");
b.ToTable("ChampionEntityRunePageEntity");
});
modelBuilder.Entity("ChampionEntitySkillEntity", b =>
{
b.Property<string>("ChampionsName")
.HasColumnType("TEXT");
b.Property<string>("SkillsName")
.HasColumnType("TEXT");
b.HasKey("ChampionsName", "SkillsName");
b.HasIndex("SkillsName");
b.ToTable("ChampionEntitySkillEntity");
});
modelBuilder.Entity("EntityFrameworkLib.ChampionEntity", b =>
{
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("Bio")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<int>("Class")
.HasColumnType("INTEGER");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int?>("ImageId")
.HasColumnType("INTEGER");
b.HasKey("Name");
b.HasIndex("ImageId");
b.ToTable("Champions");
});
modelBuilder.Entity("EntityFrameworkLib.CharacteristicEntity", b =>
{
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("ChampionForeignKey")
.HasColumnType("TEXT");
b.Property<int>("Value")
.HasColumnType("INTEGER");
b.HasKey("Name", "ChampionForeignKey");
b.HasIndex("ChampionForeignKey");
b.ToTable("Characteristics");
});
modelBuilder.Entity("EntityFrameworkLib.LargeImageEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Base64")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("t_LargeImage");
});
modelBuilder.Entity("EntityFrameworkLib.RuneEntity", b =>
{
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<int?>("ImageId")
.HasColumnType("INTEGER");
b.Property<int>("RuneFamily")
.HasColumnType("INTEGER");
b.HasKey("Name");
b.HasIndex("ImageId");
b.ToTable("Runes");
});
modelBuilder.Entity("EntityFrameworkLib.RunePageEntity", b =>
{
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("RunesPage");
});
modelBuilder.Entity("EntityFrameworkLib.RunePageRuneEntity", b =>
{
b.Property<string>("RunePageName")
.HasColumnType("TEXT");
b.Property<string>("RuneName")
.HasColumnType("TEXT");
b.Property<int>("Category")
.HasColumnType("INTEGER");
b.HasKey("RunePageName", "RuneName");
b.HasIndex("RuneName");
b.ToTable("RunePageRunes");
});
modelBuilder.Entity("EntityFrameworkLib.SkillEntity", b =>
{
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("Name");
b.ToTable("Skills");
});
modelBuilder.Entity("EntityFrameworkLib.SkinEntity", b =>
{
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("ChampionForeignKey")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int?>("ImageId")
.HasColumnType("INTEGER");
b.Property<float>("Price")
.HasColumnType("REAL");
b.HasKey("Name");
b.HasIndex("ChampionForeignKey");
b.HasIndex("ImageId");
b.ToTable("Skins");
});
modelBuilder.Entity("ChampionEntityRunePageEntity", b =>
{
b.HasOne("EntityFrameworkLib.ChampionEntity", null)
.WithMany()
.HasForeignKey("ChampionsName")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("EntityFrameworkLib.RunePageEntity", null)
.WithMany()
.HasForeignKey("RunePagesName")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("ChampionEntitySkillEntity", b =>
{
b.HasOne("EntityFrameworkLib.ChampionEntity", null)
.WithMany()
.HasForeignKey("ChampionsName")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("EntityFrameworkLib.SkillEntity", null)
.WithMany()
.HasForeignKey("SkillsName")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("EntityFrameworkLib.ChampionEntity", b =>
{
b.HasOne("EntityFrameworkLib.LargeImageEntity", "Image")
.WithMany()
.HasForeignKey("ImageId");
b.Navigation("Image");
});
modelBuilder.Entity("EntityFrameworkLib.CharacteristicEntity", b =>
{
b.HasOne("EntityFrameworkLib.ChampionEntity", "Champion")
.WithMany("Characteristics")
.HasForeignKey("ChampionForeignKey")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Champion");
});
modelBuilder.Entity("EntityFrameworkLib.RuneEntity", b =>
{
b.HasOne("EntityFrameworkLib.LargeImageEntity", "Image")
.WithMany()
.HasForeignKey("ImageId");
b.Navigation("Image");
});
modelBuilder.Entity("EntityFrameworkLib.RunePageRuneEntity", b =>
{
b.HasOne("EntityFrameworkLib.RuneEntity", "Rune")
.WithMany("RunePages")
.HasForeignKey("RuneName")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("EntityFrameworkLib.RunePageEntity", "RunePage")
.WithMany("Runes")
.HasForeignKey("RunePageName")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Rune");
b.Navigation("RunePage");
});
modelBuilder.Entity("EntityFrameworkLib.SkinEntity", b =>
{
b.HasOne("EntityFrameworkLib.ChampionEntity", "Champion")
.WithMany()
.HasForeignKey("ChampionForeignKey")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("EntityFrameworkLib.LargeImageEntity", "Image")
.WithMany()
.HasForeignKey("ImageId");
b.Navigation("Champion");
b.Navigation("Image");
});
modelBuilder.Entity("EntityFrameworkLib.ChampionEntity", b =>
{
b.Navigation("Characteristics");
});
modelBuilder.Entity("EntityFrameworkLib.RuneEntity", b =>
{
b.Navigation("RunePages");
});
modelBuilder.Entity("EntityFrameworkLib.RunePageEntity", b =>
{
b.Navigation("Runes");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,28 @@
using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameworkLib
{
public class RuneEntity
{
[Key]
[MaxLength(256)]
public string Name { get; set; }
[Required]
[MaxLength(500)]
public string Description { get; set; }
[Required]
public RuneFamily RuneFamily { get; set; }
public ICollection<RunePageRuneEntity>? RunePages { get; set; }
public int? ImageId { get; set; }
[ForeignKey("ImageId")]
public LargeImageEntity? Image { get; set; }
}
}

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameworkLib
{
public class RunePageEntity
{
[Key]
[MaxLength(256)]
public string Name { get; set; }
public ICollection<RunePageRuneEntity> Runes { get; set; }
public ICollection<ChampionEntity> Champions { get; set; }
}
}

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Model.RunePage;
namespace EntityFrameworkLib
{
public class RunePageRuneEntity
{
public Category Category { get; set; }
[ForeignKey("RuneName")]
public RuneEntity Rune { get; set; }
public string RuneName { get; set; }
[ForeignKey("RunePageName")]
public RunePageEntity RunePage { get; set; }
public string RunePageName { get; set; }
}
}

@ -0,0 +1,24 @@
using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameworkLib
{
public class SkillEntity
{
[Key]
[MaxLength(256)]
public string Name { get; set; }
[Required]
[MaxLength(500)]
public string Description { get; set; }
[Required]
public SkillType Type { get; set; }
public ICollection<ChampionEntity>? Champions { get; set; }
}
}

@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameworkLib
{
public class Skin
{
public string Name { get; set; }
public string Description { get; set; }
public string Icon { get; set; }
public float Price { get; set; }
}
}

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameworkLib
{
public class SkinEntity
{
[Key]
[MaxLength(256)]
public string Name { get; set; }
[Required]
[MaxLength(500)]
public string Description { get; set; }
[Required]
public string Icon { get; set; }
[Required]
public float Price { get; set; }
[Required]
public string ChampionForeignKey { get; set; }
[ForeignKey("ChampionForeignKey")]
public ChampionEntity Champion { get; set; }
public int? ImageId { get; set; }
[ForeignKey("ImageId")]
public LargeImageEntity? Image { get; set; }
}
}

@ -31,7 +31,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DBWithStub", "DBWithStub",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DBEntitiesWithStub", "DBEntitiesWithStub\DBEntitiesWithStub.csproj", "{C9D40527-6F42-4FA9-8063-554D2A0E9161}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DBDataManager", "DBDataManager\DBDataManager.csproj", "{9596049A-FCBB-4F61-9E48-D3086EAEFF85}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DBDataManager", "DBDataManager\DBDataManager.csproj", "{9596049A-FCBB-4F61-9E48-D3086EAEFF85}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleConfig", "ConsoleConfig\ConsoleConfig.csproj", "{4E2A53C1-E504-42F4-AD36-8384F74577BE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LolApp", "..\..\..\..\Downloads\EntityFramework_LoL-master\entityframework_lol\Sources\LolApp\LolApp.csproj", "{0C898A04-092A-49AA-BE65-8AE818A2AF50}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ViewModels", "..\..\..\..\Downloads\EntityFramework_LoL-master\entityframework_lol\Sources\ViewModels\ViewModels.csproj", "{3F2F7988-38E0-413A-B1BA-826E6DB3224D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -83,6 +89,20 @@ Global
{9596049A-FCBB-4F61-9E48-D3086EAEFF85}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9596049A-FCBB-4F61-9E48-D3086EAEFF85}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9596049A-FCBB-4F61-9E48-D3086EAEFF85}.Release|Any CPU.Build.0 = Release|Any CPU
{4E2A53C1-E504-42F4-AD36-8384F74577BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E2A53C1-E504-42F4-AD36-8384F74577BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E2A53C1-E504-42F4-AD36-8384F74577BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E2A53C1-E504-42F4-AD36-8384F74577BE}.Release|Any CPU.Build.0 = Release|Any CPU
{0C898A04-092A-49AA-BE65-8AE818A2AF50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C898A04-092A-49AA-BE65-8AE818A2AF50}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C898A04-092A-49AA-BE65-8AE818A2AF50}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{0C898A04-092A-49AA-BE65-8AE818A2AF50}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C898A04-092A-49AA-BE65-8AE818A2AF50}.Release|Any CPU.Build.0 = Release|Any CPU
{0C898A04-092A-49AA-BE65-8AE818A2AF50}.Release|Any CPU.Deploy.0 = Release|Any CPU
{3F2F7988-38E0-413A-B1BA-826E6DB3224D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3F2F7988-38E0-413A-B1BA-826E6DB3224D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F2F7988-38E0-413A-B1BA-826E6DB3224D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3F2F7988-38E0-413A-B1BA-826E6DB3224D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -95,6 +115,7 @@ Global
{B9D905BB-F4CD-4CE4-B718-7534AE5C3862} = {F18B03EC-963B-4EEA-842D-5C041A931D20}
{313DC068-AFD4-4FCC-BB19-F344F996050D} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}
{C9D40527-6F42-4FA9-8063-554D2A0E9161} = {F0711CE6-C48B-4E96-8DE0-79BDBB4635D6}
{4E2A53C1-E504-42F4-AD36-8384F74577BE} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9}

@ -3,10 +3,12 @@ namespace Model
{
public class LargeImage : IEquatable<LargeImage>
{
public int Id { get; set; }
public string Base64 { get; set; }
public LargeImage(string base64)
{
Id = 0;
Base64 = base64;
}
@ -23,6 +25,11 @@ namespace Model
public override int GetHashCode()
=> Base64.Substring(0, 10).GetHashCode();
public static implicit operator LargeImage(string v)
{
return new LargeImage(v);
}
}
}

@ -13,6 +13,7 @@
<Folder Include="enums\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.2">
<PrivateAssets>all</PrivateAssets>

@ -3,93 +3,94 @@ using System.Collections.ObjectModel;
namespace Model
{
public partial class RunePage
{
public string Name
{
get => name;
private init
{
if(string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException("a Rune Page must have a name");
}
name = value;
}
}
private readonly string name = null!;
public partial class RunePage
{
public string Name
{
get => name;
private init
{
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException("a Rune Page must have a name");
}
name = value;
}
}
private readonly string name = null!;
public ReadOnlyDictionary<Category, Rune> Runes { get; private set; }
private Dictionary<Category, Rune> runes = new Dictionary<Category, Rune>();
public ReadOnlyDictionary<Category, Rune> Runes { get; private set; }
private Dictionary<Category, Rune> runes = new Dictionary<Category, Rune>();
public RunePage(string name)
{
Name = name;
Runes = new ReadOnlyDictionary<Category, Rune>(runes);
}
public RunePage(string name)
{
Name = name;
Runes = new ReadOnlyDictionary<Category, Rune>(runes);
}
public Rune? this[Category category]
{
get
{
if(runes.TryGetValue(category, out Rune? rune))
{
return rune;
}
return null;
}
set
{
if(value == null)
{
runes.Remove(category);
}
runes[category] = value!;
CheckRunes(category);
}
}
public Rune? this[Category category]
{
get
{
if (runes.TryGetValue(category, out Rune? rune))
{
return rune;
}
return null;
}
set
{
if (value == null)
{
runes.Remove(category);
return;
}
runes[category] = value!;
CheckRunes(category);
}
}
private void CheckRunes(Category newRuneCategory)
{
switch(newRuneCategory)
{
case Category.Major:
UpdateMajorFamily(Category.Minor1, true);
UpdateMajorFamily(Category.Minor2, true);
UpdateMajorFamily(Category.Minor3, true);
UpdateMajorFamily(Category.OtherMinor1, false);
UpdateMajorFamily(Category.OtherMinor2, false);
break;
case Category.Minor1:
case Category.Minor2:
case Category.Minor3:
UpdateMajorFamily(newRuneCategory, true);
break;
case Category.OtherMinor1:
case Category.OtherMinor2:
UpdateMajorFamily(newRuneCategory, false);
break;
}
}
private void CheckRunes(Category newRuneCategory)
{
switch (newRuneCategory)
{
case Category.Major:
UpdateMajorFamily(Category.Minor1, true);
UpdateMajorFamily(Category.Minor2, true);
UpdateMajorFamily(Category.Minor3, true);
UpdateMajorFamily(Category.OtherMinor1, false);
UpdateMajorFamily(Category.OtherMinor2, false);
break;
case Category.Minor1:
case Category.Minor2:
case Category.Minor3:
UpdateMajorFamily(newRuneCategory, true);
break;
case Category.OtherMinor1:
case Category.OtherMinor2:
UpdateMajorFamily(newRuneCategory, false);
break;
}
}
private bool? CheckFamilies(Category cat1, Category cat2)
{
runes.TryGetValue(cat1, out Rune? rune1);
runes.TryGetValue(cat2, out Rune? rune2);
if(rune1 == null || rune2 == null)
{
return null;
}
return rune1.Family == rune2.Family;
}
private bool? CheckFamilies(Category cat1, Category cat2)
{
runes.TryGetValue(cat1, out Rune? rune1);
runes.TryGetValue(cat2, out Rune? rune2);
if (rune1 == null || rune2 == null)
{
return null;
}
return rune1.Family == rune2.Family;
}
private void UpdateMajorFamily(Category minor, bool expectedValue)
{
if(CheckFamilies(Category.Major, minor).GetValueOrDefault(expectedValue) == expectedValue)
{
runes.Remove(minor);
}
}
}
private void UpdateMajorFamily(Category cat, bool expectedValue)
{
if (CheckFamilies(Category.Major, cat).GetValueOrDefault(expectedValue) != expectedValue)
{
runes.Remove(cat);
}
}
}
}

@ -62,6 +62,13 @@ namespace Model
Description = description;
}
public Skin(string name, string description, string icon, float price)
{
this.name = name;
this.description = description;
Price = price;
}
public Skin(string name, string description, float price)
{
this.name = name;

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.2">
<PrivateAssets>all</PrivateAssets>

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.2">
<PrivateAssets>all</PrivateAssets>

@ -15,6 +15,7 @@
<None Remove="Microsoft.Extensions.DependencyInjection" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.2">
<PrivateAssets>all</PrivateAssets>

@ -2,6 +2,7 @@ using EntityFrameworkLib;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Model;
using System.Diagnostics;
namespace UnitTestsSQLiteInMemory
{
@ -20,9 +21,9 @@ namespace UnitTestsSQLiteInMemory
using(var context = new LolContext(options))
{
ChampionEntity akali = new ChampionEntity { Name = "Akali", Bio = "Bio Akali", Icon = "Icon Akali" };
ChampionEntity alistar = new ChampionEntity { Name = "Alistar", Bio = "Bio Alistar", Icon = "Icon Alistar" };
ChampionEntity bard = new ChampionEntity { Name = "Bard", Bio = "Bio Bard", Icon = "Icon Bard" };
ChampionEntity akali = new ChampionEntity { Name = "Akali", Bio = "Bio Akali", Icon = "Icon Akali", Class = ChampionClass.Assassin };
ChampionEntity alistar = new ChampionEntity { Name = "Alistar", Bio = "Bio Alistar", Icon = "Icon Alistar", Class = ChampionClass.Support };
ChampionEntity bard = new ChampionEntity { Name = "Bard", Bio = "Bio Bard", Icon = "Icon Bard", Class = ChampionClass.Support };
context.Champions.Add(akali);
context.Champions.Add(alistar);
@ -54,9 +55,9 @@ namespace UnitTestsSQLiteInMemory
//context.Database.OpenConnection();
context.Database.EnsureCreated();
ChampionEntity akali = new ChampionEntity { Name = "Akali", Bio = "Bio Akali", Icon = "Icon Akali" };
ChampionEntity akshan = new ChampionEntity { Name = "Akshan", Bio = "Bio Akshan", Icon = "Icon Akshan" };
ChampionEntity twitch = new ChampionEntity { Name = "Twitch", Bio = "Bio Twitch", Icon = "icon Twitch" };
ChampionEntity akali = new ChampionEntity { Name = "Akali", Bio = "Bio Akali", Icon = "Icon Akali", Class = ChampionClass.Assassin };
ChampionEntity akshan = new ChampionEntity { Name = "Akshan", Bio = "Bio Akshan", Icon = "Icon Akshan", Class = ChampionClass.Fighter };
ChampionEntity twitch = new ChampionEntity { Name = "Twitch", Bio = "Bio Twitch", Icon = "icon Twitch", Class = ChampionClass.Assassin };
context.Champions.Add(akali);
context.Champions.Add(akshan);
@ -89,5 +90,40 @@ namespace UnitTestsSQLiteInMemory
Assert.Equal(1, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
}
}
[Fact]
public void Delete_Champions_Test()
{
//connection must be opened to use In-memory database
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<LolContext>()
.UseSqlite(connection)
.Options;
//prepares the database with one instance of the context
using (var context = new LolContext(options))
{
//context.Database.OpenConnection();
context.Database.EnsureCreated();
ChampionEntity veigar = new ChampionEntity { Name = "Veigar", Bio = "Bio Veigar", Icon = "Icon Veigar", Class = ChampionClass.Fighter };
ChampionEntity yone = new ChampionEntity { Name = "Yone", Bio = "Bio Yone", Icon = "Icon Yone", Class = ChampionClass.Assassin };
ChampionEntity yasuo = new ChampionEntity { Name = "Yasuo", Bio = "Bio Yasuo", Icon = "icon Yasuo", Class = ChampionClass.Assassin };
context.Champions.Add(veigar);
context.Champions.Add(yone);
context.Champions.Add(yasuo);
context.SaveChanges();
context.Champions.Remove(veigar);
context.Champions.Remove(yone);
context.Champions.Remove(yasuo);
context.SaveChanges();
}
}
}
}

@ -9,6 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />

@ -7,6 +7,10 @@ namespace Web_Api
public int Id { get; set; }
public string Name { get; set; }
public string Bio { get; set; }
public string Icon { get; set; }
public LargeImageDTO Image { get; set; }
public ChampionClass Class { get; set; }
public Champion toModel()
{

@ -1,18 +1,31 @@
using Microsoft.AspNetCore.Http;
using EntityFrameworkLib;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
using Model;
using StubLib;
using Web_Api.Mapper;
using static StubLib.StubData;
namespace Web_Api.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class ChampionsController : Controller
public class ChampionsController : ControllerBase
{
private StubData.ChampionsManager ChampionsManager { get; set; } = new StubData.ChampionsManager(new StubData());
private readonly LolContext _context;
public ChampionsController(LolContext context)
{
_context = context;
}
//private StubData.ChampionsManager ChampionsManager { get; set; } = new StubData.ChampionsManager(new StubData());
private readonly ILogger<ChampionsController> _logger;
public ChampionsController(ILogger<ChampionsController> logger)
@ -20,21 +33,28 @@ namespace Web_Api.Controllers
_logger = logger;
}
[HttpGet]
[HttpGet("GET")]
public async Task<IActionResult> Get()
{
var list = await ChampionsManager.GetItems(0, await ChampionsManager.GetNbItems());
return Ok(list.Select(champion => champion?.toDTO()));
return Ok(list.Select(rune => rune?.toDTO()));
//Faire en sorte d'avoir un ChampionDTO et pas ChampionENtity
}
[HttpGet("name")]
public async Task<IActionResult> GetById(string name)
[HttpGet("GETBYNAME")]
public async Task<IActionResult> GetByName(string name)
{
var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);
return Ok(championSelected.Select(c => c?.toDTO()));
if (championSelected.Count() == 0)
{
Console.WriteLine("Aucun champion ne correspond au nom { " + name + " } !");
throw new Exception("Aucun champion ne correspond au nom { " + name + " } !");
}
Console.WriteLine("Le champion { " + name + " } existe");
return Ok(championSelected.Select(champion => champion?.toDTO()));
}
[HttpPost("addChampion")]
[HttpPost("ADD")]
public async Task<IActionResult> AddChampion([FromBody] ChampionDTO champion)
{
var newChampion = champion.toModel();
@ -47,7 +67,7 @@ namespace Web_Api.Controllers
return Ok();
}
[HttpPut("updateChampion")]
[HttpPut("UPDATE")]
public async Task<IActionResult> UpdateChampion(string name, [FromBody] ChampionDTO champion)
{
var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);
@ -67,7 +87,7 @@ namespace Web_Api.Controllers
return Ok();
}
[HttpDelete("deleteChampion")]
[HttpDelete("DELETE")]
public async Task<IActionResult> DeleteChampion(string name)
{
var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);

@ -19,21 +19,27 @@ namespace Web_Api.Controllers
_logger = logger;
}
[HttpGet]
[HttpGet("GET")]
public async Task<IActionResult> Get()
{
var list = await RunesManager.GetItems(0, await RunesManager.GetNbItems());
return Ok(list.Select(rune => rune?.toDTO()));
}
[HttpGet("name")]
public async Task<IActionResult> GetById(string name)
[HttpGet("GETBYNAME")]
public async Task<IActionResult> GetByName(string name)
{
var runeSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null);
return Ok(runeSelected.Select(rune => rune?.toDTO()));
var runesSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null);
if (runesSelected.Count() == 0)
{
Console.WriteLine("Aucune rune ne correspond au nom { " + name + " } !");
throw new Exception("Aucune rune ne correspond au nom { " + name + " } !");
}
Console.WriteLine("La rune { " + name + " } existe");
return Ok(runesSelected.Select(runes => runes?.toDTO()));
}
[HttpPost("addRune")]
[HttpPost("ADD")]
public async Task<IActionResult> AddRune(RuneDTO rune)
{
var newRune = rune.toModel();
@ -46,7 +52,7 @@ namespace Web_Api.Controllers
return Ok(newRune);
}
[HttpPut("updateRune")]
[HttpPut("UPDATE")]
public async Task<IActionResult> UpdateRune(string name, RuneDTO rune)
{
var runeSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null);
@ -66,7 +72,7 @@ namespace Web_Api.Controllers
return Ok();
}
[HttpDelete("deleteRune")]
[HttpDelete("DELETE")]
public async Task<IActionResult> DeleteRune(string name)
{
var runeSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null);

@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using StubLib;
using Web_Api.Mapper;
using static StubLib.StubData;
namespace Web_Api.Controllers
{
@ -17,21 +18,27 @@ namespace Web_Api.Controllers
_logger = logger;
}
[HttpGet]
[HttpGet("GET")]
public async Task<IActionResult> Get()
{
var list = await SkinsManager.GetItems(0, await SkinsManager.GetNbItems());
return Ok(list.Select(skin => skin?.toDTO()));
}
[HttpGet("name")]
public async Task<IActionResult> GetById(string name)
[HttpGet("GETBYNAME")]
public async Task<IActionResult> GetByName(string name)
{
var skinSelected = await SkinsManager.GetItemsByName(name, 0, await SkinsManager.GetNbItemsByName(name), null);
return Ok(skinSelected.Select(skin => skin?.toDTO()));
var skinsSelected = await SkinsManager.GetItemsByName(name, 0, await SkinsManager.GetNbItemsByName(name), null);
if (skinsSelected.Count() == 0)
{
Console.WriteLine("Aucun skin ne correspond au nom { " + name + " } !");
throw new Exception("Aucun skin ne correspond au nom { " + name + " } !");
}
Console.WriteLine("Le skin { " + name + " } existe");
return Ok(skinsSelected.Select(skins => skins?.toDTO()));
}
[HttpPost("addSkin")]
[HttpPost("ADD")]
public async Task<IActionResult> AddSkin(SkinDTO skin)
{
var newSkin = skin.toModel();
@ -44,7 +51,7 @@ namespace Web_Api.Controllers
return Ok(newSkin);
}
[HttpPut("updateSkin")]
[HttpPut("UPDATE")]
public async Task<IActionResult> UpdateChampion(string name, SkinDTO skin)
{
var skinSelected = await SkinsManager.GetItemsByName(name, 0, await SkinsManager.GetNbItemsByName(name), null);
@ -65,7 +72,7 @@ namespace Web_Api.Controllers
return Ok();
}
[HttpDelete("deleteSkin")]
[HttpDelete("DELETE")]
public async Task<IActionResult> DeleteChampion(string name)
{
var skinSelected = await SkinsManager.GetItemsByName(name, 0, await SkinsManager.GetNbItemsByName(name), null);

@ -1,33 +0,0 @@
using Microsoft.AspNetCore.Mvc;
namespace Web_Api.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}

@ -0,0 +1,17 @@
using Model;
using System.Reflection.Metadata.Ecma335;
using System.Runtime.CompilerServices;
namespace Web_Api
{
public class LargeImageDTO
{
public int Id { get; set; }
public string Base64 { get; set; }
public LargeImage toModel()
{
return new LargeImage(Base64);
}
}
}

@ -1,11 +1,39 @@
using EntityFrameworkLib;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using Web_Api.Controllers;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<LolContext>(options =>
options.UseSqlite($"DataSource=projet.Champions.db"));
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// Add versioning middleware
builder.Services.AddApiVersioning(options =>
{
// Add a default version
options.DefaultApiVersion = new ApiVersion(1, 0);
options.AssumeDefaultVersionWhenUnspecified = true;
options.ReportApiVersions = true;
});
//builder.Services.AddEndpointsApiExplorer();
//builder.Services.AddSwaggerGen();
// Add Swagger
builder.Services.AddSwaggerGen(c =>
{
// Add version 1 documentation
c.SwaggerDoc("v1", new OpenApiInfo { Title = "API_LOL", Version = "v1" });
// Add version 2 documentation
c.SwaggerDoc("v2", new OpenApiInfo { Title = "API_LOL", Version = "v2" });
});
var app = builder.Build();
@ -13,13 +41,38 @@ var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
//app.UseSwaggerUI();
app.UseSwaggerUI(c =>
{
// Configure Swagger for version 1
c.SwaggerEndpoint("/swagger/v1/swagger.json", "API_LOL v1");
// Configure Swagger for version 2
c.SwaggerEndpoint("/swagger/v2/swagger.json", "API_LOL v2");
});
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.MapControllers();
// Map version 1 to /api/v1
app.Map("/api/v1", app =>
{
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
});
// Map version 2 to /api/v2
app.Map("/api/v2", app =>
{
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
});
//app.MapControllers();
app.Run();

@ -0,0 +1,10 @@
namespace Web_Api
{
public class SwaggerOptions
{
public string JsonRoute { get; set; }
public string Description { get; set; }
public string UIEndpoint { get; set; }
public string Version { get; set; }
}
}

@ -1,13 +0,0 @@
namespace Web_Api
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

@ -7,10 +7,12 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EntityFrameworkLib\EntityFrameworkLib.csproj" />
<ProjectReference Include="..\StubLib\StubLib.csproj" />
</ItemGroup>

Loading…
Cancel
Save