Merge pull request 'Arthur_EF_Business' (#2) from Arthur_EF_Business into master

Reviewed-on: #2
David_next_step
David D'ALMEIDA 2 years ago
commit f7b85e8e5d

@ -12,6 +12,7 @@
<ItemGroup>
<ProjectReference Include="..\DTO\DTO.csproj" />
<ProjectReference Include="..\Entities\Entities.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\StubLib\StubLib.csproj" />
</ItemGroup>

@ -21,7 +21,7 @@ namespace API_LoL_Project.Controllers
{
var champions = await dataManager.GetItems(0, await dataManager.GetNbItems());
return Ok(new { result = champions.Select(c => c.toDTO())});
return Ok(new { result = champions.Select(c => c.ToDTO())});
}
@ -32,14 +32,14 @@ namespace API_LoL_Project.Controllers
var champion = await dataManager
.GetItemsByName(name, 0, await dataManager.GetNbItems());
return Ok(new { result = champion.First().toDTO() });
return Ok(new { result = champion.First().ToDTO() });
}
// POST api/<ChampionController>
[HttpPost]
public async Task<IActionResult> Post([FromBody] ChampionDTO value)
{
await dataManager.AddItem(value.toModel());
await dataManager.AddItem(value.ToModel());
return Ok();
}
@ -50,7 +50,7 @@ namespace API_LoL_Project.Controllers
{
var champion = await dataManager
.GetItemsByName(name, 0, await dataManager.GetNbItems());
await dataManager.UpdateItem(champion.First(), value.toModel());
await dataManager.UpdateItem(champion.First(), value.ToModel());
return Ok();
}

