Merge branch 'stage7_user_web_interface_prototype' of https://git.is.ulstu.ru/ns.potapov/PIbd-21_CourseWork_Polyclinic_BeSick into stage7_user_web_interface_prototype
This commit is contained in:
commit
e5b125041a
@ -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<int, IRecipeModel> ProcedureRecipes { get; set; } = new();
|
||||
|
||||
public string Comment { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -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<int, IProcedureModel> RecipeProcedures { get; } = new();
|
||||
}
|
||||
}
|
@ -11,6 +11,5 @@ namespace PolyclinicContracts.ViewModels
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Комментарий")]
|
||||
public string Comment { get; set; } = string.Empty;
|
||||
public Dictionary<int, IRecipeModel> ProcedureRecipes { get; set; } = new();
|
||||
}
|
||||
}
|
@ -12,5 +12,7 @@ namespace PolyclinicContracts.ViewModels
|
||||
|
||||
[DisplayName("Комментарий")]
|
||||
public string Comment { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<int, IProcedureModel> RecipeProcedures { get; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,5 @@
|
||||
string Name { get; }
|
||||
string Comment { get; }
|
||||
int UserId { get; }
|
||||
Dictionary<int, IRecipeModel> ProcedureRecipes { get; }
|
||||
}
|
||||
}
|
@ -4,5 +4,6 @@
|
||||
{
|
||||
int ProceduresCount { get; set; }
|
||||
string Comment { get; set; }
|
||||
Dictionary<int, IProcedureModel> RecipeProcedures { get; }
|
||||
}
|
||||
}
|
@ -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)
|
||||
{
|
||||
|
@ -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<RecipeViewModel> 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<RecipeViewModel> 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;
|
||||
|
@ -11,8 +11,8 @@ using SecuritySystemDatabaseImplement;
|
||||
namespace PolyclinicDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(PolyclinicDatabase))]
|
||||
[Migration("20240430074427_InitializeDatabase")]
|
||||
partial class InitializeDatabase
|
||||
[Migration("20240430121818_InitCreate")]
|
||||
partial class InitCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Comment")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("ProceduresCount")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Recipes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PolyclinicDatabaseImplement.Models.RecipeProcedure", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@ -176,27 +196,7 @@ namespace PolyclinicDatabaseImplement.Migrations
|
||||
|
||||
b.HasIndex("RecipeId");
|
||||
|
||||
b.ToTable("ProcedureRecipes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Recipe", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Comment")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("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 =>
|
@ -5,7 +5,7 @@
|
||||
namespace PolyclinicDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitializeDatabase : Migration
|
||||
public partial class InitCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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<int>(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");
|
@ -153,7 +153,27 @@ namespace PolyclinicDatabaseImplement.Migrations
|
||||
b.ToTable("Procedures");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PolyclinicDatabaseImplement.Models.ProcedureRecipe", b =>
|
||||
modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Recipe", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Comment")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("ProceduresCount")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Recipes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PolyclinicDatabaseImplement.Models.RecipeProcedure", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@ -173,27 +193,7 @@ namespace PolyclinicDatabaseImplement.Migrations
|
||||
|
||||
b.HasIndex("RecipeId");
|
||||
|
||||
b.ToTable("ProcedureRecipes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PolyclinicDatabaseImplement.Models.Recipe", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Comment")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("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 =>
|
||||
|
@ -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<int, IRecipeModel>? _procedureRecipes = null;
|
||||
|
||||
[ForeignKey("ProcedureId")]
|
||||
public virtual List<ProcedureRecipe> Recipes { get; set; } = new();
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, IRecipeModel> 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;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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<int, IProcedureModel>? _recipeProcedures = null;
|
||||
|
||||
[ForeignKey("RecipeId")]
|
||||
public virtual List<RecipeProcedure> Procedures { get; set; } = new();
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, IProcedureModel> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace PolyclinicDatabaseImplement.Models
|
||||
{
|
||||
public class ProcedureRecipe
|
||||
public class RecipeProcedure
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
@ -18,7 +18,7 @@ namespace SecuritySystemDatabaseImplement
|
||||
public virtual DbSet<Diagnose> Diagnoses { set; get; }
|
||||
public virtual DbSet<Medicament> Medicaments { set; get; }
|
||||
public virtual DbSet<Procedure> Procedures { set; get; }
|
||||
public virtual DbSet<ProcedureRecipe> ProcedureRecipes { set; get; }
|
||||
public virtual DbSet<RecipeProcedure> RecipeProcedures { set; get; }
|
||||
public virtual DbSet<Recipe> Recipes { set; get; }
|
||||
public virtual DbSet<Symptom> Symptomes { set; get; }
|
||||
public virtual DbSet<SymptomDiagnose> SymptomDiagnoses { set; get; }
|
||||
|
@ -32,7 +32,15 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<td>
|
||||
1
|
||||
</td>
|
||||
<td>
|
||||
Фенибут
|
||||
</td>
|
||||
<td>
|
||||
При особом неврозе употребляйте каждый день и спина не будет болеть
|
||||
</td>
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
|
@ -1,6 +1,47 @@
|
||||
@*
|
||||
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||
*@
|
||||
@using PolyclinicContracts.ViewModels
|
||||
@model List<ProcedureViewModel>
|
||||
@{
|
||||
ViewBag.SelectedSiteMenuItem = SiteMenuItems.Procedures;
|
||||
ViewData["Title"] = "Procedures";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Процедуры</h1>
|
||||
</div>
|
||||
|
||||
<div class="text-center">
|
||||
@{
|
||||
// if (Model == null)
|
||||
// {
|
||||
// <h3 class="display-4">Авторизируйтесь</h3>
|
||||
// return;
|
||||
// }
|
||||
<p>
|
||||
<a asp-action="CreateProcedure">Создать процедуру</a>
|
||||
</p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Название процедуры
|
||||
</th>
|
||||
<th>
|
||||
Комментарий
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<td>
|
||||
1
|
||||
</td>
|
||||
<td>
|
||||
Массаж пяточек
|
||||
</td>
|
||||
<td>
|
||||
ммммммм
|
||||
</td>
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
@ -1,6 +1,48 @@
|
||||
@*
|
||||
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||
*@
|
||||
@using PolyclinicContracts.ViewModels
|
||||
@model List<RecipeViewModel>
|
||||
@{
|
||||
ViewBag.SelectedSiteMenuItem = SiteMenuItems.Recipes;
|
||||
ViewData["Title"] = "Recipes";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Рецепты</h1>
|
||||
</div>
|
||||
|
||||
<div class="text-center">
|
||||
@{
|
||||
// if (Model == null)
|
||||
// {
|
||||
// <h3 class="display-4">Авторизируйтесь</h3>
|
||||
// return;
|
||||
// }
|
||||
<p>
|
||||
<a asp-action="CreateRecipe">Создать рецепт</a>
|
||||
</p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Количество процедур
|
||||
</th>
|
||||
<th>
|
||||
Комментарий
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<td>
|
||||
1
|
||||
</td>
|
||||
<td>
|
||||
4
|
||||
</td>
|
||||
<td>
|
||||
Вот столько процедур делайте
|
||||
|
||||
</td>
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user