From ff9385bac5fc4dce9d9c724eaac697269cbb5e29 Mon Sep 17 00:00:00 2001 From: Najlae Lambaraa Date: Sun, 23 Oct 2022 19:33:48 +0200 Subject: [PATCH] Entity :green_heart: --- Sources/MaSoluction/App/App.csproj | 10 ++++ Sources/MaSoluction/App/Program.cs | 2 + Sources/MaSoluction/Data/DBManager.cs | 52 +++++++++++++++++-- Sources/MaSoluction/Data/Data.csproj | 1 + Sources/MaSoluction/Data/Stub.cs | 7 ++- Sources/MaSoluction/Entities/Entities.csproj | 18 +++++++ ...221023150750_monNomDeMigration.Designer.cs | 46 ++++++++++++++++ .../20221023150750_monNomDeMigration.cs | 33 ++++++++++++ .../NumberDieDbContextModelSnapshot.cs | 44 ++++++++++++++++ .../Entities/NumberDieDbContext.cs | 20 +++++++ .../MaSoluction/Entities/NumberDieEntity.cs | 10 ++++ Sources/MaSoluction/MaSoluction.sln | 16 +++++- Sources/MaSoluction/Model/Manager.cs | 12 ++--- Sources/MaSoluction/Testeur/TesterStub.cs | 9 +++- 14 files changed, 262 insertions(+), 18 deletions(-) create mode 100644 Sources/MaSoluction/App/App.csproj create mode 100644 Sources/MaSoluction/App/Program.cs create mode 100644 Sources/MaSoluction/Entities/Entities.csproj create mode 100644 Sources/MaSoluction/Entities/Migrations/20221023150750_monNomDeMigration.Designer.cs create mode 100644 Sources/MaSoluction/Entities/Migrations/20221023150750_monNomDeMigration.cs create mode 100644 Sources/MaSoluction/Entities/Migrations/NumberDieDbContextModelSnapshot.cs create mode 100644 Sources/MaSoluction/Entities/NumberDieDbContext.cs create mode 100644 Sources/MaSoluction/Entities/NumberDieEntity.cs diff --git a/Sources/MaSoluction/App/App.csproj b/Sources/MaSoluction/App/App.csproj new file mode 100644 index 0000000..74abf5c --- /dev/null +++ b/Sources/MaSoluction/App/App.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/Sources/MaSoluction/App/Program.cs b/Sources/MaSoluction/App/Program.cs new file mode 100644 index 0000000..3751555 --- /dev/null +++ b/Sources/MaSoluction/App/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/Sources/MaSoluction/Data/DBManager.cs b/Sources/MaSoluction/Data/DBManager.cs index b1fa54b..4b6d97b 100644 --- a/Sources/MaSoluction/Data/DBManager.cs +++ b/Sources/MaSoluction/Data/DBManager.cs @@ -1,15 +1,59 @@ -using System; +using Entities; +using Model; +using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Data { - public class DBManager + public class DBManager : IDataManager { - + public bool AddDice(Die addD) + { + bool resulta=false; + using (var context = new NumberDieDbContext()) + { + NumberDieEntity entity = new NumberDieEntity + { + + + + }; + context.AddAsync(entity); + resulta = context.SaveChanges() == 1; + } + return resulta; + } + + public void clear() + { + using (var context = new NumberDieDbContext()) + { + context.RemoveRange(context.NumberDice); + context.SaveChanges(); + } + } + + public List GetDices() + { + throw new NotImplementedException(); + } + + public bool RemoveDice(Die removeD) + { + bool reslta = false; + using (var context = new NumberDieDbContext()) + { + context.Remove(removeD); + reslta= context.SaveChanges() == 1; + } + return reslta; + + } } - + } diff --git a/Sources/MaSoluction/Data/Data.csproj b/Sources/MaSoluction/Data/Data.csproj index bcb5f29..945e627 100644 --- a/Sources/MaSoluction/Data/Data.csproj +++ b/Sources/MaSoluction/Data/Data.csproj @@ -7,6 +7,7 @@ + diff --git a/Sources/MaSoluction/Data/Stub.cs b/Sources/MaSoluction/Data/Stub.cs index 0ea76d1..0279d11 100644 --- a/Sources/MaSoluction/Data/Stub.cs +++ b/Sources/MaSoluction/Data/Stub.cs @@ -15,6 +15,7 @@ namespace Data if (addD != null) { listDice.Add(addD); + return true; } return false; @@ -32,8 +33,6 @@ namespace Data public List GetDices() { - - return listDice; } @@ -41,8 +40,8 @@ namespace Data { if (removeD!=null) { - listDice.Remove(removeD); - return true; + + return listDice.Remove(removeD); } return false; diff --git a/Sources/MaSoluction/Entities/Entities.csproj b/Sources/MaSoluction/Entities/Entities.csproj new file mode 100644 index 0000000..37aa1c1 --- /dev/null +++ b/Sources/MaSoluction/Entities/Entities.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/Sources/MaSoluction/Entities/Migrations/20221023150750_monNomDeMigration.Designer.cs b/Sources/MaSoluction/Entities/Migrations/20221023150750_monNomDeMigration.Designer.cs new file mode 100644 index 0000000..2e6f9e5 --- /dev/null +++ b/Sources/MaSoluction/Entities/Migrations/20221023150750_monNomDeMigration.Designer.cs @@ -0,0 +1,46 @@ +// +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(NumberDieDbContext))] + [Migration("20221023150750_monNomDeMigration")] + partial class monNomDeMigration + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "6.0.10"); + + modelBuilder.Entity("Entities.NumberDieEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Max") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Min") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("NumberDice"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/MaSoluction/Entities/Migrations/20221023150750_monNomDeMigration.cs b/Sources/MaSoluction/Entities/Migrations/20221023150750_monNomDeMigration.cs new file mode 100644 index 0000000..f10520b --- /dev/null +++ b/Sources/MaSoluction/Entities/Migrations/20221023150750_monNomDeMigration.cs @@ -0,0 +1,33 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Entities.Migrations +{ + public partial class monNomDeMigration : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "NumberDice", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: false), + Min = table.Column(type: "TEXT", nullable: false), + Max = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_NumberDice", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "NumberDice"); + } + } +} diff --git a/Sources/MaSoluction/Entities/Migrations/NumberDieDbContextModelSnapshot.cs b/Sources/MaSoluction/Entities/Migrations/NumberDieDbContextModelSnapshot.cs new file mode 100644 index 0000000..d64a017 --- /dev/null +++ b/Sources/MaSoluction/Entities/Migrations/NumberDieDbContextModelSnapshot.cs @@ -0,0 +1,44 @@ +// +using Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Entities.Migrations +{ + [DbContext(typeof(NumberDieDbContext))] + partial class NumberDieDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "6.0.10"); + + modelBuilder.Entity("Entities.NumberDieEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Max") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Min") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("NumberDice"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/MaSoluction/Entities/NumberDieDbContext.cs b/Sources/MaSoluction/Entities/NumberDieDbContext.cs new file mode 100644 index 0000000..683bdf1 --- /dev/null +++ b/Sources/MaSoluction/Entities/NumberDieDbContext.cs @@ -0,0 +1,20 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entities +{ + public class NumberDieDbContext:DbContext + { + public DbSet NumberDice { get; set; } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + => optionsBuilder.UseSqlite($"Data Source=Dice_App.NumberDice.db"); + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + } + } +} diff --git a/Sources/MaSoluction/Entities/NumberDieEntity.cs b/Sources/MaSoluction/Entities/NumberDieEntity.cs new file mode 100644 index 0000000..c70dec6 --- /dev/null +++ b/Sources/MaSoluction/Entities/NumberDieEntity.cs @@ -0,0 +1,10 @@ +namespace Entities +{ + public class NumberDieEntity + { + public long Id { get; set; } + public int Name { get; set; } + public int Min { get; set; } + public int Max { get; set; } + } +} \ No newline at end of file diff --git a/Sources/MaSoluction/MaSoluction.sln b/Sources/MaSoluction/MaSoluction.sln index ac1d5f3..5653294 100644 --- a/Sources/MaSoluction/MaSoluction.sln +++ b/Sources/MaSoluction/MaSoluction.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31005.135 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32929.385 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model", "Model\Model.csproj", "{2CC2AF2A-F6B6-44BF-A1C2-710575725F6B}" EndProject @@ -9,6 +9,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Testeur", "Testeur\Testeur. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Data", "Data\Data.csproj", "{A99FF3EF-45E2-4688-B5D0-84E69E0F0E8E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entities", "Entities\Entities.csproj", "{F0890B94-7F39-47F0-B085-1728FAF43EA3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App", "App\App.csproj", "{FBC77BA2-6449-4338-A6E5-19B0ABE5A883}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +31,14 @@ Global {A99FF3EF-45E2-4688-B5D0-84E69E0F0E8E}.Debug|Any CPU.Build.0 = Debug|Any CPU {A99FF3EF-45E2-4688-B5D0-84E69E0F0E8E}.Release|Any CPU.ActiveCfg = Release|Any CPU {A99FF3EF-45E2-4688-B5D0-84E69E0F0E8E}.Release|Any CPU.Build.0 = Release|Any CPU + {F0890B94-7F39-47F0-B085-1728FAF43EA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F0890B94-7F39-47F0-B085-1728FAF43EA3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F0890B94-7F39-47F0-B085-1728FAF43EA3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F0890B94-7F39-47F0-B085-1728FAF43EA3}.Release|Any CPU.Build.0 = Release|Any CPU + {FBC77BA2-6449-4338-A6E5-19B0ABE5A883}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FBC77BA2-6449-4338-A6E5-19B0ABE5A883}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FBC77BA2-6449-4338-A6E5-19B0ABE5A883}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FBC77BA2-6449-4338-A6E5-19B0ABE5A883}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Sources/MaSoluction/Model/Manager.cs b/Sources/MaSoluction/Model/Manager.cs index 53536d9..39e7b01 100644 --- a/Sources/MaSoluction/Model/Manager.cs +++ b/Sources/MaSoluction/Model/Manager.cs @@ -20,10 +20,10 @@ namespace Model public bool AddDice(Die addD) { - if(addD!=null) + if(dataManager!=null) { - dataManager.AddDice(addD); - return true; + return dataManager.AddDice(addD); + } return false; @@ -31,10 +31,10 @@ namespace Model } public bool RemoveDice(Die removeD) { - if (removeD != null) + if (dataManager != null) { - dataManager.RemoveDice(removeD); - return true; + + return dataManager.RemoveDice(removeD); } return false; } diff --git a/Sources/MaSoluction/Testeur/TesterStub.cs b/Sources/MaSoluction/Testeur/TesterStub.cs index 9d6bd2b..8198092 100644 --- a/Sources/MaSoluction/Testeur/TesterStub.cs +++ b/Sources/MaSoluction/Testeur/TesterStub.cs @@ -17,7 +17,8 @@ namespace Testeur Manager m = new Manager(new Stub()); NumberDie nd = new NumberDie("de1",1,6); // Acct - m.AddDice(nd); + //m.AddDice(nd); + m.dataManager.AddDice(nd); //Assert Assert.Equal("de1", nd.Name); @@ -31,7 +32,8 @@ namespace Testeur int n = m.GetDice().Count(); NumberDie nd = new NumberDie("de1", 2, 6); // Acct - m.RemoveDice(nd); + // m.RemoveDice(nd); + m.dataManager.RemoveDice(nd); //Assert Assert.NotEqual(n, m.GetDice().Count); } @@ -44,8 +46,11 @@ namespace Testeur int n = m.GetDice().Count(); NumberDie nd = null; + Assert.False(m.AddDice(nd)); + Assert.False(m.RemoveDice(nd)); + } } } -- 2.36.3