Merge branch 'master' of https://codefirst.iut.uca.fr/git/corentin.richard/EntityFramework_ConsoDeServices_TP into DevPF
continuous-integration/drone/push Build is passing Details

pull/38/head
Pierre Ferreira 2 years ago
commit 446d2d84a2

@ -40,9 +40,6 @@ Ce projet est decoupé en deux parties :
[![Build Status](https://codefirst.iut.uca.fr/api/badges/corentin.richard/EntityFramework_ConsoDeServices_TP/status.svg)](https://codefirst.iut.uca.fr/corentin.richard/EntityFramework_ConsoDeServices_TP)
#### Diagramme d'architechture :
=> Disponible à `./Diagramme d'architecture.jpg`
---
## :package: Entity FrameWork :construction_worker:
@ -86,12 +83,28 @@ Partie 2 :
Ajouter le paterne UnitOfWork (rollback en cas de probleme sur les transaction)
---
#### Diagramme d'architechture :
![](./docAsset/Diagramme%20d'architecture.jpg)
Le schéma ci-dessus décris l'architecture finale que doit avoir le projet,
Tout en haut, la partie client est composé du client MAUI et et du client Console, ceux-ci permettent l'affichage des ressources, l'utilisation de l'architecture et donc de tester si tout le projet fonctionne. Celui-ci utilise le HTTPDataManager qui lui permet d'effectuer les requêtes à l'API afin de récupérer les données. Il hérite de IDataManager et peux donc être remplacé par EFDataManager, court-circuitant ainsi l'API ou par StubLib, n'utilisant pas l'API et l'EF. Le DataManager utilise l'une des extensions mapper pour convertir les objets DTO en Model.
> On indique aux client d'utiliser le HttpDataManager :
builder.Services.AddScoped<IDataManager,HTTPDataManager>();
En second, la partie API, celle-ci s'occupe de recevoir les requêtes et de renvoyer les objet en conséquent. Dans l'implémentation idéale, l'API utilise l'EFDataManger pour faire appel aux données stockés en base de données. Il hérite lui aussi de IDataManager mais ne peut être remplacé que par le StubLib.Il utilise lui aussi des extensions mapper pour convertir les objets Entity en Model.
> On indique à l'API d'utiliser le EFDataManager :
builder.Services.AddScoped<IDataManager,EFDataManager>();
## Explication de ce qu'on a fait et ce qu'on a pas fait et pourquoi on a priorisé ca plutot que d'autre :
:construction:
:construction:
## Coordonnées :
``Corentin Richard`` : **[corentin.richard@etu.uca.fr](https://codefirst.iut.uca.fr/git/corentin.richard)**

@ -0,0 +1,186 @@
using API_LoL.Mapper;
using DTO;
using EntityFramework;
using Microsoft.AspNetCore.Mvc;
using Model;
namespace API_LoL.Controllers
{
[Route("api/v{version:apiVersion}/[controller]")]
[ApiController]
public class RunesController : ControllerBase
{
public RunesController(IDataManager Manager)
{
this.RunesManager = Manager.RunesMgr;
}
private IRunesManager RunesManager;
// GET api/<ChampionController>/5
[HttpGet("count")]
public async Task<IActionResult> GetCount()
{
return Ok(RunesManager.GetNbItems());
}
[HttpGet]
public async Task<IActionResult> Get(string? name = null, string desc = null, EnumRuneFamily Family = EnumRuneFamily.Unknown, LargeImage Image = null, int index = 0, int size = 10)
{
if (size - index > 10)
{
return BadRequest();
}
if (!string.IsNullOrEmpty(name))
{
var list = await RunesManager.GetItemsByName(name, index, size);
if (list.Count() != 0)
{
return Ok(list.Select(rune => rune?.ToDTO()));
}
else { return NoContent(); }
}
///else if peu important : on ne cherche pas des runes par famille ou description
//else if (!string.IsNullOrEmpty(desc))
//{
// var list = await RunesManager.GetItemsBySkill(desc, index, size);
// if (list.Count() != 0)
// {
// return Ok(list.Select(champion => champion?.ToDTO()));
// }
// else { return NoContent(); }
//}
//else if (!string.IsNullOrEmpty(Family))
//{
// var list = await RunesManager.GetItems(index, size);
// if (list.Count() != 0)
// {
// return Ok(list.Select(champion => champion?.ToDTO()));
// }
// else { return NoContent(); }
//}
//else if (!string.IsNullOrEmpty(Image))
//{
// var list = await RunesManager.GetItems(index, size);
// if (list.Count() != 0)
// {
// return Ok(list.Select(champion => champion?.ToDTO()));
// }
// else { return NoContent(); }
//}
else
{
var list = await RunesManager.GetItems(index, size);
if (list.Count() != 0)
{
return Ok(list.Select(champion => champion?.ToDTO()));
}
else { return NoContent(); }
}
}
[HttpGet("name")]
public async Task<IActionResult> GetByName(String name)
{
if (string.IsNullOrEmpty(name)) return BadRequest();
var list = await RunesManager.GetItemsByName(name, 0, 1);
if (list.Count() == 1)
{
return Ok(list.Select(rune => rune?.ToDTO()).First());
}
else { return NoContent(); }
}
//[HttpGet("name/skins")]
//public async Task<IActionResult> GetSkinsByName(String name)
//{
// if (string.IsNullOrEmpty(name)) return BadRequest();
// var list = await RunesManager.GetItemsByName(name, 0, 1);
// if (list.Count() == 1)
// {
// var nb = await SkinsManager.GetNbItemsByChampion(list.First());
// if (nb != 0)
// {
// var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, nb);
// return Ok(skins.Select(skin => skin?.ToDTO()));
// }
// else { return NoContent(); }
// }
// else { return NoContent(); }
//}
//[HttpGet("name/skills")]
//public async Task<IActionResult> GetSkillsByName(String name)
//{
// if (string.IsNullOrEmpty(name)) return BadRequest();
// var list = await RunesManager.GetItemsByName(name, 0, 1);
// if (list.Count() == 1)
// {
// var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, await SkinsManager.GetNbItemsByChampion(list.First()));
// if (skins.Count() != 0)
// {
// return Ok(skins.Select(skin => skin?.ToDTO()));
// }
// else { return NoContent(); }
// }
// else { return NoContent(); }
//}
// POST api/<ChampionController>
[HttpPost]
public async Task<IActionResult> Post(RuneDTO rune)
{
if (rune == null)
{
return UnprocessableEntity();
}
else
{
var champ = await RunesManager.GetItemsByName(rune.Name, 0, 1);
if (champ.Count() != 0 && champ.FirstOrDefault().Name == rune.Name)
{
return Conflict(rune);
}
await RunesManager.AddItem(rune.ToRune());
return CreatedAtAction("Post", rune);
}
}
// PUT api/<ChampionController>/5
[HttpPut("name")]
public async Task<IActionResult> Put(string name, RuneDTO rune)
{
if (string.IsNullOrEmpty(name))
return BadRequest();
if (rune == null)
return UnprocessableEntity();
var list = await RunesManager.GetItemsByName(name, 0, 1);
if (list.Count() == 1)
{
return Ok(RunesManager.UpdateItem(list.First(), rune.ToRune()));
}
else { return NoContent(); }
}
// DELETE api/<ChampionController>/5
[HttpDelete("name")]
public async Task<IActionResult> Delete(string name)
{
if (string.IsNullOrEmpty(name))
return BadRequest();
var list = await RunesManager.GetItemsByName(name, 0, 1);
if (list.Count() == 1)
{
return Ok(await RunesManager.DeleteItem(list.First()));
}
else { return NoContent(); }
}
}
}

@ -0,0 +1,19 @@
using DTO;
using Model;
namespace API_LoL.Mapper
{
public static class RuneMapper
{
public static RuneDTO ToDTO(this Rune rune)
{
return new RuneDTO(rune.Name, rune.Description, rune.Family, rune.Image, rune.Icon);
}
public static Rune ToRune(this RuneDTO rune)
{
return new Rune(rune.Name, rune.Family, rune.Icon, rune.Image.Base64, rune.Description);
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\EntityFramework\EntityFramework.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\StubLib\StubLib.csproj" />
</ItemGroup>

@ -0,0 +1,43 @@
using EntityFramework;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO
{
public class RuneDTO
{
public RuneDTO(string name, string desc, RuneFamily family, LargeImage image, string icon)
{
Name = name;
Description = desc;
Family = family;
Image = image;
Icon = icon;
}
public string Name { get; set; }
public string Description { get; set; }
public RuneFamily Family { get; set; }
public string Icon { get; set; }
public LargeImage Image { get; set; }
public bool equals(RuneDTO other)
{
return other.Name == Name
&& other.Description == Description
&& other.Family == Family
&& other.Image == Image
&& other.Icon == Icon;
}
public string toString()
{
return Name + Description + Family.ToString();
}
}
}

@ -13,8 +13,9 @@ namespace EntityFramework
public DbSet<SkinEntity> Skins { get; set; }
public DbSet<LargeImageEntity> Image { get; set; }
public DbSet<SkillEntity> Skills { get; set; }
public DbSet<LargeImageEntity> Image { get; set; }
public DbSet<RuneEntity> Rune { get; set; }
@ -46,7 +47,8 @@ namespace EntityFramework
modelBuilder.Entity<ChampionEntity>().Property(entity => entity.Name)
.IsRequired()
.HasMaxLength(50);
.HasMaxLength(50)
.ValueGeneratedOnAdd();
modelBuilder.Entity<ChampionEntity>().Property(entity => entity.Bio)
.HasMaxLength(500)
@ -76,11 +78,32 @@ namespace EntityFramework
.HasForeignKey("ChampionEntityForeignKey");
/// One to many
/// ChampionEntity ---> * SkillEntity
//création de la table ChampionEntity
//modelBuilder.Entity<ChampionEntity>().HasKey(c => c.Name); //définition de la clé primaire
//modelBuilder.Entity<ChampionEntity>().Property(c => c.Name)
// .ValueGeneratedOnAdd(); //définition du mode de génération de la clé : génération à l'insertion
//création de la table SkillEntity
modelBuilder.Entity<SkillEntity>().HasKey(s => s.Name); //définition de la clé primaire
modelBuilder.Entity<SkillEntity>().Property(s => s.Name)
.ValueGeneratedOnAdd(); //définition du mode de génération de la clé : génération à l'insertion
// Add the shadow property to the model
modelBuilder.Entity<SkillEntity>()
.Property<string>("ChampionEntityToSkillForeignKey");
// Use the shadow property as a foreign key
modelBuilder.Entity<SkillEntity>()
.HasOne(s => s.Champion)
.WithMany(c => c.Skills)
.HasForeignKey("ChampionEntityToSkillForeignKey");
// Many to Many ChampionEntity - RunePageEntity
modelBuilder.Entity<RuneEntity>().HasKey(entity => entity.Name);
/// Many to Many ChampionEntity - RunePageEntity
modelBuilder.Entity<RunePageEntity>().HasKey(entity => entity.Name);
modelBuilder.Entity<RunePageEntity>().HasKey(entity => entity.Name);
modelBuilder.Entity<RunePageEntity>().ToTable("RunePage");
@ -95,6 +118,23 @@ namespace EntityFramework
.HasMany(c => c.RunePageEntities)
.WithMany(r => r.Champion);
//.HasForeignKey("AlbumForeignKey");
//création de la table RuneEntity
modelBuilder.Entity<RuneEntity>().HasKey(r => r.Name); //définition de la clé primaire
modelBuilder.Entity<RuneEntity>().Property(r => r.Name)
.ValueGeneratedOnAdd(); //définition du mode de génération de la clé : génération à l'insertion
modelBuilder.Entity<RuneEntity>()
.Property<string>("RuneForeignKey");
modelBuilder.Entity<RuneEntity>()
.HasOne(r => r.RunePage)
.WithMany(rp => rp.Runes)
.HasForeignKey("RuneForeignKey");
}
}
}

@ -0,0 +1,225 @@
// <auto-generated />
using EntityFramework;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFramework.Migrations
{
[DbContext(typeof(LoLDbContext))]
[Migration("20230325150121_MigrSkill")]
partial class MigrSkill
{
/// <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>("ChampionName")
.HasColumnType("TEXT");
b.Property<string>("RunePageEntitiesName")
.HasColumnType("TEXT");
b.HasKey("ChampionName", "RunePageEntitiesName");
b.HasIndex("RunePageEntitiesName");
b.ToTable("ChampionEntityRunePageEntity");
});
modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Bio")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("string")
.HasColumnName("Bio");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Image")
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("Champions", (string)null);
});
modelBuilder.Entity("EntityFramework.LargeImageEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Base64")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Image");
});
modelBuilder.Entity("EntityFramework.RuneEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("RuneForeignKey")
.HasColumnType("TEXT");
b.HasKey("Name");
b.HasIndex("RuneForeignKey");
b.ToTable("Rune");
});
modelBuilder.Entity("EntityFramework.RunePageEntity", b =>
{
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("RuneName")
.HasColumnType("TEXT");
b.HasKey("Name");
b.HasIndex("RuneName");
b.ToTable("RunePage", (string)null);
});
modelBuilder.Entity("EntityFramework.SkillEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("ChampionEntityToSkillForeignKey")
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("Name");
b.HasIndex("ChampionEntityToSkillForeignKey");
b.ToTable("Skills");
});
modelBuilder.Entity("EntityFramework.SkinEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("ChampionEntityForeignKey")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Image")
.HasColumnType("TEXT");
b.Property<float>("Price")
.HasColumnType("REAL");
b.HasKey("Name");
b.HasIndex("ChampionEntityForeignKey");
b.ToTable("Skins");
});
modelBuilder.Entity("ChampionEntityRunePageEntity", b =>
{
b.HasOne("EntityFramework.ChampionEntity", null)
.WithMany()
.HasForeignKey("ChampionName")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("EntityFramework.RunePageEntity", null)
.WithMany()
.HasForeignKey("RunePageEntitiesName")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("EntityFramework.RuneEntity", b =>
{
b.HasOne("EntityFramework.RunePageEntity", "RunePage")
.WithMany("Runes")
.HasForeignKey("RuneForeignKey");
b.Navigation("RunePage");
});
modelBuilder.Entity("EntityFramework.RunePageEntity", b =>
{
b.HasOne("EntityFramework.RuneEntity", "Rune")
.WithMany()
.HasForeignKey("RuneName");
b.Navigation("Rune");
});
modelBuilder.Entity("EntityFramework.SkillEntity", b =>
{
b.HasOne("EntityFramework.ChampionEntity", "Champion")
.WithMany("Skills")
.HasForeignKey("ChampionEntityToSkillForeignKey");
b.Navigation("Champion");
});
modelBuilder.Entity("EntityFramework.SkinEntity", b =>
{
b.HasOne("EntityFramework.ChampionEntity", "Champion")
.WithMany("skins")
.HasForeignKey("ChampionEntityForeignKey");
b.Navigation("Champion");
});
modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
{
b.Navigation("Skills");
b.Navigation("skins");
});
modelBuilder.Entity("EntityFramework.RunePageEntity", b =>
{
b.Navigation("Runes");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,197 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFramework.Migrations
{
/// <inheritdoc />
public partial class MigrSkill : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Champions",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
Bio = table.Column<string>(type: "string", maxLength: 500, nullable: false),
Icon = table.Column<string>(type: "TEXT", nullable: false),
Image = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Champions", x => x.Name);
});
migrationBuilder.CreateTable(
name: "Image",
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_Image", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Skills",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", nullable: false),
Type = table.Column<int>(type: "INTEGER", nullable: false),
Description = table.Column<string>(type: "TEXT", nullable: false),
ChampionEntityToSkillForeignKey = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Skills", x => x.Name);
table.ForeignKey(
name: "FK_Skills_Champions_ChampionEntityToSkillForeignKey",
column: x => x.ChampionEntityToSkillForeignKey,
principalTable: "Champions",
principalColumn: "Name");
});
migrationBuilder.CreateTable(
name: "Skins",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", nullable: false),
Description = table.Column<string>(type: "TEXT", nullable: true),
Icon = table.Column<string>(type: "TEXT", nullable: false),
Image = table.Column<string>(type: "TEXT", nullable: true),
Price = table.Column<float>(type: "REAL", nullable: false),
ChampionEntityForeignKey = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Skins", x => x.Name);
table.ForeignKey(
name: "FK_Skins_Champions_ChampionEntityForeignKey",
column: x => x.ChampionEntityForeignKey,
principalTable: "Champions",
principalColumn: "Name");
});
migrationBuilder.CreateTable(
name: "ChampionEntityRunePageEntity",
columns: table => new
{
ChampionName = table.Column<string>(type: "TEXT", nullable: false),
RunePageEntitiesName = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ChampionEntityRunePageEntity", x => new { x.ChampionName, x.RunePageEntitiesName });
table.ForeignKey(
name: "FK_ChampionEntityRunePageEntity_Champions_ChampionName",
column: x => x.ChampionName,
principalTable: "Champions",
principalColumn: "Name",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Rune",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", nullable: false),
RuneForeignKey = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Rune", x => x.Name);
});
migrationBuilder.CreateTable(
name: "RunePage",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", nullable: false),
RuneName = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_RunePage", x => x.Name);
table.ForeignKey(
name: "FK_RunePage_Rune_RuneName",
column: x => x.RuneName,
principalTable: "Rune",
principalColumn: "Name");
});
migrationBuilder.CreateIndex(
name: "IX_ChampionEntityRunePageEntity_RunePageEntitiesName",
table: "ChampionEntityRunePageEntity",
column: "RunePageEntitiesName");
migrationBuilder.CreateIndex(
name: "IX_Rune_RuneForeignKey",
table: "Rune",
column: "RuneForeignKey");
migrationBuilder.CreateIndex(
name: "IX_RunePage_RuneName",
table: "RunePage",
column: "RuneName");
migrationBuilder.CreateIndex(
name: "IX_Skills_ChampionEntityToSkillForeignKey",
table: "Skills",
column: "ChampionEntityToSkillForeignKey");
migrationBuilder.CreateIndex(
name: "IX_Skins_ChampionEntityForeignKey",
table: "Skins",
column: "ChampionEntityForeignKey");
migrationBuilder.AddForeignKey(
name: "FK_ChampionEntityRunePageEntity_RunePage_RunePageEntitiesName",
table: "ChampionEntityRunePageEntity",
column: "RunePageEntitiesName",
principalTable: "RunePage",
principalColumn: "Name",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Rune_RunePage_RuneForeignKey",
table: "Rune",
column: "RuneForeignKey",
principalTable: "RunePage",
principalColumn: "Name");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Rune_RunePage_RuneForeignKey",
table: "Rune");
migrationBuilder.DropTable(
name: "ChampionEntityRunePageEntity");
migrationBuilder.DropTable(
name: "Image");
migrationBuilder.DropTable(
name: "Skills");
migrationBuilder.DropTable(
name: "Skins");
migrationBuilder.DropTable(
name: "Champions");
migrationBuilder.DropTable(
name: "RunePage");
migrationBuilder.DropTable(
name: "Rune");
}
}
}

