From ad4377ffc77cfc4bebfbb24ab3e5e0618b1df699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=91=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D1=81=D0=BA=D0=B0=D1=8F?= Date: Tue, 30 Apr 2024 16:20:00 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0=20ProcedureRecipe=20=D0=BD=D0=B0=20RecipeProcedure,=20?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0=20=D0=B1=D0=B4=20=D0=B8=20=D0=BC=D0=B8=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/ProcedureBindingModel.cs | 8 +-- .../BindingModels/RecipeBindingModel.cs | 1 + .../ViewModels/ProcedureViewModel.cs | 1 - .../ViewModels/RecipeViewModel.cs | 2 + .../Models/IProcedureModel.cs | 1 - .../Models/IRecipeModel.cs | 1 + .../Implements/ProcedureStorage.cs | 32 +++------- .../Implements/RecipeStorage.cs | 56 +++++++++++++----- ... => 20240430121818_InitCreate.Designer.cs} | 58 +++++++++---------- ...tabase.cs => 20240430121818_InitCreate.cs} | 20 +++---- .../PolyclinicDatabaseModelSnapshot.cs | 54 ++++++++--------- .../Models/Procedure.cs | 51 +--------------- .../Models/Recipe.cs | 47 ++++++++++++++- ...{ProcedureRecipe.cs => RecipeProcedure.cs} | 2 +- .../PolyclinicDatabase.cs | 2 +- 15 files changed, 173 insertions(+), 163 deletions(-) rename Polyclinic/PolyclinicDatabaseImplement/Migrations/{20240430074427_InitializeDatabase.Designer.cs => 20240430121818_InitCreate.Designer.cs} (97%) rename Polyclinic/PolyclinicDatabaseImplement/Migrations/{20240430074427_InitializeDatabase.cs => 20240430121818_InitCreate.cs} (96%) rename Polyclinic/PolyclinicDatabaseImplement/Models/{ProcedureRecipe.cs => RecipeProcedure.cs} (92%) diff --git a/Polyclinic/PolyclinicContracts/BindingModels/ProcedureBindingModel.cs b/Polyclinic/PolyclinicContracts/BindingModels/ProcedureBindingModel.cs index 344ab1c..5f09139 100644 --- a/Polyclinic/PolyclinicContracts/BindingModels/ProcedureBindingModel.cs +++ b/Polyclinic/PolyclinicContracts/BindingModels/ProcedureBindingModel.cs @@ -2,13 +2,11 @@ namespace PolyclinicContracts.BindingModels { - public class ProcedureBindingModel : IProcedureModel + public class ProcedureBindingModel : IProcedureModel { public int Id { get; set; } - public int UserId { get; set; } + public int UserId { get; set; } public string Name { get; set; } = string.Empty; - public string Comment { get; set; } = string.Empty; - public Dictionary ProcedureRecipes { get; set; } = new(); - + public string Comment { get; set; } = string.Empty; } } \ No newline at end of file diff --git a/Polyclinic/PolyclinicContracts/BindingModels/RecipeBindingModel.cs b/Polyclinic/PolyclinicContracts/BindingModels/RecipeBindingModel.cs index 28311de..fdf120b 100644 --- a/Polyclinic/PolyclinicContracts/BindingModels/RecipeBindingModel.cs +++ b/Polyclinic/PolyclinicContracts/BindingModels/RecipeBindingModel.cs @@ -7,5 +7,6 @@ namespace PolyclinicContracts.BindingModels public int Id { get; set; } public int ProceduresCount { get; set; } public string Comment { get; set; } = string.Empty; + public Dictionary RecipeProcedures { get; } = new(); } } \ No newline at end of file diff --git a/Polyclinic/PolyclinicContracts/ViewModels/ProcedureViewModel.cs b/Polyclinic/PolyclinicContracts/ViewModels/ProcedureViewModel.cs index eb70d53..dccc9d6 100644 --- a/Polyclinic/PolyclinicContracts/ViewModels/ProcedureViewModel.cs +++ b/Polyclinic/PolyclinicContracts/ViewModels/ProcedureViewModel.cs @@ -11,6 +11,5 @@ namespace PolyclinicContracts.ViewModels public string Name { get; set; } = string.Empty; [DisplayName("Комментарий")] public string Comment { get; set; } = string.Empty; - public Dictionary ProcedureRecipes { get; set; } = new(); } } \ No newline at end of file diff --git a/Polyclinic/PolyclinicContracts/ViewModels/RecipeViewModel.cs b/Polyclinic/PolyclinicContracts/ViewModels/RecipeViewModel.cs index 26d7d31..b22d3b2 100644 --- a/Polyclinic/PolyclinicContracts/ViewModels/RecipeViewModel.cs +++ b/Polyclinic/PolyclinicContracts/ViewModels/RecipeViewModel.cs @@ -12,5 +12,7 @@ namespace PolyclinicContracts.ViewModels [DisplayName("Комментарий")] public string Comment { get; set; } = string.Empty; + + public Dictionary RecipeProcedures { get; } = new(); } } diff --git a/Polyclinic/PolyclinicDataModels/Models/IProcedureModel.cs b/Polyclinic/PolyclinicDataModels/Models/IProcedureModel.cs index 47827ad..500e459 100644 --- a/Polyclinic/PolyclinicDataModels/Models/IProcedureModel.cs +++ b/Polyclinic/PolyclinicDataModels/Models/IProcedureModel.cs @@ -5,6 +5,5 @@ string Name { get; } string Comment { get; } int UserId { get; } - Dictionary ProcedureRecipes { get; } } } \ No newline at end of file diff --git a/Polyclinic/PolyclinicDataModels/Models/IRecipeModel.cs b/Polyclinic/PolyclinicDataModels/Models/IRecipeModel.cs index f9ba21c..f912678 100644 --- a/Polyclinic/PolyclinicDataModels/Models/IRecipeModel.cs +++ b/Polyclinic/PolyclinicDataModels/Models/IRecipeModel.cs @@ -4,5 +4,6 @@ { int ProceduresCount { get; set; } string Comment { get; set; } + Dictionary RecipeProcedures { get; } } } \ No newline at end of file diff --git a/Polyclinic/PolyclinicDatabaseImplement/Implements/ProcedureStorage.cs b/Polyclinic/PolyclinicDatabaseImplement/Implements/ProcedureStorage.cs index 60c77b5..63002db 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Implements/ProcedureStorage.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Implements/ProcedureStorage.cs @@ -14,8 +14,6 @@ namespace PolyclinicDatabaseImplement.Implements { using var database = new PolyclinicDatabase(); return database.Procedures - .Include(x => x.Recipes) - .ThenInclude(x => x.Recipe) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -29,8 +27,6 @@ namespace PolyclinicDatabaseImplement.Implements } using var database = new PolyclinicDatabase(); return database.Procedures - .Include(x => x.Recipes) - .ThenInclude(x => x.Recipe) .Where(x => x.Name == model.Name) .Select(x => x.GetViewModel) .ToList(); @@ -45,8 +41,6 @@ namespace PolyclinicDatabaseImplement.Implements } using var database = new PolyclinicDatabase(); return database.Procedures - .Include(x => x.Recipes) - .ThenInclude(x => x.Recipe) .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } @@ -54,7 +48,7 @@ namespace PolyclinicDatabaseImplement.Implements public ProcedureViewModel? Insert(ProcedureBindingModel model) { using var database = new PolyclinicDatabase(); - var newProcedure = Procedure.Create(database, model); + var newProcedure = Procedure.Create(model); if (newProcedure == null) { return null; @@ -66,31 +60,19 @@ namespace PolyclinicDatabaseImplement.Implements public ProcedureViewModel? Update(ProcedureBindingModel model) { using var database = new PolyclinicDatabase(); - using var transaction = database.Database.BeginTransaction(); - try + var procedure = database.Procedures.FirstOrDefault(x => x.Id == model.Id); + if (procedure == null) { - var Procedure = database.Procedures.FirstOrDefault(rec => rec.Id == model.Id); - if (Procedure == null) - { - return null; - } - Procedure.Update(model); - database.SaveChanges(); - Procedure.UpdateRecipes(database, model); - transaction.Commit(); - return Procedure.GetViewModel; - } - catch - { - transaction.Rollback(); - throw; + return null; } + procedure.Update(model); + database.SaveChanges(); + return procedure.GetViewModel; } public ProcedureViewModel? Delete(ProcedureBindingModel model) { using var database = new PolyclinicDatabase(); var element = database.Procedures - .Include(x => x.Recipes) .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { diff --git a/Polyclinic/PolyclinicDatabaseImplement/Implements/RecipeStorage.cs b/Polyclinic/PolyclinicDatabaseImplement/Implements/RecipeStorage.cs index c9d0583..d3aa7a6 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Implements/RecipeStorage.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Implements/RecipeStorage.cs @@ -1,4 +1,5 @@ -using PolyclinicContracts.BindingModels; +using Microsoft.EntityFrameworkCore; +using PolyclinicContracts.BindingModels; using PolyclinicContracts.SearchModels; using PolyclinicContracts.StoragesContracts; using PolyclinicContracts.ViewModels; @@ -12,7 +13,11 @@ namespace PolyclinicDatabaseImplement.Implements public List GetFullList() { using var database = new PolyclinicDatabase(); - return database.Recipes.Select(x => x.GetViewModel).ToList(); + return database.Recipes + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) + .Select(x => x.GetViewModel) + .ToList(); } public List GetFilteredList(RecipeSearchModel bindingModel) { @@ -21,7 +26,12 @@ namespace PolyclinicDatabaseImplement.Implements return new(); } using var database = new PolyclinicDatabase(); - return database.Recipes.Where(x => x.Comment.Contains(bindingModel.Comment)).Select(x => x.GetViewModel).ToList(); + return database.Recipes + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) + .Where(x => x.Comment.Contains(bindingModel.Comment)) + .Select(x => x.GetViewModel) + .ToList(); } public RecipeViewModel? GetElement(RecipeSearchModel bindingModel) @@ -31,15 +41,20 @@ namespace PolyclinicDatabaseImplement.Implements return null; } using var database = new PolyclinicDatabase(); - return database.Recipes.FirstOrDefault(x => (!string.IsNullOrEmpty(bindingModel.Comment) && - x.Comment == bindingModel.Comment) || (bindingModel.Id.HasValue && x.Id == bindingModel.Id))?.GetViewModel; + return database.Recipes + .Include(x => x.Procedures) + .ThenInclude(x => x.Procedure) + .FirstOrDefault(x => (!string.IsNullOrEmpty(bindingModel.Comment) && + x.Comment == bindingModel.Comment) || + (bindingModel.Id.HasValue && x.Id == bindingModel.Id))? + .GetViewModel; } public RecipeViewModel? Insert(RecipeBindingModel bindingModel) { using var database = new PolyclinicDatabase(); - var newRecipe = Recipe.Create(bindingModel); - if(newRecipe == null) + var newRecipe = Recipe.Create(database, bindingModel); + if (newRecipe == null) { return null; } @@ -51,20 +66,33 @@ namespace PolyclinicDatabaseImplement.Implements public RecipeViewModel? Update(RecipeBindingModel bindingModel) { using var database = new PolyclinicDatabase(); - var recipe = database.Recipes.FirstOrDefault(x => x.Id == bindingModel.Id); - if(recipe == null) + using var transaction = database.Database.BeginTransaction(); + try { - return null; + var Recipe = database.Recipes.FirstOrDefault(rec => rec.Id == bindingModel.Id); + if (Recipe == null) + { + return null; + } + Recipe.Update(bindingModel); + database.SaveChanges(); + Recipe.UpdateProcedures(database, bindingModel); + transaction.Commit(); + return Recipe.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; } - recipe.Update(bindingModel); - database.SaveChanges(); - return recipe.GetViewModel; } public RecipeViewModel? Delete(RecipeBindingModel bindingModel) { using var database = new PolyclinicDatabase(); - var recipe = database.Recipes.FirstOrDefault(x => x.Id == bindingModel.Id); + var recipe = database.Recipes + .Include(x => x.Procedures) + .FirstOrDefault(x => x.Id == bindingModel.Id); if (recipe == null) { return null; diff --git a/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240430074427_InitializeDatabase.Designer.cs b/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240430121818_InitCreate.Designer.cs similarity index 97% rename from Polyclinic/PolyclinicDatabaseImplement/Migrations/20240430074427_InitializeDatabase.Designer.cs rename to Polyclinic/PolyclinicDatabaseImplement/Migrations/20240430121818_InitCreate.Designer.cs index 6e6261c..86163da 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240430074427_InitializeDatabase.Designer.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240430121818_InitCreate.Designer.cs @@ -11,8 +11,8 @@ using SecuritySystemDatabaseImplement; namespace PolyclinicDatabaseImplement.Migrations { [DbContext(typeof(PolyclinicDatabase))] - [Migration("20240430074427_InitializeDatabase")] - partial class InitializeDatabase + [Migration("20240430121818_InitCreate")] + partial class InitCreate { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -156,7 +156,27 @@ namespace PolyclinicDatabaseImplement.Migrations b.ToTable("Procedures"); }); - modelBuilder.Entity("PolyclinicDatabaseImplement.Models.ProcedureRecipe", b => + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Recipe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Comment") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ProceduresCount") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Recipes"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.RecipeProcedure", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -176,27 +196,7 @@ namespace PolyclinicDatabaseImplement.Migrations b.HasIndex("RecipeId"); - b.ToTable("ProcedureRecipes"); - }); - - modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Recipe", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Comment") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("ProceduresCount") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("Recipes"); + b.ToTable("RecipeProcedures"); }); modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Symptom", b => @@ -354,16 +354,16 @@ namespace PolyclinicDatabaseImplement.Migrations b.Navigation("Symptom"); }); - modelBuilder.Entity("PolyclinicDatabaseImplement.Models.ProcedureRecipe", b => + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.RecipeProcedure", b => { b.HasOne("PolyclinicDatabaseImplement.Models.Procedure", "Procedure") - .WithMany("Recipes") + .WithMany() .HasForeignKey("ProcedureId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PolyclinicDatabaseImplement.Models.Recipe", "Recipe") - .WithMany() + .WithMany("Procedures") .HasForeignKey("RecipeId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -416,9 +416,9 @@ namespace PolyclinicDatabaseImplement.Migrations b.Navigation("Diagnoses"); }); - modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Procedure", b => + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Recipe", b => { - b.Navigation("Recipes"); + b.Navigation("Procedures"); }); modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Symptom", b => diff --git a/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240430074427_InitializeDatabase.cs b/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240430121818_InitCreate.cs similarity index 96% rename from Polyclinic/PolyclinicDatabaseImplement/Migrations/20240430074427_InitializeDatabase.cs rename to Polyclinic/PolyclinicDatabaseImplement/Migrations/20240430121818_InitCreate.cs index f85fb17..1dd5edc 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240430074427_InitializeDatabase.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Migrations/20240430121818_InitCreate.cs @@ -5,7 +5,7 @@ namespace PolyclinicDatabaseImplement.Migrations { /// - public partial class InitializeDatabase : Migration + public partial class InitCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -92,7 +92,7 @@ namespace PolyclinicDatabaseImplement.Migrations }); migrationBuilder.CreateTable( - name: "ProcedureRecipes", + name: "RecipeProcedures", columns: table => new { Id = table.Column(type: "int", nullable: false) @@ -102,15 +102,15 @@ namespace PolyclinicDatabaseImplement.Migrations }, constraints: table => { - table.PrimaryKey("PK_ProcedureRecipes", x => x.Id); + table.PrimaryKey("PK_RecipeProcedures", x => x.Id); table.ForeignKey( - name: "FK_ProcedureRecipes_Procedures_ProcedureId", + name: "FK_RecipeProcedures_Procedures_ProcedureId", column: x => x.ProcedureId, principalTable: "Procedures", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_ProcedureRecipes_Recipes_RecipeId", + name: "FK_RecipeProcedures_Recipes_RecipeId", column: x => x.RecipeId, principalTable: "Recipes", principalColumn: "Id", @@ -275,13 +275,13 @@ namespace PolyclinicDatabaseImplement.Migrations column: "SymptomId"); migrationBuilder.CreateIndex( - name: "IX_ProcedureRecipes_ProcedureId", - table: "ProcedureRecipes", + name: "IX_RecipeProcedures_ProcedureId", + table: "RecipeProcedures", column: "ProcedureId"); migrationBuilder.CreateIndex( - name: "IX_ProcedureRecipes_RecipeId", - table: "ProcedureRecipes", + name: "IX_RecipeProcedures_RecipeId", + table: "RecipeProcedures", column: "RecipeId"); migrationBuilder.CreateIndex( @@ -315,7 +315,7 @@ namespace PolyclinicDatabaseImplement.Migrations name: "Medicaments"); migrationBuilder.DropTable( - name: "ProcedureRecipes"); + name: "RecipeProcedures"); migrationBuilder.DropTable( name: "SymptomDiagnoses"); diff --git a/Polyclinic/PolyclinicDatabaseImplement/Migrations/PolyclinicDatabaseModelSnapshot.cs b/Polyclinic/PolyclinicDatabaseImplement/Migrations/PolyclinicDatabaseModelSnapshot.cs index 90355e1..5066c49 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Migrations/PolyclinicDatabaseModelSnapshot.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Migrations/PolyclinicDatabaseModelSnapshot.cs @@ -153,7 +153,27 @@ namespace PolyclinicDatabaseImplement.Migrations b.ToTable("Procedures"); }); - modelBuilder.Entity("PolyclinicDatabaseImplement.Models.ProcedureRecipe", b => + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Recipe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Comment") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ProceduresCount") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Recipes"); + }); + + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.RecipeProcedure", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -173,27 +193,7 @@ namespace PolyclinicDatabaseImplement.Migrations b.HasIndex("RecipeId"); - b.ToTable("ProcedureRecipes"); - }); - - modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Recipe", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Comment") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("ProceduresCount") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("Recipes"); + b.ToTable("RecipeProcedures"); }); modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Symptom", b => @@ -351,16 +351,16 @@ namespace PolyclinicDatabaseImplement.Migrations b.Navigation("Symptom"); }); - modelBuilder.Entity("PolyclinicDatabaseImplement.Models.ProcedureRecipe", b => + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.RecipeProcedure", b => { b.HasOne("PolyclinicDatabaseImplement.Models.Procedure", "Procedure") - .WithMany("Recipes") + .WithMany() .HasForeignKey("ProcedureId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("PolyclinicDatabaseImplement.Models.Recipe", "Recipe") - .WithMany() + .WithMany("Procedures") .HasForeignKey("RecipeId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -413,9 +413,9 @@ namespace PolyclinicDatabaseImplement.Migrations b.Navigation("Diagnoses"); }); - modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Procedure", b => + modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Recipe", b => { - b.Navigation("Recipes"); + b.Navigation("Procedures"); }); modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Symptom", b => diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/Procedure.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/Procedure.cs index acb2cb3..7236289 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/Procedure.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/Procedure.cs @@ -3,7 +3,6 @@ using PolyclinicContracts.ViewModels; using PolyclinicDataModels.Models; using SecuritySystemDatabaseImplement; using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; namespace PolyclinicDatabaseImplement.Models { @@ -15,30 +14,12 @@ namespace PolyclinicDatabaseImplement.Models public int UserId { get; set; } [Required] - public string Name { get; set; } = string.Empty; + public string Name { get; set; } = string.Empty; [Required] public string Comment { get; set; } = string.Empty; - private Dictionary? _procedureRecipes = null; - - [ForeignKey("ProcedureId")] - public virtual List Recipes { get; set; } = new(); - - [NotMapped] - public Dictionary ProcedureRecipes - { - get - { - if(_procedureRecipes == null) - { - _procedureRecipes = Recipes.ToDictionary(recPC => recPC.RecipeId, recPC => (recPC.Recipe as IRecipeModel)); - } - return _procedureRecipes; - } - } - - public static Procedure Create(PolyclinicDatabase database, ProcedureBindingModel bindingModel) + public static Procedure Create(ProcedureBindingModel bindingModel) { return new Procedure() { @@ -46,10 +27,6 @@ namespace PolyclinicDatabaseImplement.Models UserId = bindingModel.UserId, Name = bindingModel.Name, Comment = bindingModel.Comment, - Recipes = bindingModel.ProcedureRecipes.Select(x => new ProcedureRecipe - { - Recipe = database.Recipes.First(y => y.Id == x.Key) - }).ToList() }; } @@ -65,28 +42,6 @@ namespace PolyclinicDatabaseImplement.Models Name = Name, UserId = UserId, Comment = Comment, - }; - - public void UpdateRecipes(PolyclinicDatabase database, ProcedureBindingModel bindingModel) - { - var ProcedureRecipes = database.ProcedureRecipes.Where(x => x.ProcedureId == bindingModel.Id).ToList(); - - if(ProcedureRecipes != null) - { - // удалили те, которых нет в модели - database.ProcedureRecipes.RemoveRange(ProcedureRecipes.Where(rec => !bindingModel.ProcedureRecipes.ContainsKey(rec.RecipeId))); - database.SaveChanges(); - } - var Procedure = database.Procedures.First(x => x.Id == bindingModel.Id); - foreach (var pc in bindingModel.ProcedureRecipes) - { - database.ProcedureRecipes.Add(new ProcedureRecipe - { - Procedure = Procedure, - Recipe = database.Recipes.First(x => x.Id == pc.Key) - }); - } - _procedureRecipes = null; - } + }; } } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs index 0648311..e04a34c 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs @@ -3,6 +3,7 @@ using PolyclinicContracts.ViewModels; using PolyclinicDataModels.Models; using SecuritySystemDatabaseImplement; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; namespace PolyclinicDatabaseImplement.Models { @@ -16,13 +17,35 @@ namespace PolyclinicDatabaseImplement.Models [Required] public string Comment { get; set; } = string.Empty; - public static Recipe Create( RecipeBindingModel bindingModel) + private Dictionary? _recipeProcedures = null; + + [ForeignKey("RecipeId")] + public virtual List Procedures { get; set; } = new(); + + [NotMapped] + public Dictionary RecipeProcedures + { + get + { + if (_recipeProcedures == null) + { + _recipeProcedures = Procedures.ToDictionary(recPC => recPC.ProcedureId, recPC => (recPC.Procedure as IProcedureModel)); + } + return _recipeProcedures; + } + } + + public static Recipe Create(PolyclinicDatabase database, RecipeBindingModel bindingModel) { return new Recipe() { Id = bindingModel.Id, ProceduresCount = bindingModel.ProceduresCount, Comment = bindingModel.Comment, + Procedures = bindingModel.RecipeProcedures.Select(x => new RecipeProcedure + { + Recipe = database.Recipes.First(y => y.Id == x.Key) + }).ToList() }; } @@ -38,5 +61,27 @@ namespace PolyclinicDatabaseImplement.Models ProceduresCount = ProceduresCount, Comment = Comment }; + + public void UpdateProcedures(PolyclinicDatabase database, RecipeBindingModel bindingModel) + { + var RecipeProcedures = database.RecipeProcedures.Where(x => x.ProcedureId == bindingModel.Id).ToList(); + + if (RecipeProcedures != null) + { + // удалили те, которых нет в модели + database.RecipeProcedures.RemoveRange(RecipeProcedures.Where(rec => !bindingModel.RecipeProcedures.ContainsKey(rec.RecipeId))); + database.SaveChanges(); + } + var Procedure = database.Procedures.First(x => x.Id == bindingModel.Id); + foreach (var pc in bindingModel.RecipeProcedures) + { + database.RecipeProcedures.Add(new RecipeProcedure + { + Procedure = Procedure, + Recipe = database.Recipes.First(x => x.Id == pc.Key) + }); + } + _recipeProcedures = null; + } } } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/ProcedureRecipe.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/RecipeProcedure.cs similarity index 92% rename from Polyclinic/PolyclinicDatabaseImplement/Models/ProcedureRecipe.cs rename to Polyclinic/PolyclinicDatabaseImplement/Models/RecipeProcedure.cs index dd0251d..86b5369 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/ProcedureRecipe.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/RecipeProcedure.cs @@ -2,7 +2,7 @@ namespace PolyclinicDatabaseImplement.Models { - public class ProcedureRecipe + public class RecipeProcedure { public int Id { get; set; } [Required] diff --git a/Polyclinic/PolyclinicDatabaseImplement/PolyclinicDatabase.cs b/Polyclinic/PolyclinicDatabaseImplement/PolyclinicDatabase.cs index d19426b..316aa28 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/PolyclinicDatabase.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/PolyclinicDatabase.cs @@ -18,7 +18,7 @@ namespace SecuritySystemDatabaseImplement public virtual DbSet Diagnoses { set; get; } public virtual DbSet Medicaments { set; get; } public virtual DbSet Procedures { set; get; } - public virtual DbSet ProcedureRecipes { set; get; } + public virtual DbSet RecipeProcedures { set; get; } public virtual DbSet Recipes { set; get; } public virtual DbSet Symptomes { set; get; } public virtual DbSet SymptomDiagnoses { set; get; } From 53365b60091c82d687945451ce27e63b613cae53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=91=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D1=81=D0=BA=D0=B0=D1=8F?= Date: Tue, 30 Apr 2024 16:21:11 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0=20=D0=BF=D1=80=D0=B8=D0=BC=D0=B5=D1=80=D1=8B=20=D0=B8=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BB=D0=B0=20=D0=B2=D1=8C=D1=8E?= =?UTF-8?q?=D1=88=D0=BA=D0=B8=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D1=80=D0=B5?= =?UTF-8?q?=D0=BF=D0=B0=D1=80=D0=B0=D1=82=D0=BE=D0=B2,=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=86=D0=B5=D0=B4=D1=83=D1=80=20=D0=B8=20=D0=BD=D0=B0?= =?UTF-8?q?=D1=87=D0=B0=D0=BB=D0=B0=20=D1=80=D0=B5=D1=86=D0=B5=D0=BF=D1=82?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PolyclinicWebView.csproj | 9 +++- .../Views/Home/Medicaments.cshtml | 10 +++- .../Views/Home/Procedures.cshtml | 48 ++++++++++++++++-- .../Views/Home/Recipes.cshtml | 49 +++++++++++++++++-- 4 files changed, 108 insertions(+), 8 deletions(-) diff --git a/Polyclinic/PolyclinicWebView/PolyclinicWebView.csproj b/Polyclinic/PolyclinicWebView/PolyclinicWebView.csproj index 4eda501..89e1be2 100644 --- a/Polyclinic/PolyclinicWebView/PolyclinicWebView.csproj +++ b/Polyclinic/PolyclinicWebView/PolyclinicWebView.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -6,6 +6,13 @@ enable + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/Polyclinic/PolyclinicWebView/Views/Home/Medicaments.cshtml b/Polyclinic/PolyclinicWebView/Views/Home/Medicaments.cshtml index 9d2a20a..001c00e 100644 --- a/Polyclinic/PolyclinicWebView/Views/Home/Medicaments.cshtml +++ b/Polyclinic/PolyclinicWebView/Views/Home/Medicaments.cshtml @@ -32,7 +32,15 @@ - + + 1 + + + Фенибут + + + При особом неврозе употребляйте каждый день и спина не будет болеть + } diff --git a/Polyclinic/PolyclinicWebView/Views/Home/Procedures.cshtml b/Polyclinic/PolyclinicWebView/Views/Home/Procedures.cshtml index e1dd794..02cf854 100644 --- a/Polyclinic/PolyclinicWebView/Views/Home/Procedures.cshtml +++ b/Polyclinic/PolyclinicWebView/Views/Home/Procedures.cshtml @@ -1,5 +1,47 @@ -@* - For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 -*@ +@using PolyclinicContracts.ViewModels +@model List @{ + ViewData["Title"] = "Procedures"; } +
+

Процедуры

+
+ +
+ @{ + // if (Model == null) + // { + //

Авторизируйтесь

+ // return; + // } +

+ Создать процедуру +

+ + + + + + + + + + + + + +
+ Номер + + Название процедуры + + Комментарий +
+ 1 + + Массаж пяточек + + ммммммм +
+ } +
\ No newline at end of file diff --git a/Polyclinic/PolyclinicWebView/Views/Home/Recipes.cshtml b/Polyclinic/PolyclinicWebView/Views/Home/Recipes.cshtml index e1dd794..1832b3b 100644 --- a/Polyclinic/PolyclinicWebView/Views/Home/Recipes.cshtml +++ b/Polyclinic/PolyclinicWebView/Views/Home/Recipes.cshtml @@ -1,5 +1,48 @@ -@* - For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 -*@ +@using PolyclinicContracts.ViewModels +@model List @{ + ViewData["Title"] = "Recipes"; } +
+

Рецепты

+
+ +
+ @{ + // if (Model == null) + // { + //

Авторизируйтесь

+ // return; + // } +

+ Создать рецепт +

+ + + + + + + + + + + + + +
+ Номер + + Количество процедур + + Комментарий +
+ 1 + + 4 + + Вот столько процедур делайте + +
+ } +
\ No newline at end of file