diff --git a/WF_EF_Api/ConsoleTest/Program.cs b/WF_EF_Api/ConsoleTest/Program.cs index af0744a..127ed44 100644 --- a/WF_EF_Api/ConsoleTest/Program.cs +++ b/WF_EF_Api/ConsoleTest/Program.cs @@ -1 +1 @@ - +Console.WriteLine("bonjour"); \ No newline at end of file diff --git a/WF_EF_Api/Contextlib/Contextlib.csproj b/WF_EF_Api/Contextlib/Contextlib.csproj index bb23fb7..805901c 100644 --- a/WF_EF_Api/Contextlib/Contextlib.csproj +++ b/WF_EF_Api/Contextlib/Contextlib.csproj @@ -6,4 +6,22 @@ enable + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + diff --git a/WF_EF_Api/Contextlib/WTFContext.cs b/WF_EF_Api/Contextlib/WTFContext.cs new file mode 100644 index 0000000..c27565d --- /dev/null +++ b/WF_EF_Api/Contextlib/WTFContext.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Entity; +using Microsoft.EntityFrameworkCore; + +namespace Contextlib +{ + public class WTFContext : DbContext + { + public DbSet Images { get; set; } + public DbSet Users { get; set; } + //public DbSet Admin { get; set; } + public DbSet Question { get; set; } + public DbSet Quiz { get; set; } + //public DbSet QuizQuestion { get; set; } + //public DbSet RecordQuiz { get; set; } + public DbSet Source { get; set; } + public DbSet Character { get; set; } + public DbSet Quote { get; set; } + //public DbSet DailyQuote { get; set; } + //public DbSet Favorite { get; set; } + //public DbSet Commentary { get; set; } + + + protected override void OnConfiguring(DbContextOptionsBuilder options) + => options.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=myFirstDatabase.mdf;Trusted_Connection=True;"); + } +} diff --git a/WF_EF_Api/Entity/Admin.cs b/WF_EF_Api/Entity/Admin.cs new file mode 100644 index 0000000..4b1ea8e --- /dev/null +++ b/WF_EF_Api/Entity/Admin.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class Admin + { + //public int IdUsers { get; set; } + } +} diff --git a/WF_EF_Api/Entity/Character.cs b/WF_EF_Api/Entity/Character.cs new file mode 100644 index 0000000..22643e6 --- /dev/null +++ b/WF_EF_Api/Entity/Character.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class Character + { + public int Id { get; set; } + public string Name { get; set; } + //public int IdImage { get; set; } + } +} diff --git a/WF_EF_Api/Entity/Commentary.cs b/WF_EF_Api/Entity/Commentary.cs new file mode 100644 index 0000000..b07ecdf --- /dev/null +++ b/WF_EF_Api/Entity/Commentary.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class Commentary + { + public int Id { get; set; } + //public int IdUsers { get; set; } + //public int IdQuote { get; set; } + public DateTime DateCommentary { get; set; } + public string Comment { get; set; } + } +} diff --git a/WF_EF_Api/Entity/DailyQuote.cs b/WF_EF_Api/Entity/DailyQuote.cs new file mode 100644 index 0000000..350290c --- /dev/null +++ b/WF_EF_Api/Entity/DailyQuote.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class DailyQuote + { + public int IdQuote { get; set; } + } +} diff --git a/WF_EF_Api/Entity/Favorite.cs b/WF_EF_Api/Entity/Favorite.cs new file mode 100644 index 0000000..0d6705e --- /dev/null +++ b/WF_EF_Api/Entity/Favorite.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class Favorite + { + //public int IdUsers { get; set; } + //public int IdQuote { get; set; } + } +} diff --git a/WF_EF_Api/Entity/Images.cs b/WF_EF_Api/Entity/Images.cs new file mode 100644 index 0000000..27fc63f --- /dev/null +++ b/WF_EF_Api/Entity/Images.cs @@ -0,0 +1,19 @@ +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 Entity +{ + public class Images + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int Id { get; set; } + public string ImgPath { get; set; } + public ICollection Users { get; set; } = new List(); + } +} diff --git a/WF_EF_Api/Entity/LangEnum.cs b/WF_EF_Api/Entity/LangEnum.cs new file mode 100644 index 0000000..a3238c3 --- /dev/null +++ b/WF_EF_Api/Entity/LangEnum.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public enum LangEnum + { + vo, + fr, + en + } +} diff --git a/WF_EF_Api/Entity/Question.cs b/WF_EF_Api/Entity/Question.cs new file mode 100644 index 0000000..5bc982c --- /dev/null +++ b/WF_EF_Api/Entity/Question.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class Question + { + public int Id { get; set; } + public string Text { get; set; } + public string AnswerA { get; set; } + public string AnswerB { get; set; } + public string AnswerC { get; set; } + public string AnswerD { get; set; } + public string CorrectAnswer { get; set; } + + } +} diff --git a/WF_EF_Api/Entity/Quiz.cs b/WF_EF_Api/Entity/Quiz.cs new file mode 100644 index 0000000..11e7bb5 --- /dev/null +++ b/WF_EF_Api/Entity/Quiz.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class Quiz + { + public int Id { get; set; } + public string Title { get; set; } + //public int IdImage { get; set; } + public int NbQuestion { get; set; } + } +} diff --git a/WF_EF_Api/Entity/QuizQuestion.cs b/WF_EF_Api/Entity/QuizQuestion.cs new file mode 100644 index 0000000..a62ba83 --- /dev/null +++ b/WF_EF_Api/Entity/QuizQuestion.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class QuizQuestion + { + //public int IdQuiz { get; set; } + //public int IdQuestion { get; set; } + } +} diff --git a/WF_EF_Api/Entity/Quote.cs b/WF_EF_Api/Entity/Quote.cs new file mode 100644 index 0000000..57621c1 --- /dev/null +++ b/WF_EF_Api/Entity/Quote.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class Quote + { + public int Id { get; set; } + public string Content { get; set; } + public int Likes { get; set; } + public LangEnum Langage { get; set; } + public bool IsValid { get; set; } + //public int IdCharacter { get; set; } + //public int IdSource { get; set; } + //public int IdUsersPropose { get; set; } + } +} diff --git a/WF_EF_Api/Entity/RecordQuiz.cs b/WF_EF_Api/Entity/RecordQuiz.cs new file mode 100644 index 0000000..5ddc02d --- /dev/null +++ b/WF_EF_Api/Entity/RecordQuiz.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class RecordQuiz + { + public int IdUsers { get; set; } + public int IdQuiz { get; set; } + public int NbPoint { get; set; } + public int TimeQuiz { get; set; } + } +} diff --git a/WF_EF_Api/Entity/Source.cs b/WF_EF_Api/Entity/Source.cs new file mode 100644 index 0000000..18f242e --- /dev/null +++ b/WF_EF_Api/Entity/Source.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity +{ + public class Source + { + public int Id { get; set; } + public string Title { get; set; } + public int Year { get; set; } + } +} diff --git a/WF_EF_Api/Entity/Users.cs b/WF_EF_Api/Entity/Users.cs new file mode 100644 index 0000000..c5049f7 --- /dev/null +++ b/WF_EF_Api/Entity/Users.cs @@ -0,0 +1,26 @@ +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 Entity +{ + public class Users + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int Id { get; set; } + public string UserName { get; set; } + public string Email { get; set; } + public string Password { get; set; } + + [ForeignKey(nameof(Images))] + public int IdImage { get; set; } + public Images Images { get; set; } + + public DateTime Created { get; set; } + } +} diff --git a/WF_EF_Api/Model/Entities.csproj b/WF_EF_Api/Model/Model.csproj similarity index 100% rename from WF_EF_Api/Model/Entities.csproj rename to WF_EF_Api/Model/Model.csproj diff --git a/WF_EF_Api/Shared/IFavoriteService.cs b/WF_EF_Api/Shared/IFavoriteService.cs index 53ca0a7..3b2de7f 100644 --- a/WF_EF_Api/Shared/IFavoriteService.cs +++ b/WF_EF_Api/Shared/IFavoriteService.cs @@ -26,3 +26,4 @@ namespace Shared // 'quoteId' is the unique identifier of the quote to be removed from all users' favorites. Task RemoveAllFavoriteForQuote(int quoteId); } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.Designer.cs new file mode 100644 index 0000000..516d42a --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.Designer.cs @@ -0,0 +1,205 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StubbedContextLib; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + [DbContext(typeof(StubWTFContext))] + [Migration("20250312160314_myFirstMigration")] + partial class myFirstMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Entity.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Character"); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImgPath") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Images"); + }); + + modelBuilder.Entity("Entity.Question", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnswerA") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AnswerB") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AnswerC") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AnswerD") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CorrectAnswer") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Text") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Question"); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("NbQuestion") + .HasColumnType("int"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Quiz"); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Content") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IsValid") + .HasColumnType("bit"); + + b.Property("Langage") + .HasColumnType("int"); + + b.Property("Likes") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Quote"); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Source"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("datetime2"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Users"); + + b.HasData( + new + { + Id = 1, + Created = new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "dev@gmail.com", + Password = "1234", + UserName = "Dev" + }); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.cs new file mode 100644 index 0000000..6fd3de5 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250312160314_myFirstMigration.cs @@ -0,0 +1,149 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + /// + public partial class myFirstMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Character", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Character", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Images", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImgPath = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Images", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Question", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Text = table.Column(type: "nvarchar(max)", nullable: false), + AnswerA = table.Column(type: "nvarchar(max)", nullable: false), + AnswerB = table.Column(type: "nvarchar(max)", nullable: false), + AnswerC = table.Column(type: "nvarchar(max)", nullable: false), + AnswerD = table.Column(type: "nvarchar(max)", nullable: false), + CorrectAnswer = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Question", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Quiz", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Title = table.Column(type: "nvarchar(max)", nullable: false), + NbQuestion = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Quiz", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Quote", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Content = table.Column(type: "nvarchar(max)", nullable: false), + Likes = table.Column(type: "int", nullable: false), + Langage = table.Column(type: "int", nullable: false), + IsValid = table.Column(type: "bit", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Quote", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Source", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Title = table.Column(type: "nvarchar(max)", nullable: false), + Year = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Source", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserName = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + Created = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + + migrationBuilder.InsertData( + table: "Users", + columns: new[] { "Id", "Created", "Email", "Password", "UserName" }, + values: new object[] { 1, new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), "dev@gmail.com", "1234", "Dev" }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Character"); + + migrationBuilder.DropTable( + name: "Images"); + + migrationBuilder.DropTable( + name: "Question"); + + migrationBuilder.DropTable( + name: "Quiz"); + + migrationBuilder.DropTable( + name: "Quote"); + + migrationBuilder.DropTable( + name: "Source"); + + migrationBuilder.DropTable( + name: "Users"); + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.Designer.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.Designer.cs new file mode 100644 index 0000000..d84e486 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.Designer.cs @@ -0,0 +1,248 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StubbedContextLib; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + [DbContext(typeof(StubWTFContext))] + [Migration("20250312162514_migr2")] + partial class migr2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Entity.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Character"); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImgPath") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Images"); + + b.HasData( + new + { + Id = 1, + ImgPath = "coucou" + }, + new + { + Id = 2, + ImgPath = "bonjour" + }); + }); + + modelBuilder.Entity("Entity.Question", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnswerA") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AnswerB") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AnswerC") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AnswerD") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CorrectAnswer") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Text") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Question"); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("NbQuestion") + .HasColumnType("int"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Quiz"); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Content") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IsValid") + .HasColumnType("bit"); + + b.Property("Langage") + .HasColumnType("int"); + + b.Property("Likes") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Quote"); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Source"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("datetime2"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("Users"); + + b.HasData( + new + { + Id = 1, + Created = new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "dev@gmail.com", + IdImage = 1, + Password = "1234", + UserName = "Dev" + }, + new + { + Id = 2, + Created = new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "admin@gmail.com", + IdImage = 1, + Password = "1234", + UserName = "Admin" + }); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Users") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Navigation("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.cs b/WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.cs new file mode 100644 index 0000000..01e2609 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/20250312162514_migr2.cs @@ -0,0 +1,89 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace StubbedContextLib.Migrations +{ + /// + public partial class migr2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "IdImage", + table: "Users", + type: "int", + nullable: false, + defaultValue: 0); + + migrationBuilder.InsertData( + table: "Images", + columns: new[] { "Id", "ImgPath" }, + values: new object[,] + { + { 1, "coucou" }, + { 2, "bonjour" } + }); + + migrationBuilder.UpdateData( + table: "Users", + keyColumn: "Id", + keyValue: 1, + column: "IdImage", + value: 1); + + migrationBuilder.InsertData( + table: "Users", + columns: new[] { "Id", "Created", "Email", "IdImage", "Password", "UserName" }, + values: new object[] { 2, new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), "admin@gmail.com", 1, "1234", "Admin" }); + + migrationBuilder.CreateIndex( + name: "IX_Users_IdImage", + table: "Users", + column: "IdImage"); + + migrationBuilder.AddForeignKey( + name: "FK_Users_Images_IdImage", + table: "Users", + column: "IdImage", + principalTable: "Images", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Users_Images_IdImage", + table: "Users"); + + migrationBuilder.DropIndex( + name: "IX_Users_IdImage", + table: "Users"); + + migrationBuilder.DeleteData( + table: "Images", + keyColumn: "Id", + keyValue: 2); + + migrationBuilder.DeleteData( + table: "Users", + keyColumn: "Id", + keyValue: 2); + + migrationBuilder.DeleteData( + table: "Images", + keyColumn: "Id", + keyValue: 1); + + migrationBuilder.DropColumn( + name: "IdImage", + table: "Users"); + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs b/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs new file mode 100644 index 0000000..4a848c7 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/Migrations/StubWTFContextModelSnapshot.cs @@ -0,0 +1,245 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StubbedContextLib; + +#nullable disable + +namespace StubbedContextLib.Migrations +{ + [DbContext(typeof(StubWTFContext))] + partial class StubWTFContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Entity.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Character"); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImgPath") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Images"); + + b.HasData( + new + { + Id = 1, + ImgPath = "coucou" + }, + new + { + Id = 2, + ImgPath = "bonjour" + }); + }); + + modelBuilder.Entity("Entity.Question", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AnswerA") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AnswerB") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AnswerC") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AnswerD") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CorrectAnswer") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Text") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Question"); + }); + + modelBuilder.Entity("Entity.Quiz", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("NbQuestion") + .HasColumnType("int"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Quiz"); + }); + + modelBuilder.Entity("Entity.Quote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Content") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IsValid") + .HasColumnType("bit"); + + b.Property("Langage") + .HasColumnType("int"); + + b.Property("Likes") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Quote"); + }); + + modelBuilder.Entity("Entity.Source", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Source"); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("datetime2"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IdImage") + .HasColumnType("int"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("IdImage"); + + b.ToTable("Users"); + + b.HasData( + new + { + Id = 1, + Created = new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "dev@gmail.com", + IdImage = 1, + Password = "1234", + UserName = "Dev" + }, + new + { + Id = 2, + Created = new DateTime(2000, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), + Email = "admin@gmail.com", + IdImage = 1, + Password = "1234", + UserName = "Admin" + }); + }); + + modelBuilder.Entity("Entity.Users", b => + { + b.HasOne("Entity.Images", "Images") + .WithMany("Users") + .HasForeignKey("IdImage") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Images"); + }); + + modelBuilder.Entity("Entity.Images", b => + { + b.Navigation("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/StubWTFContext.cs b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs new file mode 100644 index 0000000..8d983a4 --- /dev/null +++ b/WF_EF_Api/StubbedContextLib/StubWTFContext.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Contextlib; +using Entity; +using Microsoft.EntityFrameworkCore; + +namespace StubbedContextLib +{ + public class StubWTFContext : WTFContext + { + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + modelBuilder.Entity() + .HasMany(i => i.Users) + .WithOne(u => u.Images) + .HasForeignKey(u => u.IdImage) + .IsRequired(); + + modelBuilder.Entity().HasData( + new Images { Id = 1, ImgPath = "coucou" }, + new Images { Id = 2, ImgPath = "bonjour" } + ); + modelBuilder.Entity().HasData( + new Users { Id = 1, UserName = "Dev", Created = new DateTime(2000, 01, 01), Email = "dev@gmail.com", Password = "1234", IdImage = 1 }, + new Users { Id = 2, UserName = "Admin", Created = new DateTime(2000, 01, 01), Email = "admin@gmail.com", Password = "1234", IdImage = 1 } + ); + } + } +} diff --git a/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj b/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj index bb23fb7..9a838f3 100644 --- a/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj +++ b/WF_EF_Api/StubbedContextLib/StubbedContextLib.csproj @@ -6,4 +6,16 @@ enable + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/WF_EF_Api/WF_EF_Api.sln b/WF_EF_Api/WF_EF_Api.sln index bff150d..2b163b7 100644 --- a/WF_EF_Api/WF_EF_Api.sln +++ b/WF_EF_Api/WF_EF_Api.sln @@ -3,25 +3,25 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34723.18 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleTest", "ConsoleTest\ConsoleTest.csproj", "{A8B0E4D8-0726-4248-BB6D-DAA2545270B1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleTest", "ConsoleTest\ConsoleTest.csproj", "{A8B0E4D8-0726-4248-BB6D-DAA2545270B1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csproj", "{792EF125-E2D4-457C-B536-BDAEFB49D14E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "Shared\Shared.csproj", "{792EF125-E2D4-457C-B536-BDAEFB49D14E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entity", "Entity\Entity.csproj", "{69A4450C-AA43-4622-A866-9A5F7C8A2C14}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entity", "Entity\Entity.csproj", "{69A4450C-AA43-4622-A866-9A5F7C8A2C14}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contextlib", "Contextlib\Contextlib.csproj", "{32977454-CE94-4532-AE26-29F6951B78CF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Contextlib", "Contextlib\Contextlib.csproj", "{32977454-CE94-4532-AE26-29F6951B78CF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubbedContextLib", "StubbedContextLib\StubbedContextLib.csproj", "{5CD69B14-C6AE-4628-A374-996C486E25F2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubbedContextLib", "StubbedContextLib\StubbedContextLib.csproj", "{5CD69B14-C6AE-4628-A374-996C486E25F2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestModel2Entities", "TestModel2Entities\TestModel2Entities.csproj", "{2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestModel2Entities", "TestModel2Entities\TestModel2Entities.csproj", "{2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entities", "Model\Entities.csproj", "{C51815EE-ED06-4F38-955E-7EBB72C0A7EF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model2Entities", "Model2entities\Model2Entities.csproj", "{4A1CBA3D-C798-4E19-865F-39F919F1205A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model2Entities", "Model2entities\Model2Entities.csproj", "{4A1CBA3D-C798-4E19-865F-39F919F1205A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XUnitTest", "XUnitTest\XUnitTest.csproj", "{48002CA2-7CFF-4077-90CF-392476320CE3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XUnitTest", "XUnitTest\XUnitTest.csproj", "{48002CA2-7CFF-4077-90CF-392476320CE3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WfApi", "WfApi\WfApi.csproj", "{D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WfApi", "WfApi\WfApi.csproj", "{D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model", "Model\Model.csproj", "{708875DC-7ED1-4FD1-9321-3E00B2E7709B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -53,10 +53,6 @@ Global {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Debug|Any CPU.Build.0 = Debug|Any CPU {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Release|Any CPU.ActiveCfg = Release|Any CPU {2CF20FAC-C2F1-4048-9D46-F39081B0FBEF}.Release|Any CPU.Build.0 = Release|Any CPU - {C51815EE-ED06-4F38-955E-7EBB72C0A7EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C51815EE-ED06-4F38-955E-7EBB72C0A7EF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C51815EE-ED06-4F38-955E-7EBB72C0A7EF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C51815EE-ED06-4F38-955E-7EBB72C0A7EF}.Release|Any CPU.Build.0 = Release|Any CPU {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Debug|Any CPU.Build.0 = Debug|Any CPU {4A1CBA3D-C798-4E19-865F-39F919F1205A}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -69,6 +65,10 @@ Global {D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}.Debug|Any CPU.Build.0 = Debug|Any CPU {D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}.Release|Any CPU.ActiveCfg = Release|Any CPU {D4EEE1BF-CDCB-4E66-997B-7A5984DA7995}.Release|Any CPU.Build.0 = Release|Any CPU + {708875DC-7ED1-4FD1-9321-3E00B2E7709B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {708875DC-7ED1-4FD1-9321-3E00B2E7709B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {708875DC-7ED1-4FD1-9321-3E00B2E7709B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {708875DC-7ED1-4FD1-9321-3E00B2E7709B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE