From ec6b887dfa9908c3c05ceb522ed18cbcffe70cbb Mon Sep 17 00:00:00 2001 From: Lucas Delanier Date: Thu, 2 Feb 2023 12:00:00 +0100 Subject: [PATCH 1/2] modification of put and get --- Sources/APILOL/APILOL.csproj | 6 ++ .../APILOL/Controllers/ChampionsController.cs | 73 +++++++++++++++++++ Sources/APILOL/Mapper/ChampionMapper.cs | 20 +++++ Sources/APILOL/Program.cs | 5 +- Sources/ChampionControllerTest.cs | 0 Sources/DTO/ChampionDTO.cs | 16 ++++ Sources/DTO/DTO.csproj | 9 +++ Sources/LeagueOfLegends.sln | 8 +- 8 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 Sources/APILOL/Controllers/ChampionsController.cs create mode 100644 Sources/APILOL/Mapper/ChampionMapper.cs create mode 100644 Sources/ChampionControllerTest.cs create mode 100644 Sources/DTO/ChampionDTO.cs create mode 100644 Sources/DTO/DTO.csproj diff --git a/Sources/APILOL/APILOL.csproj b/Sources/APILOL/APILOL.csproj index 60bf9ea..3b42408 100644 --- a/Sources/APILOL/APILOL.csproj +++ b/Sources/APILOL/APILOL.csproj @@ -10,4 +10,10 @@ + + + + + + diff --git a/Sources/APILOL/Controllers/ChampionsController.cs b/Sources/APILOL/Controllers/ChampionsController.cs new file mode 100644 index 0000000..08f558b --- /dev/null +++ b/Sources/APILOL/Controllers/ChampionsController.cs @@ -0,0 +1,73 @@ +using APILOL.Mapper; +using DTO; +using Microsoft.AspNetCore.Mvc; +using Model; +using StubLib; +using System; +using System.Xml.Linq; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace APILOL.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ChampionsController : ControllerBase + { + + IChampionsManager managerChampions; + + public ChampionsController(IDataManager manager) + { + managerChampions = manager.ChampionsMgr; + } + + + // GET: api/ + [HttpGet] + + public async Task Get() + { + IEnumerable championDTOs = (await managerChampions.GetItems(0, await managerChampions.GetNbItems())).Select(x => x.ToDTO()); + + if (championDTOs != null) + { + return Ok(championDTOs); + } + return NotFound(); + } + + // GET api//5 + [HttpGet("{name}")] + public async Task GetAsync(String name) + { + IEnumerable champ = await managerChampions.GetItemsByName(name, 0, await managerChampions.GetNbItems()); + if (champ.Count() != 0) + { + return Ok(champ.First().ToDTO()); + } + return NotFound(); + } + + // POST api/ + [HttpPost] + public async Task Post([FromBody] ChampionDTO champion) + { + return CreatedAtAction(nameof(Get), await managerChampions.AddItem(champion.ToModel())); + + } + + // PUT api//5 + [HttpPut("{name}")] + public async void Put(String name, [FromBody] ChampionDTO champion) + { + + } + + // DELETE api//5 + [HttpDelete("{id}")] + public async void Delete(int id) + { + } + } +} diff --git a/Sources/APILOL/Mapper/ChampionMapper.cs b/Sources/APILOL/Mapper/ChampionMapper.cs new file mode 100644 index 0000000..561a96c --- /dev/null +++ b/Sources/APILOL/Mapper/ChampionMapper.cs @@ -0,0 +1,20 @@ +using DTO; +using Model; +using System.Buffers.Text; +using System.Xml.Linq; + +namespace APILOL.Mapper +{ + public static class ChampionMapper + { + public static ChampionDTO ToDTO(this Champion champ) + { + return new ChampionDTO() { Name = champ.Name, Bio = champ.Bio, Icon = champ.Icon, Image = champ.Image.Base64 }; + } + + public static Champion ToModel(this ChampionDTO champ) + { + return new Champion(champ.Name,icon: champ.Icon, image: champ.Icon, bio: champ.Bio); + } + } +} diff --git a/Sources/APILOL/Program.cs b/Sources/APILOL/Program.cs index 48863a6..440cdf0 100644 --- a/Sources/APILOL/Program.cs +++ b/Sources/APILOL/Program.cs @@ -1,7 +1,10 @@ +using Model; +using StubLib; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. - +builder.Services.AddSingleton(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); diff --git a/Sources/ChampionControllerTest.cs b/Sources/ChampionControllerTest.cs new file mode 100644 index 0000000..e69de29 diff --git a/Sources/DTO/ChampionDTO.cs b/Sources/DTO/ChampionDTO.cs new file mode 100644 index 0000000..a66c8cc --- /dev/null +++ b/Sources/DTO/ChampionDTO.cs @@ -0,0 +1,16 @@ +namespace DTO +{ + public class ChampionDTO + { + public string Name { get; set; } + public string Bio { get; set; } + public string Icon { get; set; } + + public string Image { get; set; } + + + + + + } +} \ No newline at end of file diff --git a/Sources/DTO/DTO.csproj b/Sources/DTO/DTO.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/Sources/DTO/DTO.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index fe317f6..1a7e6bf 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -15,7 +15,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Stub", "Stub", "{2C607793-B EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubLib", "StubLib\StubLib.csproj", "{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "APILOL", "APILOL\APILOL.csproj", "{88538F30-9D26-4A70-88FD-12BA05576E39}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "APILOL", "APILOL\APILOL.csproj", "{88538F30-9D26-4A70-88FD-12BA05576E39}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{2124E1DB-1E6D-4FCE-9F34-53457C374394}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -43,6 +45,10 @@ Global {88538F30-9D26-4A70-88FD-12BA05576E39}.Debug|Any CPU.Build.0 = Debug|Any CPU {88538F30-9D26-4A70-88FD-12BA05576E39}.Release|Any CPU.ActiveCfg = Release|Any CPU {88538F30-9D26-4A70-88FD-12BA05576E39}.Release|Any CPU.Build.0 = Release|Any CPU + {2124E1DB-1E6D-4FCE-9F34-53457C374394}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2124E1DB-1E6D-4FCE-9F34-53457C374394}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2124E1DB-1E6D-4FCE-9F34-53457C374394}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2124E1DB-1E6D-4FCE-9F34-53457C374394}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From bb2bcb3a30ab88f0942bb3f52b3b8f04cf81f0e6 Mon Sep 17 00:00:00 2001 From: Louison PARANT Date: Thu, 2 Feb 2023 12:04:31 +0100 Subject: [PATCH 2/2] modif Entity --- .../{ => DBContexts}/ChampionContext.cs | 7 +- .../DBContexts/RuneContext.cs | 13 +++ .../DBContexts/SQLiteContext.cs | 15 +++ .../DBContexts/SkinContext.cs | 13 +++ Sources/EntityFrameworkLOL/DBLOL.db | Bin 20480 -> 45056 bytes .../{ => Entities}/ChampionEntity.cs | 3 +- .../EntityFrameworkLOL/Entities/RuneEntity.cs | 18 ++++ .../EntityFrameworkLOL/Entities/SkinEntity.cs | 22 ++++ .../EntityFrameworkLOL.DBLOL.db | Bin 20480 -> 0 bytes .../EntityFrameworkLOL.csproj | 4 + ...230202105714_MigrationWallah2.Designer.cs} | 18 ++-- ....cs => 20230202105714_MigrationWallah2.cs} | 11 +- ...pshot.cs => SQLiteContextModelSnapshot.cs} | 16 ++- Sources/EntityFrameworkLOL/Program.cs | 99 +++++++++++++++++- Sources/StubLib/StubData.Champions.cs | 3 +- 15 files changed, 207 insertions(+), 35 deletions(-) rename Sources/EntityFrameworkLOL/{ => DBContexts}/ChampionContext.cs (52%) create mode 100644 Sources/EntityFrameworkLOL/DBContexts/RuneContext.cs create mode 100644 Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs create mode 100644 Sources/EntityFrameworkLOL/DBContexts/SkinContext.cs rename Sources/EntityFrameworkLOL/{ => Entities}/ChampionEntity.cs (85%) create mode 100644 Sources/EntityFrameworkLOL/Entities/RuneEntity.cs create mode 100644 Sources/EntityFrameworkLOL/Entities/SkinEntity.cs delete mode 100644 Sources/EntityFrameworkLOL/EntityFrameworkLOL.DBLOL.db rename Sources/EntityFrameworkLOL/Migrations/{20230201163336_MigrationWallah.Designer.cs => 20230202105714_MigrationWallah2.Designer.cs} (64%) rename Sources/EntityFrameworkLOL/Migrations/{20230201163336_MigrationWallah.cs => 20230202105714_MigrationWallah2.cs} (66%) rename Sources/EntityFrameworkLOL/Migrations/{ChampionContextModelSnapshot.cs => SQLiteContextModelSnapshot.cs} (63%) diff --git a/Sources/EntityFrameworkLOL/ChampionContext.cs b/Sources/EntityFrameworkLOL/DBContexts/ChampionContext.cs similarity index 52% rename from Sources/EntityFrameworkLOL/ChampionContext.cs rename to Sources/EntityFrameworkLOL/DBContexts/ChampionContext.cs index 719926b..f7d3a11 100644 --- a/Sources/EntityFrameworkLOL/ChampionContext.cs +++ b/Sources/EntityFrameworkLOL/DBContexts/ChampionContext.cs @@ -1,10 +1,11 @@ -using Microsoft.EntityFrameworkCore; +using EntityFrameworkLOL.Entities; +using Microsoft.EntityFrameworkCore; -namespace EntityFrameworkLOL +namespace EntityFrameworkLOL.DBContexts { class ChampionContext : DbContext { - public DbSet Champions { get; set; } + public DbSet Champion { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder options) => options.UseSqlite($"Data Source=DBLOL.db"); diff --git a/Sources/EntityFrameworkLOL/DBContexts/RuneContext.cs b/Sources/EntityFrameworkLOL/DBContexts/RuneContext.cs new file mode 100644 index 0000000..daa69f9 --- /dev/null +++ b/Sources/EntityFrameworkLOL/DBContexts/RuneContext.cs @@ -0,0 +1,13 @@ +using EntityFrameworkLOL.Entities; +using Microsoft.EntityFrameworkCore; + +namespace EntityFrameworkLOL.DBContexts +{ + class RuneContext : DbContext + { + public DbSet Rune { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder options) + => options.UseSqlite($"Data Source=DBLOL.db"); + } +} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs b/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs new file mode 100644 index 0000000..8c31903 --- /dev/null +++ b/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs @@ -0,0 +1,15 @@ +using EntityFrameworkLOL.Entities; +using Microsoft.EntityFrameworkCore; + +namespace EntityFrameworkLOL.DBContexts +{ + class SQLiteContext : DbContext + { + /*public DbSet Champion { get; set; } + public DbSet Skin { get; set; }*/ + public DbSet Rune { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder options) + => options.UseSqlite($"Data Source=DBLOL.db"); + } +} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/DBContexts/SkinContext.cs b/Sources/EntityFrameworkLOL/DBContexts/SkinContext.cs new file mode 100644 index 0000000..5628c53 --- /dev/null +++ b/Sources/EntityFrameworkLOL/DBContexts/SkinContext.cs @@ -0,0 +1,13 @@ +using EntityFrameworkLOL.Entities; +using Microsoft.EntityFrameworkCore; + +namespace EntityFrameworkLOL.DBContexts +{ + class SkinContext : DbContext + { + public DbSet Skin { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder options) + => options.UseSqlite($"Data Source=DBLOL.db"); + } +} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/DBLOL.db b/Sources/EntityFrameworkLOL/DBLOL.db index 6e8e7c513bb882be2ef983154f94548171efa3cd..e1ce9c74d5f9994634429e98dacb045436979531 100644 GIT binary patch literal 45056 zcmeI&O-~a+7{KveTG~=**BHneBgtA55u@1MR;%$MVvP+@u++B$*;J^y5n63a)FT|c zdG$MZFnZOq2hW~7naDTr#?cv|&|P;yFGlKr$n<6U%crB&a2zH=(u zY@f70aZdTH>$RPqkQWLGUm^)S3ssZu{wM zoySM!TD7^*aGtcpX#C0`E@t%dP!NMWrftgGKF?K`R%%sQBkp8nlPlT%u6nD(pI)`L zp~i!+S{~Cj&o=6d zD+{gL)kf2IY8HAT`g|^EYWkkXHhr5z;sZ7&KV%c~LGpv5ebwG+FSU6stMw<>MFRx^ z1Q0*~0R#|0009ILKmdV%L0}{nn$)edl}U>mGkrd1X6>Etd zRQFjYh`D2Ymk6Tn7~j=_h$qHxVW77&CSXkbj)w|;+qnlU0?7S; z@uPnV0tg_000IagfB*srAb0tg_000IagfB*srARq+T z|7RK?fB*srAbfB*srAbhxcqv}~9}FzKuNn9*@vr55%{PCuqCh#X zWuqZ8ySThOW0PS?Vp2}3b4FrrL1unlF`U8T9OUX4;;Inh=;Y(7pad76JdxX!v3T+W z9?{9SxeeG1S=hu~zQ||H$i~QjgMt6XWj3%p82Il2 N`B(Ti-_uu800239HcS8j diff --git a/Sources/EntityFrameworkLOL/ChampionEntity.cs b/Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs similarity index 85% rename from Sources/EntityFrameworkLOL/ChampionEntity.cs rename to Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs index f693c37..fcc602e 100644 --- a/Sources/EntityFrameworkLOL/ChampionEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs @@ -5,8 +5,9 @@ using System.Threading.Tasks; using System.Collections.Generic; using System.Text; using System.ComponentModel.DataAnnotations; +using System.Xml.Linq; -namespace EntityFrameworkLOL +namespace EntityFrameworkLOL.Entities { class ChampionEntity { diff --git a/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs b/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs new file mode 100644 index 0000000..7ceb423 --- /dev/null +++ b/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs @@ -0,0 +1,18 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Linq; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel.DataAnnotations; + +namespace EntityFrameworkLOL.Entities +{ + class RuneEntity + { + [Key] + public string Name { get; set; } + + public string Description { get; set; } + } +} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs b/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs new file mode 100644 index 0000000..9412f33 --- /dev/null +++ b/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Linq; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel.DataAnnotations; + +namespace EntityFrameworkLOL.Entities +{ + class SkinEntity + { + [Key] + public string Name { get; set; } + + public string Description { get; set; } + + /*public string Icon { get; set; } + + public float Price { get; set; }*/ + } +} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/EntityFrameworkLOL.DBLOL.db b/Sources/EntityFrameworkLOL/EntityFrameworkLOL.DBLOL.db deleted file mode 100644 index e40710c96492a259a9812802b2d7b5b83a14c274..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20480 zcmeI&zi!h&9Ki9jleQ4a4VxvF92pQuD2g44Fp@?_SWT0V8fXV(nZ~7-k{BFUg0X!O zo`9EOV&Vn*0*st1;ugzcVrljL$tT~P?K}TI_ToSLuLe;X%Hueh2dV6cdqUU6b18)o zx+)v0tRibyR}Hn+uGQC7b;w%TF`)tm+4+X?)qfn#;HHX*bRev@NsS)y_wkY5KnNVlVoT1ZkG* z%V?R#$(Pbj{qOWk_qn3T$8@KK(=Ljv8K^{OoW#@9qx4OfEY-;thE*D_zG=SeuG1); z$G1wmE9#EAligK@Dq8)APz!+o0tg_000IagfB*srAb7PIV0R#|0009ILKmY**5I_KdTP%=$|L6Jt7GGdeLjVB;5I_I{1Q0*~0R#|0 HKneT?YZ%8* diff --git a/Sources/EntityFrameworkLOL/EntityFrameworkLOL.csproj b/Sources/EntityFrameworkLOL/EntityFrameworkLOL.csproj index d683ca4..40baca6 100644 --- a/Sources/EntityFrameworkLOL/EntityFrameworkLOL.csproj +++ b/Sources/EntityFrameworkLOL/EntityFrameworkLOL.csproj @@ -20,4 +20,8 @@ + + + + \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Migrations/20230201163336_MigrationWallah.Designer.cs b/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.Designer.cs similarity index 64% rename from Sources/EntityFrameworkLOL/Migrations/20230201163336_MigrationWallah.Designer.cs rename to Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.Designer.cs index e24c7dc..da7a0e3 100644 --- a/Sources/EntityFrameworkLOL/Migrations/20230201163336_MigrationWallah.Designer.cs +++ b/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.Designer.cs @@ -1,5 +1,5 @@ // -using EntityFrameworkLOL; +using EntityFrameworkLOL.DBContexts; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; @@ -9,9 +9,9 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace EntityFrameworkLOL.Migrations { - [DbContext(typeof(ChampionContext))] - [Migration("20230201163336_MigrationWallah")] - partial class MigrationWallah + [DbContext(typeof(SQLiteContext))] + [Migration("20230202105714_MigrationWallah2")] + partial class MigrationWallah2 { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -19,22 +19,18 @@ namespace EntityFrameworkLOL.Migrations #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - modelBuilder.Entity("EntityFrameworkLOL.ChampionEntity", b => + modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => { b.Property("Name") .HasColumnType("TEXT"); - b.Property("Bio") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Icon") + b.Property("Description") .IsRequired() .HasColumnType("TEXT"); b.HasKey("Name"); - b.ToTable("Champions"); + b.ToTable("Rune"); }); #pragma warning restore 612, 618 } diff --git a/Sources/EntityFrameworkLOL/Migrations/20230201163336_MigrationWallah.cs b/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.cs similarity index 66% rename from Sources/EntityFrameworkLOL/Migrations/20230201163336_MigrationWallah.cs rename to Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.cs index eb2dfc8..0150ec7 100644 --- a/Sources/EntityFrameworkLOL/Migrations/20230201163336_MigrationWallah.cs +++ b/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.cs @@ -5,22 +5,21 @@ namespace EntityFrameworkLOL.Migrations { /// - public partial class MigrationWallah : Migration + public partial class MigrationWallah2 : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( - name: "Champions", + name: "Rune", columns: table => new { Name = table.Column(type: "TEXT", nullable: false), - Bio = table.Column(type: "TEXT", nullable: false), - Icon = table.Column(type: "TEXT", nullable: false) + Description = table.Column(type: "TEXT", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_Champions", x => x.Name); + table.PrimaryKey("PK_Rune", x => x.Name); }); } @@ -28,7 +27,7 @@ namespace EntityFrameworkLOL.Migrations protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( - name: "Champions"); + name: "Rune"); } } } diff --git a/Sources/EntityFrameworkLOL/Migrations/ChampionContextModelSnapshot.cs b/Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs similarity index 63% rename from Sources/EntityFrameworkLOL/Migrations/ChampionContextModelSnapshot.cs rename to Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs index 351bf79..59fd766 100644 --- a/Sources/EntityFrameworkLOL/Migrations/ChampionContextModelSnapshot.cs +++ b/Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs @@ -1,5 +1,5 @@ // -using EntityFrameworkLOL; +using EntityFrameworkLOL.DBContexts; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; @@ -8,30 +8,26 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace EntityFrameworkLOL.Migrations { - [DbContext(typeof(ChampionContext))] - partial class ChampionContextModelSnapshot : ModelSnapshot + [DbContext(typeof(SQLiteContext))] + partial class SQLiteContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - modelBuilder.Entity("EntityFrameworkLOL.ChampionEntity", b => + modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => { b.Property("Name") .HasColumnType("TEXT"); - b.Property("Bio") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Icon") + b.Property("Description") .IsRequired() .HasColumnType("TEXT"); b.HasKey("Name"); - b.ToTable("Champions"); + b.ToTable("Rune"); }); #pragma warning restore 612, 618 } diff --git a/Sources/EntityFrameworkLOL/Program.cs b/Sources/EntityFrameworkLOL/Program.cs index 3751555..7271191 100644 --- a/Sources/EntityFrameworkLOL/Program.cs +++ b/Sources/EntityFrameworkLOL/Program.cs @@ -1,2 +1,97 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using EntityFrameworkLOL.DBContexts; +using EntityFrameworkLOL.Entities; +using System.Linq; +using System; +using System.Text; + +class Program +{ + static void Main(string[] args) + { + /*ChampionEntity akali = new ChampionEntity {Name="Akali"}; + ChampionEntity aatrox = new ChampionEntity { Name = "Aatrox" }; + ChampionEntity ahri = new ChampionEntity { Name = "Ahri" }; + ChampionEntity bard = new ChampionEntity { Name = "Bard" }; + ChampionEntity alistar = new ChampionEntity { Name = "Alistar" }; + ChampionEntity akshan = new ChampionEntity { Name = "Akshan" }; + + using (var context = new ChampionContext()) + { + // Crée des champions et les insère dans la base + Console.WriteLine("Creates and inserts new Champions"); + context.Add(akali); + context.Add(aatrox); + context.Add(ahri); + context.Add(bard); + context.Add(alistar); + context.Add(akshan); + context.SaveChanges(); + Console.WriteLine("Creates and executes a query retrieving the first Champion of the database whose name starts with an \"A\":"); + var aChampion = context.Champions + .Where(c => c.Name.StartsWith("A")) + .First(); + Console.WriteLine($"{aChampion.Name} (with bio : {aChampion.Bio}"); + }*/ + + RuneEntity conqueror = new RuneEntity { Name = "Conqueror", Description = "" }; + RuneEntity thriumph = new RuneEntity { Name = "Thriumph", Description = "" }; + RuneEntity alacrity = new RuneEntity { Name = "Legend : Alacrity", Description = "" }; + RuneEntity tenacity = new RuneEntity { Name = "Legend : Tenacity", Description = "" }; + RuneEntity laststand = new RuneEntity { Name = "Last Stand", Description = "" }; + RuneEntity laststand2 = new RuneEntity { Name = "Last Stand 2", Description = "" }; + + using (var context = new RuneContext()) + { + // Crée des Runes et les insère dans la base + Console.WriteLine("Creates and inserts new Runes"); + context.Add(conqueror); + context.Add(thriumph); + context.Add(alacrity); + context.Add(tenacity); + context.Add(laststand); + context.Add(laststand2); + context.SaveChanges(); + Console.WriteLine("Creates and executes a query retrieving the first Runes of the database whose name starts with an \"L\":"); + var lRune = context.Rune + .Where(r => r.Name.StartsWith("L")) + .First(); + Console.WriteLine($"{lRune.Name} (with Description : {lRune.Description}"); + } + + /*SkinEntity stinger = new SkinEntity { Name = "Stinger", Description = "" }; + SkinEntity infernal = new SkinEntity { Name = "Infernal", Description = "" }; + SkinEntity allStar = new SkinEntity { Name = "All-Star", Description = "" }; + SkinEntity justicar = new SkinEntity { Name = "Justicar", Description = "" }; + SkinEntity mecha = new SkinEntity { Name = "Mecha", Description = "" }; + SkinEntity seaHunter = new SkinEntity { Name = "Sea Hunter", Description = "" }; + + using (var context = new SkinContext()) + { + // Crée des Skins et les insère dans la base + Console.WriteLine("Creates and inserts new Skins"); + context.Add(stinger); + context.Add(infernal); + context.Add(allStar); + context.Add(justicar); + context.Add(mecha); + context.Add(seaHunter); + context.SaveChanges(); + Console.WriteLine("Creates and executes a query retrieving the first Skins of the database whose name starts with an \"I\":"); + var iSkin = context.Skin + .Where(s => s.Name.StartsWith("I")) + .First(); + Console.WriteLine($"{iSkin.Name} (with Description : {iSkin.Description}"); + + Console.WriteLine("Updates the name of the Infernal Skin"); + iSkin.Name = "Infernal of Hell (Wallah)"; + context.SaveChanges(); + Console.WriteLine($"{iSkin.Name} (with Description : {iSkin.Description}"); + + Console.WriteLine("Deletes one item from the database"); + var droid = context.Skin + .SingleOrDefault(s => s.Name.Equals("Infernal")); + context.Remove(droid); + context.SaveChanges(); + }*/ + } +} \ No newline at end of file diff --git a/Sources/StubLib/StubData.Champions.cs b/Sources/StubLib/StubData.Champions.cs index ad19275..8df8028 100644 --- a/Sources/StubLib/StubData.Champions.cs +++ b/Sources/StubLib/StubData.Champions.cs @@ -96,5 +96,4 @@ namespace StubLib => parent.champions.UpdateItem(oldItem, newItem); } } -} - +} \ No newline at end of file