diff --git a/Verax_API_EF/Verax_API_EF/API/Controllers/UserController.cs b/Verax_API_EF/Verax_API_EF/API/Controllers/UserController.cs index 3b4a285..c7ed3c2 100644 --- a/Verax_API_EF/Verax_API_EF/API/Controllers/UserController.cs +++ b/Verax_API_EF/Verax_API_EF/API/Controllers/UserController.cs @@ -18,6 +18,28 @@ namespace API.Controllers this._us = us; } + [HttpGet("/users")] + public async Task GetAll([FromQuery] int index = 0, [FromQuery] int count = 10, [FromQuery] UserOrderCriteria orderCriteria = UserOrderCriteria.None) + { + var result = (await _us.GetAll(index, count, orderCriteria)).Select(u => u.ToDTO()); + if (result == null) + { + return NotFound(); + } + return Ok(result); + } + + [HttpGet("/user/{pseudo}")] + public async Task GetByPseudo(string pseudo) + { + var result = (await _us.GetByPseudo(pseudo)).ToDTO(); + if (result == null) + { + return NotFound(); + } + return Ok(result); + } + [HttpPost("/user")] public async Task Create(User user) { @@ -37,27 +59,8 @@ namespace API.Controllers return await _us.Delete(pseudo); } - [HttpGet("/user/{pseudo}")] - public async Task GetByPseudo(string pseudo) - { - var result = (await _us.GetByPseudo(pseudo)).ToDTO(); - if (result == null) - { - return NotFound(); - } - return Ok(result); - } - [HttpGet("/users")] - public async Task GetAll([FromQuery] int index = 0, [FromQuery] int count = 10, [FromQuery] UserOrderCriteria orderCriteria = UserOrderCriteria.None) - { - var result = (await _us.GetAll(index, count, orderCriteria)).Select(u => u.ToDTO()); - if (result == null) - { - return NotFound(); - } - return Ok(result); - - } + + } } diff --git a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db index 2cd90a9..d1afbee 100644 Binary files a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db and b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db differ diff --git a/Verax_API_EF/Verax_API_EF/API/Program.cs b/Verax_API_EF/Verax_API_EF/API/Program.cs index 9bf4f16..7ee0854 100644 --- a/Verax_API_EF/Verax_API_EF/API/Program.cs +++ b/Verax_API_EF/Verax_API_EF/API/Program.cs @@ -38,8 +38,8 @@ app.MapControllers(); using var scoped = app.Services.CreateScope(); var libraryContext = scoped.ServiceProvider.GetService(); -//libraryContext.Database.EnsureCreated(); -libraryContext.Database.Migrate(); +libraryContext.Database.EnsureCreated(); +//libraryContext.Database.Migrate(); app.Run(); diff --git a/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs b/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs index 58c2539..774ded2 100644 --- a/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs +++ b/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs @@ -19,6 +19,8 @@ public class LibraryContext : DbContext public DbSet UserSet { get; set; } public DbSet FormSet { get; set; } + public DbSet ArticleUserSet { get; set; } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) @@ -91,6 +93,14 @@ public class LibraryContext : DbContext new UserEntity { Id = 3, Nom = "M&M's", Prenom = "Red", Pseudo = "RedM", Mail = "M&M#mail.com", Mdp = "1234", Role = "Modérator" + }, + new UserEntity + { + Id = 4, Nom = "Cascarra", Prenom = "Cascarra", Pseudo = "Sha", Mail = "ShaCasca@gmail.com", Mdp = "1234", Role = "Admin" + }, + new UserEntity + { + Id = 5, Nom = "Sillard", Prenom = "Noa", Pseudo = "NoaSil", Mail = "", Mdp = "1234", Role = "Admin" } ); diff --git a/Verax_API_EF/Verax_API_EF/StubbedContextLib/Migrations/20240307182411_mrg1.Designer.cs b/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240311132206_mrg1.Designer.cs similarity index 80% rename from Verax_API_EF/Verax_API_EF/StubbedContextLib/Migrations/20240307182411_mrg1.Designer.cs rename to Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240311132206_mrg1.Designer.cs index 1340e2b..6c21748 100644 --- a/Verax_API_EF/Verax_API_EF/StubbedContextLib/Migrations/20240307182411_mrg1.Designer.cs +++ b/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240311132206_mrg1.Designer.cs @@ -1,16 +1,16 @@ // +using DbContextLib; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using StubbedContextLib; #nullable disable -namespace StubbedContextLib.Migrations +namespace DbContextLib.Migrations { - [DbContext(typeof(StubbedContext))] - [Migration("20240307182411_mrg1")] + [DbContext(typeof(LibraryContext))] + [Migration("20240311132206_mrg1")] partial class mrg1 { /// @@ -90,7 +90,7 @@ namespace StubbedContextLib.Migrations b.HasIndex("UserEntityId"); - b.ToTable("ArticleUserEntity"); + b.ToTable("ArticleUserSet"); b.HasData( new @@ -150,6 +150,35 @@ namespace StubbedContextLib.Migrations b.HasIndex("UserEntityId"); b.ToTable("FormSet"); + + b.HasData( + new + { + Id = 1L, + DatePublication = "Form 1 Description", + Link = "hhtp://form1.com", + Pseudo = "Form 1", + Theme = "", + UserEntityId = 1L + }, + new + { + Id = 2L, + DatePublication = "Form 2 Description", + Link = "hhtp://form2.com", + Pseudo = "Form 2", + Theme = "", + UserEntityId = 2L + }, + new + { + Id = 3L, + DatePublication = "Form 3 Description", + Link = "hhtp://form3.com", + Pseudo = "Form 3", + Theme = "", + UserEntityId = 3L + }); }); modelBuilder.Entity("Entities.UserEntity", b => @@ -216,6 +245,26 @@ namespace StubbedContextLib.Migrations Prenom = "Red", Pseudo = "RedM", Role = "Modérator" + }, + new + { + Id = 4L, + Mail = "ShaCasca@gmail.com", + Mdp = "1234", + Nom = "Cascarra", + Prenom = "Cascarra", + Pseudo = "Sha", + Role = "Admin" + }, + new + { + Id = 5L, + Mail = "", + Mdp = "1234", + Nom = "Sillard", + Prenom = "Noa", + Pseudo = "NoaSil", + Role = "Admin" }); }); diff --git a/Verax_API_EF/Verax_API_EF/StubbedContextLib/Migrations/20240307182411_mrg1.cs b/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240311132206_mrg1.cs similarity index 83% rename from Verax_API_EF/Verax_API_EF/StubbedContextLib/Migrations/20240307182411_mrg1.cs rename to Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240311132206_mrg1.cs index a40c540..b9278d6 100644 --- a/Verax_API_EF/Verax_API_EF/StubbedContextLib/Migrations/20240307182411_mrg1.cs +++ b/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240311132206_mrg1.cs @@ -4,7 +4,7 @@ #pragma warning disable CA1814 // Prefer jagged arrays over multidimensional -namespace StubbedContextLib.Migrations +namespace DbContextLib.Migrations { /// public partial class mrg1 : Migration @@ -48,7 +48,7 @@ namespace StubbedContextLib.Migrations }); migrationBuilder.CreateTable( - name: "ArticleUserEntity", + name: "ArticleUserSet", columns: table => new { UserEntityId = table.Column(type: "INTEGER", nullable: false), @@ -56,15 +56,15 @@ namespace StubbedContextLib.Migrations }, constraints: table => { - table.PrimaryKey("PK_ArticleUserEntity", x => new { x.ArticleEntityId, x.UserEntityId }); + table.PrimaryKey("PK_ArticleUserSet", x => new { x.ArticleEntityId, x.UserEntityId }); table.ForeignKey( - name: "FK_ArticleUserEntity_ArticleSet_ArticleEntityId", + name: "FK_ArticleUserSet_ArticleSet_ArticleEntityId", column: x => x.ArticleEntityId, principalTable: "ArticleSet", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_ArticleUserEntity_UserSet_UserEntityId", + name: "FK_ArticleUserSet_UserSet_UserEntityId", column: x => x.UserEntityId, principalTable: "UserSet", principalColumn: "Id", @@ -111,11 +111,13 @@ namespace StubbedContextLib.Migrations { { 1L, "tony@gmail.com", "1234", "Fages", "Tony", "TonyF", "Admin" }, { 2L, "tom@mail.com", "1234", "Smith", "Tom", "TomS", "User" }, - { 3L, "M&M#mail.com", "1234", "M&M's", "Red", "RedM", "Modérator" } + { 3L, "M&M#mail.com", "1234", "M&M's", "Red", "RedM", "Modérator" }, + { 4L, "ShaCasca@gmail.com", "1234", "Cascarra", "Cascarra", "Sha", "Admin" }, + { 5L, "", "1234", "Sillard", "Noa", "NoaSil", "Admin" } }); migrationBuilder.InsertData( - table: "ArticleUserEntity", + table: "ArticleUserSet", columns: new[] { "ArticleEntityId", "UserEntityId" }, values: new object[,] { @@ -126,9 +128,19 @@ namespace StubbedContextLib.Migrations { 3L, 3L } }); + migrationBuilder.InsertData( + table: "FormSet", + columns: new[] { "Id", "DatePublication", "Link", "Pseudo", "Theme", "UserEntityId" }, + values: new object[,] + { + { 1L, "Form 1 Description", "hhtp://form1.com", "Form 1", "", 1L }, + { 2L, "Form 2 Description", "hhtp://form2.com", "Form 2", "", 2L }, + { 3L, "Form 3 Description", "hhtp://form3.com", "Form 3", "", 3L } + }); + migrationBuilder.CreateIndex( - name: "IX_ArticleUserEntity_UserEntityId", - table: "ArticleUserEntity", + name: "IX_ArticleUserSet_UserEntityId", + table: "ArticleUserSet", column: "UserEntityId"); migrationBuilder.CreateIndex( @@ -141,7 +153,7 @@ namespace StubbedContextLib.Migrations protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( - name: "ArticleUserEntity"); + name: "ArticleUserSet"); migrationBuilder.DropTable( name: "FormSet"); diff --git a/Verax_API_EF/Verax_API_EF/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs b/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/LibraryContextModelSnapshot.cs similarity index 80% rename from Verax_API_EF/Verax_API_EF/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs rename to Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/LibraryContextModelSnapshot.cs index c4e950b..4e992dc 100644 --- a/Verax_API_EF/Verax_API_EF/StubbedContextLib/Migrations/StubbedContextModelSnapshot.cs +++ b/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/LibraryContextModelSnapshot.cs @@ -1,15 +1,15 @@ // +using DbContextLib; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using StubbedContextLib; #nullable disable -namespace StubbedContextLib.Migrations +namespace DbContextLib.Migrations { - [DbContext(typeof(StubbedContext))] - partial class StubbedContextModelSnapshot : ModelSnapshot + [DbContext(typeof(LibraryContext))] + partial class LibraryContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { @@ -87,7 +87,7 @@ namespace StubbedContextLib.Migrations b.HasIndex("UserEntityId"); - b.ToTable("ArticleUserEntity"); + b.ToTable("ArticleUserSet"); b.HasData( new @@ -147,6 +147,35 @@ namespace StubbedContextLib.Migrations b.HasIndex("UserEntityId"); b.ToTable("FormSet"); + + b.HasData( + new + { + Id = 1L, + DatePublication = "Form 1 Description", + Link = "hhtp://form1.com", + Pseudo = "Form 1", + Theme = "", + UserEntityId = 1L + }, + new + { + Id = 2L, + DatePublication = "Form 2 Description", + Link = "hhtp://form2.com", + Pseudo = "Form 2", + Theme = "", + UserEntityId = 2L + }, + new + { + Id = 3L, + DatePublication = "Form 3 Description", + Link = "hhtp://form3.com", + Pseudo = "Form 3", + Theme = "", + UserEntityId = 3L + }); }); modelBuilder.Entity("Entities.UserEntity", b => @@ -213,6 +242,26 @@ namespace StubbedContextLib.Migrations Prenom = "Red", Pseudo = "RedM", Role = "Modérator" + }, + new + { + Id = 4L, + Mail = "ShaCasca@gmail.com", + Mdp = "1234", + Nom = "Cascarra", + Prenom = "Cascarra", + Pseudo = "Sha", + Role = "Admin" + }, + new + { + Id = 5L, + Mail = "", + Mdp = "1234", + Nom = "Sillard", + Prenom = "Noa", + Pseudo = "NoaSil", + Role = "Admin" }); }); diff --git a/Verax_API_EF/Verax_API_EF/StubbedContextLib/StubTest.cs b/Verax_API_EF/Verax_API_EF/StubbedContextLib/StubTest.cs deleted file mode 100644 index 6e01d1f..0000000 --- a/Verax_API_EF/Verax_API_EF/StubbedContextLib/StubTest.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Entities; -using Model; - -namespace StubbedContextLib; - -public class StubTest -{ - private List
_article; - - public List
StubArticle() - { - _article = new List
- { - new Article - { - Id = 1, - Title = "Test", - Description = "Test", - Author = "Test", - DatePublished = "Test", - LectureTime = 1 - } - }; - return _article; - } -} \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db new file mode 100644 index 0000000..16746d5 Binary files /dev/null and b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db differ diff --git a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db-shm similarity index 98% rename from Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm rename to Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db-shm index 9662394..edfc9f0 100644 Binary files a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm and b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db-shm differ diff --git a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-wal b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db-wal similarity index 94% rename from Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-wal rename to Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db-wal index f654cc2..e170424 100644 Binary files a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-wal and b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db-wal differ diff --git a/Verax_API_EF/Verax_API_EF/Test_Console_EF/Program.cs b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Program.cs deleted file mode 100644 index 5077f83..0000000 --- a/Verax_API_EF/Verax_API_EF/Test_Console_EF/Program.cs +++ /dev/null @@ -1,83 +0,0 @@ -// See https://aka.ms/new-console-template for more information - -using DbContextLib; -using Entities; - -addArticle(); -listArticle(); - -// Allows to list all the articles from the db -void listArticle() -{ - using (var context = new LibraryContext()) - { - var articles = context.ArticleSet; - foreach (var article in articles) - { - Console.WriteLine($"{article.Author} - {article.Title} - {article.Description} - {article.DatePublished} - {article.LectureTime}"); - } - } -} - - -// Allows to list all the articles from the db by author -void listArticleByAuthor() -{ - using (var context = new LibraryContext()) - { - var articles = context.ArticleSet.Where(a => a.Author.Equals("Tony Fages")); - foreach (var article in articles) - { - Console.WriteLine($"{article.Author} - {article.Title} - {article.Description} - {article.DatePublished} - {article.LectureTime}"); - } - } -} - -// Allows to add an article to the db -void addArticle() -{ - using (var context = new LibraryContext()) - { - var article = new ArticleEntity - { - Title = "Louis is not sick anymore", - Description = "Louis is not sick anymore, he is now healthy and happy", - DatePublished = "16-02-2024", - LectureTime = 1, - Author = "Tony Fages" - }; - context.ArticleSet.Add(article); - context.SaveChanges(); - } -} - - -// Allows to modify an article from the db -void modifyArticle() -{ - using (var context = new LibraryContext()) - { - var article = context.ArticleSet.Where(a => a.Author.Equals("Tom Smith")); - - foreach (var articles in article) - { - articles.Title = "Demain des l'aube"; - context.SaveChanges(); - } - } -} - -// Allows to delete an article from the db -void deleteArticle() -{ - using (var context = new LibraryContext()) - { - var article = context.ArticleSet.Where(a => a.Author.Equals("M&M's Red")); - - foreach (var articles in article) - { - context.ArticleSet.Remove(articles); - context.SaveChanges(); - } - } -} \ No newline at end of file diff --git a/Verax_API_EF/Verax_API_EF/Test_Console_EF/Test_Console_Article.cs b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Test_Console_Article.cs new file mode 100644 index 0000000..ae275db --- /dev/null +++ b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Test_Console_Article.cs @@ -0,0 +1,304 @@ +// See https://aka.ms/new-console-template for more information + +using DbContextLib; +using Entities; + +//Article +//addArticle(); +listArticle(); +//modifyArticle(); +//deleteArticle(); +//listArticleByAuthor(); + +//Form +//addForm(); +listForms(); +//updateForm(); +//deleteForm(); + +//User +//listUser(); +//addUser(); +//updateUser(); +//deleteUser(); + +//ArticleUser +//listArticleUser(); +//addArticleUser(); +//updateArticleUser(); +//deleteArticleUser(); + +//FormUser +listFormUser(); +//addFormUser(); + + +// Allows to list all the articles from the db +void listArticle() +{ + using (var context = new LibraryContext()) + { + var articles = context.ArticleSet; + foreach (var article in articles) + { + Console.WriteLine($"{article.Author} - {article.Title} - {article.Description} - {article.DatePublished} - {article.LectureTime}"); + } + } +} + + +// Allows to list all the articles from the db by author +void listArticleByAuthor() +{ + using (var context = new LibraryContext()) + { + var articles = context.ArticleSet.Where(a => a.Author.Equals("Tony Fages")); + foreach (var article in articles) + { + Console.WriteLine($"{article.Author} - {article.Title} - {article.Description} - {article.DatePublished} - {article.LectureTime}"); + } + } +} + +// Allows to add an article to the db +void addArticle() +{ + using (var context = new LibraryContext()) + { + var article = new ArticleEntity + { + Title = "Louis is not sick anymore", + Description = "Louis is not sick anymore, he is now healthy and happy", + DatePublished = "16-02-2024", + LectureTime = 1, + Author = "Tony Fages" + }; + context.ArticleSet.Add(article); + context.SaveChanges(); + } +} + + +// Allows to modify an article from the db +void modifyArticle() +{ + using (var context = new LibraryContext()) + { + var article = context.ArticleSet.Where(a => a.Author.Equals("Tom Smith")); + + foreach (var articles in article) + { + articles.Title = "Demain des l'aube"; + context.SaveChanges(); + } + } +} + +// Allows to delete an article from the db +void deleteArticle() +{ + using (var context = new LibraryContext()) + { + var article = context.ArticleSet.Where(a => a.Author.Equals("M&M's Red")); + + foreach (var articles in article) + { + context.ArticleSet.Remove(articles); + context.SaveChanges(); + } + } +} + +// Allow to get all forms +void listForms() +{ + using (var context = new LibraryContext()) + { + var forms = context.FormSet; + foreach (var form in forms) + { + Console.WriteLine($"{form.Id} - {form.Link} - {form.DatePublication} - {form.Pseudo} - {form.Theme} - {form.UserEntityId}"); + } + } +} + +void addForm() +{ + using (var context = new LibraryContext()) + { + var form = new FormEntity + { + Id = 5, + Theme = "Covid", + DatePublication = "16-02-2024", + Link = "https://www.covid.com", + Pseudo = "Tony Fages", + UserEntityId = 1 + }; + context.FormSet.Add(form); + context.SaveChanges(); + } +} + +void updateForm() +{ + using (var context = new LibraryContext()) + { + var form = context.FormSet.Where(f => f.Id.Equals(5)); + + foreach (var forms in form) + { + forms.Theme = "Demain des l'aube"; + context.SaveChanges(); + } + } +} + +void deleteForm() +{ + using (var context = new LibraryContext()) + { + var form = context.FormSet.Where(f => f.Id.Equals(5)); + + foreach (var forms in form) + { + context.FormSet.Remove(forms); + context.SaveChanges(); + } + } +} + +void listUser() +{ + using (var context = new LibraryContext()) + { + var users = context.UserSet; + foreach (var user in users) + { + Console.WriteLine($"{user.Id} - {user.Pseudo} - {user.Nom} - {user.Prenom} - {user.Mail} - {user.Role}"); + } + } +} + +void addUser() +{ + using (var context = new LibraryContext()) + { + var user = new UserEntity + { + Id = 7, Nom = "Fages", Prenom = "Tony", Pseudo = "TonyF", Mail = "tony@gmail.com", Mdp = "1234", Role = "Admin" + }; + context.UserSet.Add(user); + context.SaveChanges(); + } + listUser(); +} + +void updateUser() +{ + using (var context = new LibraryContext()) + { + var user = context.UserSet.Where(u => u.Id.Equals(7)); + + foreach (var users in user) + { + users.Nom = "Thomas"; + context.SaveChanges(); + } + } + listUser(); +} + +void deleteUser() +{ + using (var context = new LibraryContext()) + { + var user = context.UserSet.Where(u => u.Id.Equals(7)); + + foreach (var users in user) + { + context.UserSet.Remove(users); + context.SaveChanges(); + } + } + listUser(); +} + +void listArticleUser() +{ + using (var context = new LibraryContext()) + { + var articleUsers = context.ArticleUserSet; + foreach (var articleUser in articleUsers) + { + Console.WriteLine($"{articleUser.ArticleEntityId} - {articleUser.UserEntityId}"); + } + } +} + +void addArticleUser() +{ + using (var context = new LibraryContext()) + { + var articleUser = new ArticleUserEntity + { + ArticleEntityId = 2, + UserEntityId = 1 + }; + context.ArticleUserSet.Add(articleUser); + context.SaveChanges(); + } + listArticleUser(); +} + +void updateArticleUser() +{ + using (var context = new LibraryContext()) + { + var articleUser = context.ArticleUserSet.FirstOrDefault(au => au.UserEntityId.Equals(2)); + if (articleUser != null) articleUser.UserEntityId = 3; + context.SaveChanges(); + } + listArticleUser(); +} + +void deleteArticleUser() +{ + using (var context = new LibraryContext()) + { + var articleUser = context.ArticleUserSet.Where(au => au.UserEntityId.Equals(1)).Where(u => u.ArticleEntityId.Equals(1)); + + foreach (var articleUsers in articleUser) + { + context.ArticleUserSet.Remove(articleUsers); + context.SaveChanges(); + } + } + listArticleUser(); +} + +void listFormUser() +{ + using (var context = new LibraryContext()) + { + var formUsers = context.FormSet; + foreach (var formUser in formUsers) + { + Console.WriteLine($"{formUser.UserEntityId}"); + } + } +} + +void addFormUser() +{ + using (var context = new LibraryContext()) + { + var formUser = new FormEntity + { + UserEntityId = 1 + }; + context.FormSet.Add(formUser); + context.SaveChanges(); + } +} +