@ -1,21 +1,39 @@
using DTO;
using Entities;
using Model;
namespace API_LoL_Project.Mapper
{
public static class ChampionMapper
{
public static ChampionDTO toDTO(this Champion item)
public static class ChampionMapper {
public static ChampionDTO ToDTO(this Champion item)
{
return new ChampionDTO() {
return new() {
Name = item.Name,
Bio = item.Bio
};
}
public static Champion toModel(this ChampionDTO dto)
public static ChampionEntity ToEntity(this Champion item)
{
return new Champion(dto.Name);
return new()
{
Name = item.Name,
Bio = item.Bio,
Icon = item.Icon,
Class = item.Class,
Image = new() { Base64 = item.Image.Base64 },
};
}
public static Champion ToModel(this ChampionDTO dto)
{
return new(dto.Name);
}
public static Champion ToModel(this ChampionEntity entity)
{
return new(entity.Name, entity.Class, entity.Icon, entity.Image.Base64, entity.Bio);
}
}

@ -0,0 +1,27 @@
namespace API_LoL_Project.Mapper
{
using DTO;
using Entities;
using Model;
namespace API_LoL_Project.Mapper
{
public static class RuneMapper
{
public static RuneEntity ToEntity(this Rune item)
{
throw new NotImplementedException();
}
public static Rune ToModel(this RuneEntity entity)
{
throw new NotImplementedException();
}
}
}
}
}

@ -0,0 +1,19 @@
using Entities;
using Model;
namespace API_LoL_Project.Mapper
{
public static class RunePageMapper
{
public static RunePageEntity ToEntity(this RunePage item)
{
throw new NotImplementedException();
}
public static RunePage ToModel(this RunePageEntity entity)
{
throw new NotImplementedException();
}
}
}

@ -0,0 +1,23 @@
using DTO;
using Entities;
using Model;
namespace API_LoL_Project.Mapper
{
public static class SkinMapper
{
public static SkinEntity ToEntity(this Skin item)
{
throw new NotImplementedException();
}
public static Skin ToModel(this SkinEntity entity)
{
throw new NotImplementedException();
}
}
}
}

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\API_LoL_Project\API_LoL_Project.csproj" />
<ProjectReference Include="..\Entities\Entities.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,136 @@
using API_LoL_Project.Mapper;
using Model;
using Shared;
using System.Data.SqlTypes;
namespace Business
{
public partial class DbData
{
public class ChampionsManager : IChampionsManager
{
private readonly DbData parent;
public ChampionsManager(DbData parent)
=> this.parent = parent;
public async Task<Champion?> AddItem(Champion? item)
{
await parent.DbContext.champions.AddAsync(item.ToEntity());
return item;
}
public async Task<bool> DeleteItem(Champion? item)
{
parent.DbContext.champions.Remove(item.ToEntity());
return true;
}
public async Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return parent.DbContext.champions.GetItemsWithFilterAndOrdering(
c => true,
index, count,
orderingPropertyName, descending).Select(c => c.ToModel());
}
public async Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return parent.DbContext.champions.GetItemsWithFilterAndOrdering(
c => c.Characteristics.Any(ch => ch.Name.Equals(charName)),
index, count,
orderingPropertyName, descending).Select(c => c.ToModel());
}
public async Task<IEnumerable<Champion?>> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return parent.DbContext.champions.GetItemsWithFilterAndOrdering(
c => c.Class.Equals(championClass),
index, count,
orderingPropertyName, descending).Select(c => c.ToModel());
}
public async Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return parent.DbContext.champions.GetItemsWithFilterAndOrdering(
c => c.Name.Contains(substring),
index, count,
orderingPropertyName, descending).Select(c => c.ToModel());
}
public async Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return parent.DbContext.champions.GetItemsWithFilterAndOrdering(
c => c.runepages.Any(rp => rp.Equals(runePage.ToEntity())),
index, count,
orderingPropertyName, descending).Select(c => c.ToModel());
}
public async Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return parent.DbContext.champions.GetItemsWithFilterAndOrdering(
c => skill != null && c.Skills.Any(s => s.Name.Equals(skill.Name)),
index, count,
orderingPropertyName, descending).Select(c => c.ToModel());
}
public async Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return parent.DbContext.champions.GetItemsWithFilterAndOrdering(
c => skill != null && c.Skills.Any(s => s.Name.Equals(skill)),
index, count,
orderingPropertyName, descending).Select(c => c.ToModel());
}
public async Task<int> GetNbItems()
{
return parent.DbContext.champions.Count();
}
public async Task<int> GetNbItemsByCharacteristic(string charName)
{
return parent.DbContext.champions.Where(c => c.Characteristics.Any(ch => ch.Name.Equals(charName))).Count();
}
public async Task<int> GetNbItemsByClass(ChampionClass championClass)
{
return parent.DbContext.champions.Where(c => c.Class.Equals(championClass))
.Count();
}
public async Task<int> GetNbItemsByName(string substring)
{
return parent.DbContext.champions.Where(c => c.Name.Contains(substring))
.Count();
}
public async Task<int> GetNbItemsByRunePage(RunePage? runePage)
{
return parent.DbContext.champions.Where(c => c.runepages.Any(rp => rp.Equals(runePage.ToEntity()))).Count();
}
public async Task<int> GetNbItemsBySkill(Skill? skill)
{
return parent.DbContext.champions.Where(c => skill != null && c.Skills.Any(s => s.Name.Equals(skill.Name)))
.Count();
}
public async Task<int> GetNbItemsBySkill(string skill)
{
return parent.DbContext.champions.Where(c => skill != null && c.Skills.Any(s => s.Name.Equals(skill)))
.Count();
}
public async Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
{
parent.DbContext.champions.Remove(oldItem.ToEntity());
parent.DbContext.champions.Add(newItem.ToEntity());
return newItem;
}
}
}
}