@ -0,0 +1,222 @@
// <auto-generated />
using EntityFramework;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFramework.Migrations
{
[DbContext(typeof(LoLDbContext))]
partial class LoLDbContextModelSnapshot : 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>("ChampionName")
.HasColumnType("TEXT");
b.Property<string>("RunePageEntitiesName")
.HasColumnType("TEXT");
b.HasKey("ChampionName", "RunePageEntitiesName");
b.HasIndex("RunePageEntitiesName");
b.ToTable("ChampionEntityRunePageEntity");
});
modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("Bio")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("string")
.HasColumnName("Bio");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Image")
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("Champions", (string)null);
});
modelBuilder.Entity("EntityFramework.LargeImageEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Base64")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Image");
});
modelBuilder.Entity("EntityFramework.RuneEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("RuneForeignKey")
.HasColumnType("TEXT");
b.HasKey("Name");
b.HasIndex("RuneForeignKey");
b.ToTable("Rune");
});
modelBuilder.Entity("EntityFramework.RunePageEntity", b =>
{
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("RuneName")
.HasColumnType("TEXT");
b.HasKey("Name");
b.HasIndex("RuneName");
b.ToTable("RunePage", (string)null);
});
modelBuilder.Entity("EntityFramework.SkillEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("ChampionEntityToSkillForeignKey")
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("Name");
b.HasIndex("ChampionEntityToSkillForeignKey");
b.ToTable("Skills");
});
modelBuilder.Entity("EntityFramework.SkinEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("ChampionEntityForeignKey")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Image")
.HasColumnType("TEXT");
b.Property<float>("Price")
.HasColumnType("REAL");
b.HasKey("Name");
b.HasIndex("ChampionEntityForeignKey");
b.ToTable("Skins");
});
modelBuilder.Entity("ChampionEntityRunePageEntity", b =>
{
b.HasOne("EntityFramework.ChampionEntity", null)
.WithMany()
.HasForeignKey("ChampionName")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("EntityFramework.RunePageEntity", null)
.WithMany()
.HasForeignKey("RunePageEntitiesName")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("EntityFramework.RuneEntity", b =>
{
b.HasOne("EntityFramework.RunePageEntity", "RunePage")
.WithMany("Runes")
.HasForeignKey("RuneForeignKey");
b.Navigation("RunePage");
});
modelBuilder.Entity("EntityFramework.RunePageEntity", b =>
{
b.HasOne("EntityFramework.RuneEntity", "Rune")
.WithMany()
.HasForeignKey("RuneName");
b.Navigation("Rune");
});
modelBuilder.Entity("EntityFramework.SkillEntity", b =>
{
b.HasOne("EntityFramework.ChampionEntity", "Champion")
.WithMany("Skills")
.HasForeignKey("ChampionEntityToSkillForeignKey");
b.Navigation("Champion");
});
modelBuilder.Entity("EntityFramework.SkinEntity", b =>
{
b.HasOne("EntityFramework.ChampionEntity", "Champion")
.WithMany("skins")
.HasForeignKey("ChampionEntityForeignKey");
b.Navigation("Champion");
});
modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
{
b.Navigation("Skills");
b.Navigation("skins");
});
modelBuilder.Entity("EntityFramework.RunePageEntity", b =>
{
b.Navigation("Runes");
});
#pragma warning restore 612, 618
}
}
}

