master
Jolys Enzo 2 years ago
parent 559269fe82
commit 5ed4479c7d

@ -8,19 +8,22 @@ using EntityFramwork.Factories;
using Model;
using StubLib;
/*
StubData tmp = new StubData();
var tmpListe = await tmp.ChampionsMgr.GetItemsByName("Akali", 0, 6);
Champion champ = tmpListe.First();
Factories facto = new Factories();
EntityChampions entity = facto.ModelToEntity(champ);
EntityChampions entity = facto.ChampionModelToEntity(champ);
List<EntitySkins> skins = new List<EntitySkins>(entity.Skins);
using ( BDDContext context = new BDDContext())
using ( BDDContext db = new BDDContext())
{
context.Add(entity);
context.SaveChanges();
db.Add(entity);
db.SaveChanges();
}
*/
/*
Console.WriteLine("Start");
Console.ReadLine();
@ -40,4 +43,5 @@ DtoChampions champ2 = await client.GetChampion("toto");
Console.WriteLine(champ2.name);
Console.WriteLine("End");
Console.ReadLine();
Console.ReadLine();
*/

@ -8,6 +8,27 @@ namespace EntityFramwork
public BDDContext() { }
public BDDContext(DbContextOptions<BDDContext> option) : base(option) { }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
//création de la table Champion
modelBuilder.Entity<EntityChampions>().HasKey(a => a.Id);
modelBuilder.Entity<EntityChampions>().Property(a => a.Id)
.ValueGeneratedOnAdd();
//création de la table Skins
modelBuilder.Entity<EntitySkins>().HasKey(m => m.Id);
modelBuilder.Entity<EntitySkins>().Property(m => m.Id)
.ValueGeneratedOnAdd();
//modelBuilder.Entity<EntitySkins>().Property<int>("ChampionForeignKey");
// Use the shadow property as a foreign key
modelBuilder.Entity<EntitySkins>()
.HasOne(m => m.Champion)
.WithMany(a => a.Skins)
.HasForeignKey("ChampionsForeignKey");
}
public DbSet<EntityChampions> Champions { get; set; }
public DbSet<EntitySkins> Skins { get; set; }

@ -1,4 +1,5 @@
using Model;
using EntityFramwork;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
@ -9,7 +10,7 @@ namespace DTO
{
public class EntityChampions
{
public long Id { get; set; }
public int Id { get; set; }
public string Name { get; set; }
@ -17,7 +18,7 @@ namespace DTO
public string Icon { get; set; }
//public List<Skin> Skins { get; set; }
public List<EntitySkins> Skins { get; set; }
}
}

@ -11,16 +11,14 @@ namespace EntityFramwork
{
public class EntitySkins
{
public long Id { get; set; }
public int Id { get; set; }
public string Description { get; set; }
public string Icon { get; set; }
public float Price { get; set; }
public EntityChampions Champion { get; set; }
[ForeignKey("ChampionsForeignKey")]
public EntityChampions EntityChampion { get; set; }
public long ChampionsForeignKey { get;set; }
}
}

@ -5,14 +5,29 @@ namespace EntityFramwork.Factories
{
public class Factories
{
public EntityChampions ModelToEntity(Champion champ)
public EntityChampions ChampionModelToEntity(Champion champ,int sansSkin = 0)
{
EntityChampions entity = new EntityChampions();
entity.Name = champ.Name;
entity.Bio = champ.Bio;
entity.Icon = champ.Icon;
//entity.Skins = new List<Skin>(champ.Skins);
if ( sansSkin == 0)
{
entity.Skins = champ.Skins.Select(Model => this.SkinsModelToEntity(Model)).ToList();
}
return entity;
}
public EntitySkins SkinsModelToEntity(Skin skin)
{
EntitySkins entity= new EntitySkins();
entity.Price = skin.Price;
entity.Icon = skin.Icon;
entity.Description= skin.Description;
entity.Champion = ChampionModelToEntity(skin.Champion,1);
return entity;
}

@ -1,54 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFramwork.Migrations
{
/// <inheritdoc />
public partial class migrationTest : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Champions",
columns: table => new
{
Id = table.Column<long>(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);
});
migrationBuilder.CreateTable(
name: "Skins",
columns: table => new
{
Id = table.Column<long>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Description = table.Column<string>(type: "TEXT", nullable: false),
Icon = table.Column<string>(type: "TEXT", nullable: false),
Price = table.Column<float>(type: "REAL", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Skins", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Champions");
migrationBuilder.DropTable(
name: "Skins");
}
}
}

@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace EntityFramwork.Migrations
{
[DbContext(typeof(BDDContext))]
[Migration("20230201131800_migrationTest")]
partial class migrationTest
[Migration("20230204085418_TEST")]
partial class TEST
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -21,7 +21,7 @@ namespace EntityFramwork.Migrations
modelBuilder.Entity("DTO.EntityChampions", b =>
{
b.Property<long>("Id")
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
@ -44,10 +44,13 @@ namespace EntityFramwork.Migrations
modelBuilder.Entity("EntityFramwork.EntitySkins", b =>
{
b.Property<long>("Id")
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("ChampionsForeignKey")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
@ -61,8 +64,26 @@ namespace EntityFramwork.Migrations
b.HasKey("Id");
b.HasIndex("ChampionsForeignKey");
b.ToTable("Skins");
});
modelBuilder.Entity("EntityFramwork.EntitySkins", b =>
{
b.HasOne("DTO.EntityChampions", "Champion")
.WithMany("Skins")
.HasForeignKey("ChampionsForeignKey")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Champion");
});
modelBuilder.Entity("DTO.EntityChampions", b =>
{
b.Navigation("Skins");
});
#pragma warning restore 612, 618
}
}

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

@ -18,7 +18,7 @@ namespace EntityFramwork.Migrations
modelBuilder.Entity("DTO.EntityChampions", b =>
{
b.Property<long>("Id")
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
@ -41,10 +41,13 @@ namespace EntityFramwork.Migrations
modelBuilder.Entity("EntityFramwork.EntitySkins", b =>
{
b.Property<long>("Id")
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("ChampionsForeignKey")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
@ -58,8 +61,26 @@ namespace EntityFramwork.Migrations
b.HasKey("Id");
b.HasIndex("ChampionsForeignKey");
b.ToTable("Skins");
});
modelBuilder.Entity("EntityFramwork.EntitySkins", b =>
{
b.HasOne("DTO.EntityChampions", "Champion")
.WithMany("Skins")
.HasForeignKey("ChampionsForeignKey")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Champion");
});
modelBuilder.Entity("DTO.EntityChampions", b =>
{
b.Navigation("Skins");
});
#pragma warning restore 612, 618
}
}

Loading…
Cancel
Save