@ -0,0 +1,91 @@
using API_LoL_Project.Mapper;
using Model;
using System.Data.SqlTypes;
using System.Linq;
namespace Business
{
public partial class DbData
{
public class RunePagesManager : IRunePagesManager
{
private readonly DbData parent;
public RunePagesManager(DbData parent)
=> this.parent = parent;
public async Task<RunePage?> AddItem(RunePage? item)
{
await parent.DbContext.runepages.AddAsync(item.ToEntity());
return item;
}
public async Task<bool> DeleteItem(RunePage? item)
{
parent.DbContext.runepages.Remove(item.ToEntity());
return true;
}
public async Task<IEnumerable<RunePage?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return parent.DbContext.runepages.GetItemsWithFilterAndOrdering(
rp => true,
index, count,
orderingPropertyName, descending).Select(rp => rp.ToModel());
}
public async Task<IEnumerable<RunePage?>> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return parent.DbContext.runepages.GetItemsWithFilterAndOrdering(
rp => rp.champions.Any(c => c.Name.Equals(champion.Name)),
index, count,
orderingPropertyName, descending).Select(rp => rp.ToModel());
}
public async Task<IEnumerable<RunePage?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return parent.DbContext.runepages.GetItemsWithFilterAndOrdering(
rp => rp.Name.Contains(substring),
index, count,
orderingPropertyName, descending).Select(rp => rp.ToModel());
}
public async Task<IEnumerable<RunePage?>> GetItemsByRune(Rune? rune, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return parent.DbContext.runepages.GetItemsWithFilterAndOrdering(
rp => rp.runes.Any(r => r.Name.Equals(rune.Name)),
index, count,
orderingPropertyName, descending).Select(rp => rp.ToModel());
}
public async Task<int> GetNbItems()
{
return parent.DbContext.runepages.Count();
}
public async Task<int> GetNbItemsByChampion(Champion? champion)
{
return parent.DbContext.runepages.Where(rp => rp.champions.Any(c => c.Name.Equals(champion.Name))).Count();
}
public async Task<int> GetNbItemsByName(string substring)
{
return parent.DbContext.runepages.Where(rp => rp.Name.Contains(substring)).Count();
}
public async Task<int> GetNbItemsByRune(Model.Rune? rune)
{
return parent.DbContext.runepages.Where(rp => rp.runes.Any(r => r.Name.Equals(rune.Name))).Count();
}
public async Task<RunePage?> UpdateItem(RunePage? oldItem, RunePage? newItem)
{
parent.DbContext.runepages.Remove(oldItem.ToEntity());
parent.DbContext.runepages.Add(newItem.ToEntity());
return newItem;
}
}
}
}

@ -0,0 +1,75 @@
using API_LoL_Project.Mapper;
using API_LoL_Project.Mapper.API_LoL_Project.Mapper;
using Model;
using Shared;
namespace Business
{
public partial class DbData
{
public class RunesManager : IRunesManager
{
private readonly DbData parent;
public RunesManager(DbData parent)
=> this.parent = parent;
public async Task<Rune?> AddItem(Rune? item)
{
await parent.DbContext.runes.AddAsync(item.ToEntity());
return item;
}
public async Task<bool> DeleteItem(Rune? item)
{
parent.DbContext.runes.Remove(item.ToEntity());
return true;
}
public async Task<IEnumerable<Rune?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return parent.DbContext.runes.GetItemsWithFilterAndOrdering(
r => true,
index, count,
orderingPropertyName, descending).Select(r => r.ToModel());
}
public async Task<IEnumerable<Rune?>> GetItemsByFamily(RuneFamily family, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return parent.DbContext.runes.GetItemsWithFilterAndOrdering(
r => r.RuneFamily.Equals(family),
index, count,
orderingPropertyName, descending).Select(r => r.ToModel());
}
public async Task<IEnumerable<Rune?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return parent.DbContext.runes.GetItemsWithFilterAndOrdering(
r => r.Name.Contains(substring),
index, count,
orderingPropertyName, descending).Select(r => r.ToModel());
}
public async Task<int> GetNbItems()
{
return parent.DbContext.runes.Count();
}
public async Task<int> GetNbItemsByFamily(RuneFamily family)
{
return parent.DbContext.runes.Where(r => r.RuneFamily.Equals(family)).Count();
}
public async Task<int> GetNbItemsByName(string substring)
{
return parent.DbContext.runes.Where(r => r.Name.Contains(substring)).Count();
}
public async Task<Rune?> UpdateItem(Rune? oldItem, Rune? newItem)
{
parent.DbContext.runes.Remove(oldItem.ToEntity());
parent.DbContext.runes.Add(newItem.ToEntity());
return newItem;
}
}
}
}

@ -0,0 +1,78 @@
using API_LoL_Project.Mapper;
using API_LoL_Project.Mapper.API_LoL_Project.Mapper;
using Model;
using System.Data.SqlTypes;
namespace Business
{
public partial class DbData
{
public class SkinsManager : ISkinsManager
{
private readonly DbData parent;
public SkinsManager(DbData parent)
=> this.parent = parent;
public async Task<Skin?> AddItem(Skin? item)
{
await parent.DbContext.skins.AddAsync(item.ToEntity());
return item;
}
public async Task<bool> DeleteItem(Skin? item)
{
parent.DbContext.skins.Remove(item.ToEntity());
return true;
}
public async Task<IEnumerable<Skin?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return parent.DbContext.skins.GetItemsWithFilterAndOrdering(
s => true,
index, count,
orderingPropertyName, descending).Select(s => s.ToModel());
}
public async Task<IEnumerable<Skin?>> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return parent.DbContext.skins.GetItemsWithFilterAndOrdering(
s => s.Champion.Name.Equals(champion.Name),
index, count,
orderingPropertyName, descending).Select(s => s.ToModel());
}
public async Task<IEnumerable<Skin?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
return parent.DbContext.skins.GetItemsWithFilterAndOrdering(
s => s.Name.Contains(substring),
index, count,
orderingPropertyName, descending).Select(s => s.ToModel());
}
public async Task<int> GetNbItems()
{
return parent.DbContext.skins.Count();
}
public async Task<int> GetNbItemsByChampion(Champion? champion)
{
return parent.DbContext.skins.Where(s => s.Champion.Name.Equals(champion.Name))
.Count();
}
public async Task<int> GetNbItemsByName(string substring)
{
return parent.DbContext.skins.Where(s => s.Name.Contains(substring))
.Count();
}
public async Task<Skin?> UpdateItem(Skin? oldItem, Skin? newItem)
{
parent.DbContext.skins.Remove(oldItem.ToEntity());
parent.DbContext.skins.Add(newItem.ToEntity());
return newItem;
}
}
}
}

@ -0,0 +1,28 @@
using Entities;
using Microsoft.EntityFrameworkCore;
using Model;
namespace Business
{
public partial class DbData : IDataManager
{
public DbData(LolDbContext dbContext)
{
DbContext = dbContext;
ChampionsMgr = new ChampionsManager(this);
SkinsMgr = new SkinsManager(this);
RunesMgr = new RunesManager(this);
RunePagesMgr = new RunePagesManager(this);
}
protected LolDbContext DbContext{ get; }
public IChampionsManager ChampionsMgr { get; }
public ISkinsManager SkinsMgr { get; }
public IRunesManager RunesMgr { get; }
public IRunePagesManager RunePagesMgr { get; }
}
}

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Business
{
static class Extensions
{
internal static IEnumerable<T?> GetItemsWithFilterAndOrdering<T>(this IEnumerable<T> collection,
Func<T, bool> filter, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
IEnumerable<T> temp = collection;
temp = temp.Where(item => filter(item));
if (orderingPropertyName != null)
{
var prop = typeof(T).GetProperty(orderingPropertyName!);
if (prop != null)
{
temp = descending ? temp.OrderByDescending(item => prop.GetValue(item))
: temp.OrderBy(item => prop.GetValue(item));
}
}
return temp.Skip(index * count).Take(count)
}
}
}

@ -1,4 +1,5 @@
using Shared;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
@ -15,14 +16,12 @@ namespace Entities
public string? Icon { get; set; }
[Required]
public ChampionClass Class { get; set;}
public virtual ICollection<SkillEntity>? Skills { get; set; }
public virtual ICollection<SkillEntity> Skills { get; set; }
public virtual ICollection<CharacteristicEntity> Characteristics { get; set; }
public ICollection<RunePageEntity> runepages { get; set; }
public Guid? ImageId { get; set; }
[ForeignKey("ImageId")]
public LargeImageEntity? Image { get; set; }
}
}

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Entities
{
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; }
}
}

@ -22,7 +22,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

@ -6,10 +6,11 @@ using System.Xml.Linq;
namespace Entities
{
public class ChampionDbContext : DbContext
public class LolDbContext : DbContext
{
public DbSet<SkinEntity> skins { get; set; }
public DbSet<ChampionEntity> champions { get; set; }
public DbSet<CharacteristicEntity> characteristics { get; set; }
public DbSet<SkillEntity> skills { get; set; }
public DbSet<RuneEntity> runes { get; set; }
public DbSet<RunePageEntity> runepages { get; set; }
@ -25,6 +26,7 @@ namespace Entities
{
modelBuilder.Entity<LargeImageEntity>().Property(e => e.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<CharacteristicEntity>().HasKey(c => new { c.Name, c.ChampionForeignKey });
modelBuilder.Entity<RunePageEntity>().Property(e => e.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<RunePageEntity>()
@ -32,6 +34,12 @@ namespace Entities
.WithMany(x => x.runepages)
.UsingEntity<RunePageRuneEntity>();
modelBuilder.Entity<ChampionEntity>()
.HasMany(x => x.runepages)
.WithMany(x => x.champions);
modelBuilder.Entity<LargeImageEntity>().HasData(new List<LargeImageEntity>()
{
@ -58,6 +66,21 @@ namespace Entities
}
});
modelBuilder.Entity<CharacteristicEntity>().HasData(new List<CharacteristicEntity>() {
new()
{
Name = "Force",
Value = 50,
ChampionForeignKey = "Dave",
},
new()
{
Name = "Défense",
Value = 75,
ChampionForeignKey = "Armure",
}
});
modelBuilder.Entity<SkinEntity>().HasData(new List<SkinEntity>() {
new SkinEntity
{

@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Entities.Migrations
{
[DbContext(typeof(ChampionDbContext))]
[Migration("20230209133904_myFirstMigration")]
[DbContext(typeof(LolDbContext))]
[Migration("20230301162639_myFirstMigration")]
partial class myFirstMigration
{
/// <inheritdoc />
@ -20,6 +20,21 @@ namespace Entities.Migrations
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("ChampionEntityRunePageEntity", b =>
{
b.Property<string>("championsName")
.HasColumnType("TEXT");
b.Property<Guid>("runepagesId")
.HasColumnType("TEXT");
b.HasKey("championsName", "runepagesId");
b.HasIndex("runepagesId");
b.ToTable("ChampionEntityRunePageEntity");
});
modelBuilder.Entity("ChampionEntitySkillEntity", b =>
{
b.Property<string>("ChampionsName")
@ -76,6 +91,39 @@ namespace Entities.Migrations
});
});
modelBuilder.Entity("Entities.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");
b.HasData(
new
{
Name = "Force",
ChampionForeignKey = "Dave",
Value = 50
},
new
{
Name = "Défense",
ChampionForeignKey = "Armure",
Value = 75
});
});
modelBuilder.Entity("Entities.LargeImageEntity", b =>
{
b.Property<Guid>("Id")
@ -93,7 +141,7 @@ namespace Entities.Migrations
b.HasData(
new
{
Id = new Guid("70d7aace-13a9-40e1-bd94-99790805f6d0"),
Id = new Guid("d3a490c6-fb49-475a-9134-47c2de9888d2"),
Base64 = "aaa"
});
});
@ -154,7 +202,7 @@ namespace Entities.Migrations
b.HasData(
new
{
Id = new Guid("a5a4f69b-5cbb-48c1-beb4-896bc9171714"),
Id = new Guid("4ea04d4f-0a64-4d28-8d74-4499dbc541f2"),
Name = "Runepage_1"
});
});
@ -262,6 +310,21 @@ namespace Entities.Migrations
});
});
modelBuilder.Entity("ChampionEntityRunePageEntity", b =>
{
b.HasOne("Entities.ChampionEntity", null)
.WithMany()
.HasForeignKey("championsName")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.RunePageEntity", null)
.WithMany()
.HasForeignKey("runepagesId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("ChampionEntitySkillEntity", b =>
{
b.HasOne("Entities.ChampionEntity", null)
@ -286,6 +349,17 @@ namespace Entities.Migrations
b.Navigation("Image");
});
modelBuilder.Entity("Entities.CharacteristicEntity", b =>
{
b.HasOne("Entities.ChampionEntity", "Champion")
.WithMany("Characteristics")
.HasForeignKey("ChampionForeignKey")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Champion");
});
modelBuilder.Entity("Entities.RuneEntity", b =>
{
b.HasOne("Entities.LargeImageEntity", "Image")
@ -326,6 +400,11 @@ namespace Entities.Migrations
b.Navigation("Image");
});
modelBuilder.Entity("Entities.ChampionEntity", b =>
{
b.Navigation("Characteristics");
});
#pragma warning restore 612, 618
}
}