@ -38,64 +38,101 @@ using ( var context = new LoLDbContext())
context.SaveChanges();
IDataManager dataManager = new EFDataManager();
IChampionsManager championsManager = dataManager.ChampionsMgr;
IEnumerable<Champion?> champions = await championsManager.GetItemsByName("A", 0, 1);
Console.WriteLine(champions.First().Name);
//using ( var context = new LoLDbContext())
//{
// //context.Add(new ChampionEntity{ Name = "test", Bio = "test", Icon = "test" } );
// context.SaveChanges();
// ChampionEntity champ = context.Find<ChampionEntity>("Akali");
// if( champ != null)
// {
// Console
// .WriteLine(champ.ToString());
// }
// else
// {
// Console.WriteLine("Not Found");
// }
// //Test BDD Skills
// ChampionEntity champSkill = new ChampionEntity { Name="nomSkill", Bio="bioSkill", Icon="iconSkill" };
// //SkillEntity s1 = new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown };
// SkillEntity s2 = new SkillEntity { Name="Skill2", Description="desc2", Type=SkillType.Ultimate };
// SkillEntity s3 = new SkillEntity { Name = "Skill3", Description = "desc3", Type = SkillType.Passive };
// champSkill.AddSkill(new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown });
// champSkill.AddSkill(s2);
// champSkill.AddSkill(s3);
// context.Add(champSkill);
// context.SaveChanges();
IDataManager dataManager = new EFDataManager();
IChampionsManager championsManager = dataManager.ChampionsMgr;
IEnumerable<Champion?> champions = await championsManager.GetItemsByName("A", 0, 1);
//Console.WriteLine(champions.First().Name);
//using ( var context = new LoLDbContext())
//{
// //context.Add(new ChampionEntity{ Name = "test", Bio = "test", Icon = "test" } );
// context.SaveChanges();
// ChampionEntity champ = context.Find<ChampionEntity>("Akali");
// if( champ != null)
// {
// Console
// .WriteLine(champ.ToString());
// }
// else
// {
// Console.WriteLine("Not Found");
// }
// //Test BDD Skills
// ChampionEntity champSkill = new ChampionEntity { Name="nomSkill", Bio="bioSkill", Icon="iconSkill" };
// //SkillEntity s1 = new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown };
// SkillEntity s2 = new SkillEntity { Name="Skill2", Description="desc2", Type=SkillType.Ultimate };
// SkillEntity s3 = new SkillEntity { Name = "Skill3", Description = "desc3", Type = SkillType.Passive };
// champSkill.AddSkill(new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown });
// champSkill.AddSkill(s2);
// champSkill.AddSkill(s3);
// context.Add(champSkill);
// context.SaveChanges();
// //OneToMany
// Console.WriteLine("Champions : ");
// foreach (var champi in context.Champions.Include(a => a.skins))
// {
// Console.WriteLine($"\t{champi.Name} : {champi.Bio}");
// foreach (var s in champi.skins)
// {
// Console.WriteLine($"\t\t{s.Name}");
// }
// }
// Console.WriteLine();
// Console.WriteLine("Skin :");
// foreach (var s in context.Skins)
// {
// Console.WriteLine($"\t{s.Name}: {s.Description} (Champion : {s.Champion.Name})");
// }
Console.WriteLine("\nAjout d'un Champion et 6 Skins...\n");
ChampionEntity captainMarvel = new ChampionEntity { Name = "Captain Marvel", Bio = "Mais que fait un avenger ici ??", Icon = "Icon.png" };
SkinEntity[] skins = { new SkinEntity {Name = "La Fiesta", Champion = captainMarvel},
new SkinEntity { Name = "Five Hundred Miles High", Champion = captainMarvel },
new SkinEntity { Name = "Captain Marvel", Champion = captainMarvel },
new SkinEntity { Name = "Time's Lie", Champion = captainMarvel },
new SkinEntity { Name = "Lush Life", Champion = captainMarvel },
new SkinEntity { Name = "Day Waves", Champion = captainMarvel }
};
foreach (var s in skins)
{
captainMarvel.skins.Add(s);
}
context.Add(captainMarvel);
context.SaveChanges();
// //OneToMany
// Console.WriteLine("Champions : ");
// foreach (var champi in context.Champions.Include(a => a.skins))
// {
// Console.WriteLine($"\t{champi.Name} : {champi.Bio}");
// foreach (var s in champi.skins)
// {
// Console.WriteLine($"\t\t{s.Name}");
// }
// }
// Console.WriteLine();
//OnetoMany Skill
ChampionEntity Levram = new ChampionEntity { Name = "Captain Levram", Bio="bio", Icon="/img" };
SkillEntity[] morceaux = { new SkillEntity { Name = "La Fiesta", Description="SkillDesc", Type=EntityFramework.SkillType.Unknown, Champion= Levram },
new SkillEntity { Name = "berserk", Description="SkillDesc1", Type=EntityFramework.SkillType.Unknown, Champion= Levram },
new SkillEntity { Name = "taunt", Description = "SkillDesc2", Type = EntityFramework.SkillType.Unknown, Champion = Levram },
new SkillEntity { Name = "fear", Description = "SkillDesc3", Type = EntityFramework.SkillType.Unknown, Champion = Levram },
new SkillEntity { Name = "flashHeal", Description = "SkillDesc4", Type = EntityFramework.SkillType.Unknown, Champion = Levram },
new SkillEntity { Name = "bubbuletp", Description = "SkillDesc5", Type = EntityFramework.SkillType.Unknown, Champion = Levram }
};
foreach (var m in morceaux)
{
Levram.Skills.Add(m);
}
context.Add(Levram);
context.SaveChanges();
// Console.WriteLine("Skin :");
// foreach (var s in context.Skins)
// {
// Console.WriteLine($"\t{s.Name}: {s.Description} (Champion : {s.Champion.Name})");
// }
var r1 = new RuneEntity { Name = "Rune1", Description = "aaa", Family = EnumRuneFamily.Domination, Image = new LargeImage("base") };
@ -109,24 +146,4 @@ Console.WriteLine(champions.First().Name);
context.Champions.AddRange(new[] { corichard, pintrand });
context.RunePage.AddRange(new[] { rp1, rp2 });
context.SaveChanges();
}
// Console.WriteLine("\nAjout d'un Champion et 6 Skins...\n");
// ChampionEntity captainMarvel = new ChampionEntity { Name = "Captain Marvel", Bio="Mais que fait un avenger ici ??", Icon="Icon.png"};
// SkinEntity[] skins = { new SkinEntity {Name = "La Fiesta", Champion = captainMarvel},
// new SkinEntity { Name = "Five Hundred Miles High", Champion = captainMarvel },
// new SkinEntity { Name = "Captain Marvel", Champion = captainMarvel },
// new SkinEntity { Name = "Time's Lie", Champion = captainMarvel },
// new SkinEntity { Name = "Lush Life", Champion = captainMarvel },
// new SkinEntity { Name = "Day Waves", Champion = captainMarvel }
// };
// foreach (var s in skins)
// {
// captainMarvel.skins.Add(s);
// }
// context.Add(captainMarvel);
// context.SaveChanges();
//}
}

