avancées en EF, entity du skin ajoutée, il reste à implémenter ses méthodes pour l'utiliser avec l'api

master
pasquizzat 2 years ago
parent 26fdad3ef8
commit 93fbe8c6b1

@ -10,7 +10,7 @@ namespace ApiDePaul.Controllers
[Route("[controller]")]
public class SkinController : ControllerBase
{
IDataManager donnees = new StubData();
IDataManager donnees;// = new StubData();
private readonly ILogger<SkinController> _logger;

Binary file not shown.

@ -3,8 +3,8 @@ using Model;
using TrucAuMilieu;
ChampionEntity c1 = new ChampionEntity("champion1", "il est beau", "imagepng.jpeg");
Champion c2 = new Champion("joe");
//ChampionEntity c1 = new ChampionEntity("champion1", "il est beau", "imagepng.jpeg");
//Champion c2 = new Champion("joe");
Console.WriteLine("allo?");
var dataMgr = new DataBdd();
@ -30,8 +30,8 @@ foreach (var champion in list1)
}*/
if (dataMgr.ChampionsMgr.DeleteItem(c2).Result)
Console.WriteLine("joe est mort.");
//if (dataMgr.ChampionsMgr.DeleteItem(c2).Result)
// Console.WriteLine("joe est mort.");
foreach (var champion in dataMgr.ChampionsMgr.GetItems(0, dataMgr.ChampionsMgr.GetNbItems().Result).Result.ToList()) { Console.WriteLine(champion.Name); }

Binary file not shown.

@ -11,6 +11,7 @@ namespace LibEntityFramework
public ChampionContext() { }
public ChampionContext(DbContextOptions<ChampionContext> options) : base(options) { }
public DbSet<ChampionEntity> Champs { get; set; }
public DbSet<SkinEntity> Skins { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
{

@ -13,12 +13,18 @@ namespace LibEntityFramework
[Key]
public string Name { get; set; }
public string Bio { get; set; }
public string Class { get; set; }
public string Icon { get; set; }
public ChampionEntity(string name, string bio, string icon)
public string Image { get; set; }
/*public List<Tuple<string, int>> Characteristics { get; set; } faudra les faire en base eux aussi
public List<SkillDto> Skills { get; set; }*/
/*public ChampionEntity(string nameid, string bio = "", string Class = "", string icon = "", string image = "")
{
Name = name;
NameId = nameid;
Bio = bio;
this.Class = Class;
Icon = icon;
}
Image = image;
}*/
}
}

@ -0,0 +1,79 @@
// <auto-generated />
using LibEntityFramework;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace LibEntityFramework.Migrations
{
[DbContext(typeof(ChampionContext))]
[Migration("20230317084952_migrationAvecSkin")]
partial class migrationAvecSkin
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("LibEntityFramework.ChampionEntity", b =>
{
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Bio")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Class")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Image")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("Champs");
});
modelBuilder.Entity("LibEntityFramework.SkinEntity", b =>
{
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Champion")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Image")
.IsRequired()
.HasColumnType("TEXT");
b.Property<float>("Price")
.HasColumnType("REAL");
b.HasKey("Name");
b.ToTable("Skins");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,59 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace LibEntityFramework.Migrations
{
/// <inheritdoc />
public partial class migrationAvecSkin : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Class",
table: "Champs",
type: "TEXT",
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<string>(
name: "Image",
table: "Champs",
type: "TEXT",
nullable: false,
defaultValue: "");
migrationBuilder.CreateTable(
name: "Skins",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", nullable: false),
Champion = table.Column<string>(type: "TEXT", nullable: false),
Description = table.Column<string>(type: "TEXT", nullable: false),
Icon = table.Column<string>(type: "TEXT", nullable: false),
Image = table.Column<string>(type: "TEXT", nullable: false),
Price = table.Column<float>(type: "REAL", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Skins", x => x.Name);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Skins");
migrationBuilder.DropColumn(
name: "Class",
table: "Champs");
migrationBuilder.DropColumn(
name: "Image",
table: "Champs");
}
}
}

@ -25,14 +25,51 @@ namespace LibEntityFramework.Migrations
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Class")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Image")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Name");
b.ToTable("Champs");
});
modelBuilder.Entity("LibEntityFramework.SkinEntity", b =>
{
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Champion")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Image")
.IsRequired()
.HasColumnType("TEXT");
b.Property<float>("Price")
.HasColumnType("REAL");
b.HasKey("Name");
b.ToTable("Skins");
});
#pragma warning restore 612, 618
}
}

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibEntityFramework
{
public class SkinEntity
{
[Key]
public string Name { get; set; }
public string Champion { get; set; }
public string Description { get; set; }
public string Icon { get; set; }
public string Image { get; set; }
public float Price { get; set; }
}
}