@ -89,6 +89,30 @@ namespace Entities.Migrations
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "ChampionEntityRunePageEntity",
columns: table => new
{
championsName = table.Column<string>(type: "TEXT", nullable: false),
runepagesId = table.Column<Guid>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ChampionEntityRunePageEntity", x => new { x.championsName, x.runepagesId });
table.ForeignKey(
name: "FK_ChampionEntityRunePageEntity_champions_championsName",
column: x => x.championsName,
principalTable: "champions",
principalColumn: "Name",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ChampionEntityRunePageEntity_runepages_runepagesId",
column: x => x.runepagesId,
principalTable: "runepages",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ChampionEntitySkillEntity",
columns: table => new
@ -113,6 +137,25 @@ namespace Entities.Migrations
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
@ -177,12 +220,12 @@ namespace Entities.Migrations
migrationBuilder.InsertData(
table: "largeimages",
columns: new[] { "Id", "Base64" },
values: new object[] { new Guid("70d7aace-13a9-40e1-bd94-99790805f6d0"), "aaa" });
values: new object[] { new Guid("d3a490c6-fb49-475a-9134-47c2de9888d2"), "aaa" });
migrationBuilder.InsertData(
table: "runepages",
columns: new[] { "Id", "Name" },
values: new object[] { new Guid("a5a4f69b-5cbb-48c1-beb4-896bc9171714"), "Runepage_1" });
values: new object[] { new Guid("4ea04d4f-0a64-4d28-8d74-4499dbc541f2"), "Runepage_1" });
migrationBuilder.InsertData(
table: "runes",
@ -202,6 +245,15 @@ namespace Entities.Migrations
{ "White Star", "Random damage", 3 }
});
migrationBuilder.InsertData(
table: "characteristics",
columns: new[] { "ChampionForeignKey", "Name", "Value" },
values: new object[,]
{
{ "Armure", "Défense", 75 },
{ "Dave", "Force", 50 }
});
migrationBuilder.InsertData(
table: "skins",
columns: new[] { "Name", "ChampionForeignKey", "Description", "Icon", "ImageId", "Price" },
@ -211,6 +263,11 @@ namespace Entities.Migrations
{ "Dave de glace", "Dave", "Enneigé", "aaa", null, 7.99f }
});
migrationBuilder.CreateIndex(
name: "IX_ChampionEntityRunePageEntity_runepagesId",
table: "ChampionEntityRunePageEntity",
column: "runepagesId");
migrationBuilder.CreateIndex(
name: "IX_ChampionEntitySkillEntity_SkillsName",
table: "ChampionEntitySkillEntity",
@ -221,6 +278,11 @@ namespace Entities.Migrations
table: "champions",
column: "ImageId");
migrationBuilder.CreateIndex(
name: "IX_characteristics_ChampionForeignKey",
table: "characteristics",
column: "ChampionForeignKey");
migrationBuilder.CreateIndex(
name: "IX_RunePageRuneEntity_runesName",
table: "RunePageRuneEntity",
@ -245,9 +307,15 @@ namespace Entities.Migrations
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ChampionEntityRunePageEntity");
migrationBuilder.DropTable(
name: "ChampionEntitySkillEntity");
migrationBuilder.DropTable(
name: "characteristics");
migrationBuilder.DropTable(
name: "RunePageRuneEntity");

@ -9,14 +9,29 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Entities.Migrations
{
[DbContext(typeof(ChampionDbContext))]
partial class ChampionDbContextModelSnapshot : ModelSnapshot
[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>("championsName")
.HasColumnType("TEXT");
b.Property<Guid>("runepagesId")
.HasColumnType("TEXT");
b.HasKey("championsName", "runepagesId");
b.HasIndex("runepagesId");
b.ToTable("ChampionEntityRunePageEntity");
});
modelBuilder.Entity("ChampionEntitySkillEntity", b =>
{
b.Property<string>("ChampionsName")
@ -73,6 +88,39 @@ namespace Entities.Migrations
});
});
modelBuilder.Entity("Entities.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");
b.HasData(
new
{
Name = "Force",
ChampionForeignKey = "Dave",
Value = 50
},
new
{
Name = "Défense",
ChampionForeignKey = "Armure",
Value = 75
});
});
modelBuilder.Entity("Entities.LargeImageEntity", b =>
{
b.Property<Guid>("Id")
@ -90,7 +138,7 @@ namespace Entities.Migrations
b.HasData(
new
{
Id = new Guid("70d7aace-13a9-40e1-bd94-99790805f6d0"),
Id = new Guid("d3a490c6-fb49-475a-9134-47c2de9888d2"),
Base64 = "aaa"
});
});
@ -151,7 +199,7 @@ namespace Entities.Migrations
b.HasData(
new
{
Id = new Guid("a5a4f69b-5cbb-48c1-beb4-896bc9171714"),
Id = new Guid("4ea04d4f-0a64-4d28-8d74-4499dbc541f2"),
Name = "Runepage_1"
});
});
@ -259,6 +307,21 @@ namespace Entities.Migrations
});
});
modelBuilder.Entity("ChampionEntityRunePageEntity", b =>
{
b.HasOne("Entities.ChampionEntity", null)
.WithMany()
.HasForeignKey("championsName")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.RunePageEntity", null)
.WithMany()
.HasForeignKey("runepagesId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("ChampionEntitySkillEntity", b =>
{
b.HasOne("Entities.ChampionEntity", null)
@ -283,6 +346,17 @@ namespace Entities.Migrations
b.Navigation("Image");
});
modelBuilder.Entity("Entities.CharacteristicEntity", b =>
{
b.HasOne("Entities.ChampionEntity", "Champion")
.WithMany("Characteristics")
.HasForeignKey("ChampionForeignKey")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Champion");
});
modelBuilder.Entity("Entities.RuneEntity", b =>
{
b.HasOne("Entities.LargeImageEntity", "Image")
@ -323,6 +397,11 @@ namespace Entities.Migrations
b.Navigation("Image");
});
modelBuilder.Entity("Entities.ChampionEntity", b =>
{
b.Navigation("Characteristics");
});
#pragma warning restore 612, 618
}
}