@ -20,5 +20,9 @@ namespace EntityFramework
public EnumRuneFamily Family;
public LargeImage Image;
//OtM
public RunePageEntity RunePage { get; set; }
}
}

@ -1,4 +1,5 @@
using System;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
@ -16,7 +17,11 @@ namespace EntityFramework
public RuneEntity? Rune { get; set; }
//? voir si cela pause probleme
public Dictionary<EnumCategory, Rune> Dico = new Dictionary<EnumCategory, Rune>();
//public Dictionary<EnumCategory, Rune> Dico = new Dictionary<EnumCategory, Rune>();
// One to many pour l'instant, voir si on retransforme en dico :
public ICollection<RuneEntity> Runes { get; set; }
// Pour le many to many Champion *<---->* RunePage
public ICollection<ChampionEntity> Champion{ get; set; }

@ -49,5 +49,9 @@ namespace EntityFramework
// this.Description = Description;
// this.Type = Type;
//}
// One to many with champion :
public ChampionEntity Champion { get; set; }
}
}

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -8,7 +9,8 @@ namespace EntityFramework
{
public class SkinEntity //ONE TO MANY
{
[Key]
public string? Name { get; set; }
public string? Description { get; set; }

@ -42,10 +42,43 @@ namespace EntityFramework
new { Name = "ruby", ChampionEntityForeignKey = "Pintrand", Description = "So What", Icon = "/Icon.png", Price = 10.0f }
);
//Skills
modelBuilder.Entity<SkillEntity>().HasData(new { Name="Skill", Description="Desc", Type= SkillType.Basic, ChampionEntityToSkillForeignKey= "Corichard" },
new { Name = "Skill2", Description = "Desc", Type = SkillType.Basic, ChampionEntityToSkillForeignKey = "Corichard" },
new { Name = "Skill3", Description = "Desc", Type = SkillType.Passive, ChampionEntityToSkillForeignKey = "Corichard" },
new { Name = "Skill4", Description = "Desc", Type = SkillType.Unknown, ChampionEntityToSkillForeignKey = "Corichard" },
new { Name = "Skill5", Description = "Desc", Type = SkillType.Basic, ChampionEntityToSkillForeignKey = "Corichard" },
new { Name = "Skill6", Description = "Desc", Type = SkillType.Basic, ChampionEntityToSkillForeignKey = "Corichard" },
new { Name = "Skill10", Description = "Desc", Type = SkillType.Basic, ChampionEntityToSkillForeignKey = "Pintrand" },
new { Name = "Skill11", Description = "Desc", Type = SkillType.Unknown, ChampionEntityToSkillForeignKey = "Pintrand" },
new { Name = "Skill12", Description = "Desc", Type = SkillType.Passive, ChampionEntityToSkillForeignKey = "Pintrand" },
new { Name = "Skill13", Description = "Desc", Type = SkillType.Basic, ChampionEntityToSkillForeignKey = "Pintrand" },
new { Name = "Skill14", Description = "Desc", Type = SkillType.Basic, ChampionEntityToSkillForeignKey = "Pintrand" }
);
modelBuilder.Entity<RunePageEntity>().HasData(new { Name = "RP1", Rune = r1, Champion = corichard},
new { Name = "RP2", Rune = r2, Champion = pintrand}
);
RunePageEntity rp11 = new RunePageEntity { Name = "rp11"};
RunePageEntity rp21 = new RunePageEntity { Name = "rp21"};
modelBuilder.Entity<RunePageEntity>().HasData(rp11, rp21);
modelBuilder.Entity<RuneEntity>().HasData(new { Name = "Rune", Description = "Desc", Famille = EnumRuneFamily.Domination, RuneForeignKey = "rp11" },
new{Name = "Rune2", Description = "Desc",Famille = EnumRuneFamily.Domination,RuneForeignKey = "rp11"},
new { Name = "Rune3", Description = "Desc", Famille = EnumRuneFamily.Domination, RuneForeignKey = "rp21" },
new { Name = "Rune4", Description = "Desc", Famille = EnumRuneFamily.Domination, RuneForeignKey = "rp21" }
);
}
}
}

@ -1,4 +1,6 @@
using Model;
using DTO;
using DTO.Mapper;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
@ -34,20 +36,22 @@ namespace HttpClient
public async Task<Champion?> AddItem(Champion? item) //return le champion ajouté, null sinon ?
{
if(item==null) throw new ArgumentNullException("item is null");
var response = await httpc.PostAsJsonAsync("/Champion?Name = " + item.Name, item);
var response = await httpc.PostAsJsonAsync("v1/Champions?Name = " + item.Name, item);
return response.IsSuccessStatusCode ? item : null;
}
public async Task<bool> DeleteItem(Champion? item)
{
HttpResponseMessage response = await httpc.DeleteAsync("/Champion?Name=" + item.Name);
HttpResponseMessage response = await httpc.DeleteAsync("v1/Champions?Name=" + item.Name);
return response.IsSuccessStatusCode;
}
public Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
public async Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return httpc.GetFromJsonAsync<IEnumerable<Champion>>("/Champion?index="+index+"&size="+count);
IEnumerable<ChampionDTO> champdto = await httpc.GetFromJsonAsync<IEnumerable<ChampionDTO>>("v1/Champions?index="+index+"&size="+count);
return champdto.Select(c => c.ToChampion());
}

@ -8,8 +8,6 @@ namespace HttpClient
public System.Net.Http.HttpClient httpC { get; set; } = new System.Net.Http.HttpClient();
public string BaseAddress;
public HttpClientManager() {
ChampionsMgr = new ChampionManager(this, httpC);

@ -26,7 +26,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Api_UT", "Api_UT\Api_UT.csp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EF_UT", "EF_UT\EF_UT.csproj", "{74F469C3-A94A-4507-9DC7-7DBADCD18173}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClient", "HttpClient\HttpClient.csproj", "{DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpClient", "HttpClient\HttpClient.csproj", "{DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Client", "Client", "{6570AF99-3E74-4CAA-AEB0-EEFE4F79780F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApplication", "ConsoleApplication\ConsoleApplication.csproj", "{53A195F7-FB7C-44E8-AB82-4D775C7D9477}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -70,6 +74,10 @@ Global
{DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}.Release|Any CPU.Build.0 = Release|Any CPU
{53A195F7-FB7C-44E8-AB82-4D775C7D9477}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{53A195F7-FB7C-44E8-AB82-4D775C7D9477}.Debug|Any CPU.Build.0 = Debug|Any CPU
{53A195F7-FB7C-44E8-AB82-4D775C7D9477}.Release|Any CPU.ActiveCfg = Release|Any CPU
{53A195F7-FB7C-44E8-AB82-4D775C7D9477}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -78,6 +86,7 @@ Global
{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {2C607793-B163-4731-A4D1-AFE8A7C4C170}
{20A1A7DC-1E93-4506-BD32-8597A5DADD7B} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}
{74F469C3-A94A-4507-9DC7-7DBADCD18173} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}
{53A195F7-FB7C-44E8-AB82-4D775C7D9477} = {6570AF99-3E74-4CAA-AEB0-EEFE4F79780F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 MiB

Loading…
Cancel
Save