Adding One Champion To Many Skins

pull/1/head
Arthur VALIN 2 years ago
parent 22ed13d535
commit ee739ed478

@ -1,9 +1,13 @@
using Microsoft.EntityFrameworkCore;
using Shared;
using System.Security.Claims;
using System.Xml.Linq;
namespace Entities
{
public class ChampionDbContext : DbContext
{
public DbSet<SkinEntity> skins { get; set; }
public DbSet<ChampionEntity> champions { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
@ -13,17 +17,39 @@ namespace Entities
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ChampionEntity>().HasData(new List<ChampionEntity>() {
new ChampionEntity
new()
{
Name = "Dave",
Bio = "Le meilleur Jazzman de France",
Class = ChampionClass.Fighter
},
new ChampionEntity
new()
{
Name = "Armure",
Name = "Armure",
Bio = "Solide",
Class = ChampionClass.Tank
}
});
modelBuilder.Entity<SkinEntity>().HasData(new List<SkinEntity>() {
new SkinEntity
{
Name = "Dave de glace",
Description = "Enneigé",
Icon = "aaa",
ChampionForeignKey = "Dave",
Price=7.99F
},
new SkinEntity
{
Name = "Armure Fullspeed",
Description = "Deja vu",
Icon = "aaa",
ChampionForeignKey = "Armure",
Price=9.99F
},
});
}
}
}

@ -1,15 +1,18 @@
using System.ComponentModel.DataAnnotations;
using Shared;
using System.ComponentModel.DataAnnotations;
namespace Entities
{
public class ChampionEntity
{
[Key]
[MaxLength(256)]
public string? Name { get; set; }
public string Name { get; set; }
[Required]
[MaxLength(500)]
public string Bio { get; set; }
public string? Icon { get; set; }
[Required]
public ChampionClass Class { get; set;}
}
}

@ -21,4 +21,8 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project>

@ -1,55 +0,0 @@
// <auto-generated />
using Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Entities.Migrations
{
[DbContext(typeof(ChampionDbContext))]
[Migration("20230204100209_myFirstMigration")]
partial class myFirstMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("Entities.ChampionEntity", b =>
{
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("Bio")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("Icon")
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("champions");
b.HasData(
new
{
Name = "Dave",
Bio = "Le meilleur Jazzman de France"
},
new
{
Name = "Armure",
Bio = "Solide"
});
});
#pragma warning restore 612, 618
}
}
}

@ -1,45 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace Entities.Migrations
{
/// <inheritdoc />
public partial class myFirstMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
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: true)
},
constraints: table =>
{
table.PrimaryKey("PK_champions", x => x.Name);
});
migrationBuilder.InsertData(
table: "champions",
columns: new[] { "Name", "Bio", "Icon" },
values: new object[,]
{
{ "Armure", "Solide", null },
{ "Dave", "Le meilleur Jazzman de France", null }
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "champions");
}
}
}

@ -0,0 +1,118 @@
// <auto-generated />
using Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Entities.Migrations
{
[DbContext(typeof(ChampionDbContext))]
[Migration("20230204105739_myFirstMigration")]
partial class myFirstMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("Entities.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")
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("champions");
b.HasData(
new
{
Name = "Dave",
Bio = "Le meilleur Jazzman de France",
Class = 2
},
new
{
Name = "Armure",
Bio = "Solide",
Class = 6
});
});
modelBuilder.Entity("Entities.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<float>("Price")
.HasColumnType("REAL");
b.HasKey("Name");
b.HasIndex("ChampionForeignKey");
b.ToTable("skins");
b.HasData(
new
{
Name = "Dave de glace",
ChampionForeignKey = "Dave",
Description = "Enneigé",
Icon = "aaa",
Price = 7.99f
},
new
{
Name = "Armure Fullspeed",
ChampionForeignKey = "Armure",
Description = "Deja vu",
Icon = "aaa",
Price = 9.99f
});
});
modelBuilder.Entity("Entities.SkinEntity", b =>
{
b.HasOne("Entities.ChampionEntity", "Champion")
.WithMany()
.HasForeignKey("ChampionForeignKey")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Champion");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,84 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace Entities.Migrations
{
/// <inheritdoc />
public partial class myFirstMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
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: true),
Class = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_champions", x => x.Name);
});
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)
},
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);
});
migrationBuilder.InsertData(
table: "champions",
columns: new[] { "Name", "Bio", "Class", "Icon" },
values: new object[,]
{
{ "Armure", "Solide", 6, null },
{ "Dave", "Le meilleur Jazzman de France", 2, null }
});
migrationBuilder.InsertData(
table: "skins",
columns: new[] { "Name", "ChampionForeignKey", "Description", "Icon", "Price" },
values: new object[,]
{
{ "Armure Fullspeed", "Armure", "Deja vu", "aaa", 9.99f },
{ "Dave de glace", "Dave", "Enneigé", "aaa", 7.99f }
});
migrationBuilder.CreateIndex(
name: "IX_skins_ChampionForeignKey",
table: "skins",
column: "ChampionForeignKey");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "skins");
migrationBuilder.DropTable(
name: "champions");
}
}
}