@ -7,7 +7,7 @@ ChampionEntity imri = new()
Bio = "Fou Furieux",
Class = ChampionClass.Assassin
};
using (var context = new ChampionDbContext())
using (var context = new LolDbContext())
{
// Crée des nounours et les insère dans la base
Console.WriteLine("Creates and inserts new Champion");

@ -10,7 +10,6 @@ namespace Entities
{
public class RunePageEntity
{
[Key]
public Guid Id { get; set; }
@ -18,6 +17,7 @@ namespace Entities
public string Name { get; set; }
public ICollection<RuneEntity> runes { get; set; }
public ICollection<ChampionEntity> champions { get; set; }
}

@ -21,7 +21,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{7
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Entity Framework", "Entity Framework", "{BC2FFCA4-3801-433F-A83E-B55345F3B31E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entities", "Entities\Entities.csproj", "{C463E2E1-237A-4339-A4C4-6EA3BE7002AE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "Entities\Entities.csproj", "{C463E2E1-237A-4339-A4C4-6EA3BE7002AE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Business", "Business\Business.csproj", "{A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -57,6 +59,10 @@ Global
{C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Release|Any CPU.Build.0 = Release|Any CPU
{A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -65,6 +71,7 @@ Global
{1889FA6E-B7C6-416E-8628-9449FB9070B9} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}
{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {2C607793-B163-4731-A4D1-AFE8A7C4C170}
{C463E2E1-237A-4339-A4C4-6EA3BE7002AE} = {BC2FFCA4-3801-433F-A83E-B55345F3B31E}
{A447B0BE-62AE-4F66-B887-D1F3D46B0DB3} = {BC2FFCA4-3801-433F-A83E-B55345F3B31E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9}

Loading…
Cancel
Save