Binary file not shown.

@ -10,7 +10,45 @@ namespace TrucAuMilieu
{
public static class ChampionConvert
{
public static ChampionEntity ChampToEf(this Champion c) => new ChampionEntity(c.Name, c.Bio, c.Icon);
public static Champion EfToChamp(this ChampionEntity c) => new Champion(c.Name,ChampionClass.Tank,c.Icon,c.Icon,c.Bio);
public static ChampionEntity ChampToEf(this Champion c)
{
/*foreach(var sk in c.Skins)
{
faudrait faire avec les autres trucs
}*/
return new ChampionEntity()
{
Name=c.Name,
Bio=c.Bio,
Class=c.Class.ToString(),
Icon=c.Icon,
Image=c.Image.ToString()
};
}
public static Champion EfToChamp(this ChampionEntity c)
{
Champion champ = new Champion(c.Name);
var classes = Enum.GetNames(typeof(ChampionClass));
if (classes.ToList().Contains(c.Class))
{
champ.Class = (ChampionClass)Enum.Parse(typeof(ChampionClass), c.Class);
}
else
{
champ.Class = 0;
}
champ.Icon = c.Icon;
champ.Image = new LargeImage(c.Image);
champ.Bio = c.Bio;
/*
foreach (var s in c.Skills)
{
champ.AddSkill(s.DtoToSkill());
}
champ.AddCharacteristics(c.Characteristics.ToArray());
*/
return champ;
}
}
}

@ -0,0 +1,82 @@
using LibEntityFramework;
using Model;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TrucAuMilieu
{
public partial class DataBdd
{
public ChampionContext ct = new ChampionContext();
public class SkinManager : ISkinsManager
{
private readonly DataBdd parent;
public SkinManager(DataBdd parent)
=> this.parent = parent;
public async Task<Skin?> AddItem(Skin? item)
{
await parent.ct.AddAsync(item.SkinToEf());
await parent.contextCh.SaveChangesAsync();
Debug.WriteLine("skin ajouté");
return item;
}
public Task<bool> DeleteItem(Skin? item)
{
throw new NotImplementedException();
}
public async Task<IEnumerable<Skin?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
//requete sur les champions avec des arguments (genre la pagination est possible, et y'a le descending et tout)
{
if (orderingPropertyName != null)
{
if (descending)
{
return await Task.FromResult(parent.ct.Skins.OrderByDescending(s => typeof(SkinEntity).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(sk => sk.EfToSkin()));
}
else
{
var pap = await Task.FromResult(parent.ct.Skins.OrderBy(c => typeof(SkinEntity).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(sk => sk.EfToSkin()));
return pap;
}
}
else
{
var pap2 = await Task.FromResult(parent.ct.Skins.Skip(index * count).Take(count).Select(sk => sk.EfToSkin()));
return pap2;
}
}
public Task<IEnumerable<Skin?>> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Skin?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<int> GetNbItems() => Task.FromResult(parent.ct.Skins.Count());
public Task<int> GetNbItemsByChampion(Champion? champion)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByName(string substring)
{
throw new NotImplementedException();
}
public Task<Skin?> UpdateItem(Skin? oldItem, Skin? newItem)
{
throw new NotImplementedException();
}
}
}
}

@ -13,6 +13,7 @@ namespace TrucAuMilieu
public DataBdd()
{
ChampionsMgr = new ChampionsManager(this);
SkinsMgr = new SkinManager(this);
}
public IChampionsManager ChampionsMgr { get; }

@ -0,0 +1,32 @@
using LibEntityFramework;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TrucAuMilieu
{
public static class SkinConvert
{
public static SkinEntity SkinToEf(this Skin s)
{
return new SkinEntity()
{
Name = s.Name,
Champion = s.Champion.Name,
Description = s.Description,
Icon = s.Icon,
Image = s.Image.ToString(),
Price = s.Price
};
}
public static Skin EfToSkin(this SkinEntity s)
{
var dataMgr = new DataBdd();
Champion c = dataMgr.ChampionsMgr.GetItemsByName(s.Champion, 0, 1).Result.First();
return new Skin(s.Name,c,s.Price,s.Icon,s.Image,s.Description);
}
}
}
Loading…
Cancel
Save