@ -27,6 +27,9 @@ namespace Entities.Migrations
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<int>("Class")
.HasColumnType("INTEGER");
b.Property<string>("Icon")
.HasColumnType("TEXT");
@ -38,14 +41,74 @@ namespace Entities.Migrations
new
{
Name = "Dave",
Bio = "Le meilleur Jazzman de France"
Bio = "Le meilleur Jazzman de France",
Class = 2
},
new
{
Name = "Armure",
Bio = "Solide"
Bio = "Solide",
Class = 6
});
});
modelBuilder.Entity("Entities.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<float>("Price")
.HasColumnType("REAL");
b.HasKey("Name");
b.HasIndex("ChampionForeignKey");
b.ToTable("skins");
b.HasData(
new
{
Name = "Dave de glace",
ChampionForeignKey = "Dave",
Description = "Enneigé",
Icon = "aaa",
Price = 7.99f
},
new
{
Name = "Armure Fullspeed",
ChampionForeignKey = "Armure",
Description = "Deja vu",
Icon = "aaa",
Price = 9.99f
});
});
modelBuilder.Entity("Entities.SkinEntity", b =>
{
b.HasOne("Entities.ChampionEntity", "Champion")
.WithMany()
.HasForeignKey("ChampionForeignKey")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Champion");
});
#pragma warning restore 612, 618
}
}

@ -1,14 +1,16 @@
using Entities;
using Shared;
ChampionEntity dave = new()
ChampionEntity imri = new()
{
Name = "Imri Cartel",
Bio = "Fou Furieux",
Class = ChampionClass.Assassin
};
using (var context = new ChampionDbContext())
{
// Crée des nounours et les insère dans la base
Console.WriteLine("Creates and inserts new Champion");
context.Add(dave);
context.Add(imri);
context.SaveChanges();
}

@ -0,0 +1,32 @@
using Shared;
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 Entities
{
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; }
}
}

@ -1,4 +1,5 @@
using System.Collections.Immutable;
using Shared;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.Numerics;
using System.Text;

@ -9,9 +9,6 @@
<ItemGroup>
<None Remove="enums\" />
</ItemGroup>
<ItemGroup>
<Folder Include="enums\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>

@ -1,4 +1,4 @@
using System;
using Shared;
namespace Model
{

@ -1,4 +1,4 @@
using System;
using Shared;
using System.Collections.ObjectModel;
namespace Model

@ -1,4 +1,4 @@
using System;
using Shared;
namespace Model
{

@ -1,5 +1,4 @@
using System;
namespace Model
namespace Shared
{
public enum ChampionClass
{

@ -1,5 +1,4 @@
using System;
namespace Model
namespace Shared
{
public enum RuneFamily
{

@ -1,8 +1,5 @@
using System;
namespace Model
namespace Shared
{
public partial class RunePage
{
public enum Category
{
Major,
@ -12,6 +9,5 @@ namespace Model
OtherMinor1,
OtherMinor2
}
}
}

@ -1,5 +1,4 @@
using System;
namespace Model
namespace Shared
{
public enum SkillType
{

@ -1,5 +1,6 @@
using System;
using Model;
using Shared;
namespace StubLib
{

@ -1,5 +1,6 @@
using System;
using Model;
using Shared;
namespace StubLib
{

@ -2,6 +2,7 @@
using System.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using Model;
using Shared;
using StubLib;
using static System.Console;

Loading…
Cancel
Save