suppression ajoutée 🆒, retrait de l'id dans l'entite, le nom est la nouvelle clé primaire, comme ça on touche pas au model, vu qu'il ne vient pas de moi

master
pasquizzat 2 years ago
parent 2effc22f30
commit ec99ef34cc

@ -9,15 +9,33 @@ Console.WriteLine("allo?");
var dataMgr = new DataBdd();
//dataMgr.ChampionsMgr.AddItem(c1.EfToChamp());
//dataMgr.ChampionsMgr.AddItem(c2);
List<Champion> list = dataMgr.ChampionsMgr.GetItems(0, dataMgr.ChampionsMgr.GetNbItems().Result).Result.ToList();
List<Champion> list2 = dataMgr.ChampionsMgr.GetItemsByName("oe", 0, 30).Result.ToList();
/*List<Champion> list1 = dataMgr.ChampionsMgr.GetItems(0, dataMgr.ChampionsMgr.GetNbItems().Result).Result.ToList();
//List<Champion> list2 = dataMgr.ChampionsMgr.GetItemsByName("oe", 0, 30).Result.ToList();
/*ChampionContext data = new ChampionContext();
data.Champs.ToList();
List<ChampionEntity> l = data.listChampions();*/
/*
foreach (var champion in list1)
{
Console.WriteLine(champion.Name + ' ' + champion.Bio);
}*/
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); }
foreach (var champion in list2) { Console.WriteLine(champion.Name); }

Binary file not shown.

@ -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,13 +9,13 @@ namespace LibEntityFramework
{
public class ChampionEntity
{
public int Id { get; set; }
//j'ai retiré l'Id, je me suis dit que ça ferait plus de sens de ne pas toucher au model, car ce code n'est pas le mien.
[Key]
public string Name { get; set; }
public string Bio { get; set; }
public string Icon { get; set; }
public ChampionEntity(string name, string bio, string icon)
{
Id = 0;
Name = name;
Bio = bio;
Icon = icon;

@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace LibEntityFramework.Migrations
{
[DbContext(typeof(ChampionContext))]
[Migration("20230201083944_Migration1")]
partial class Migration1
[Migration("20230308101741_NouvelleMigration")]
partial class NouvelleMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -21,9 +21,8 @@ namespace LibEntityFramework.Migrations
modelBuilder.Entity("LibEntityFramework.ChampionEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Bio")
.IsRequired()
@ -33,11 +32,7 @@ namespace LibEntityFramework.Migrations
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasKey("Name");
b.ToTable("Champs");
});

@ -5,7 +5,7 @@
namespace LibEntityFramework.Migrations
{
/// <inheritdoc />
public partial class Migration1 : Migration
public partial class NouvelleMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
@ -14,15 +14,13 @@ namespace LibEntityFramework.Migrations
name: "Champs",
columns: table => new
{
Id = table.Column<int>(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_Champs", x => x.Id);
table.PrimaryKey("PK_Champs", x => x.Name);
});
}

@ -18,9 +18,8 @@ namespace LibEntityFramework.Migrations
modelBuilder.Entity("LibEntityFramework.ChampionEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Bio")
.IsRequired()
@ -30,11 +29,7 @@ namespace LibEntityFramework.Migrations
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasKey("Name");
b.ToTable("Champs");
});

Binary file not shown.

@ -11,6 +11,6 @@ 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);
public static Champion EfToChamp(this ChampionEntity c) => new Champion(c.Name,ChampionClass.Tank,c.Icon,c.Icon,c.Bio);
}
}

@ -14,7 +14,6 @@ namespace TrucAuMilieu
public ChampionContext contextCh = new ChampionContext();
public class ChampionsManager : IChampionsManager
{
private readonly DataBdd parent;
public ChampionsManager(DataBdd parent)
=> this.parent = parent;
@ -27,10 +26,15 @@ namespace TrucAuMilieu
return item;
}
public Task<bool> DeleteItem(Champion? item)
//pas fait
public async Task<bool> DeleteItem(Champion? item)
//supprimer un champion? je crois? et renvoie true si il est supprimé? à tester
{
throw new NotImplementedException();
if (parent.contextCh.Champs.Remove(item.ChampToEf()).Entity==item.ChampToEf())
{
await parent.contextCh.SaveChangesAsync();
return true;
}
return false;
}
public async Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)

Loading…
Cancel
Save