работает ворд и эксель
This commit is contained in:
parent
d6d13df913
commit
c07422e040
@ -38,9 +38,9 @@ namespace HospitalBusinessLogic.BusinessLogics
|
||||
}
|
||||
var kurses = _kurseStorage.GetFullList();
|
||||
List<MedicinesViewModel> medicines = new List<MedicinesViewModel>();
|
||||
foreach (var memId in Ids)
|
||||
foreach (var mId in Ids)
|
||||
{
|
||||
var res = _medicineStorage.GetElement(new MedicinesSearchModel { Id = memId });
|
||||
var res = _medicineStorage.GetElement(new MedicinesSearchModel { Id = mId });
|
||||
if (res != null)
|
||||
{
|
||||
medicines.Add(res);
|
||||
@ -56,7 +56,7 @@ namespace HospitalBusinessLogic.BusinessLogics
|
||||
};
|
||||
foreach (var kurse in kurses)
|
||||
{
|
||||
if (kurse.KurseMedicine.ContainsKey(medicine.Id))
|
||||
if (kurse.KurseMedicines.ContainsKey(medicine.Id))
|
||||
{
|
||||
record.Kurses.Add(new Tuple<int, string>(kurse.Id, kurse.Duration));
|
||||
}
|
||||
@ -111,7 +111,7 @@ namespace HospitalBusinessLogic.BusinessLogics
|
||||
// return listAll;
|
||||
//}
|
||||
|
||||
public List<ReportRecipeMedicineViewModel> GetRecipeMedicine(ReportBindingModel model)
|
||||
public List<ReportMedicinesViewModel> GetRecipeMedicine(ReportBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@ -131,7 +131,7 @@ namespace HospitalBusinessLogic.BusinessLogics
|
||||
_saveToWord.CreateDoc(new WordInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список конференций",
|
||||
Title = "Список курсов",
|
||||
KurseMedicines = GetKurseMedicines(model.Ids)
|
||||
});
|
||||
}
|
||||
|
@ -49,17 +49,15 @@ namespace HospitalBusinessLogic.OfficePackage
|
||||
Text = kurse.Item1.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
rowIndex++;
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "B",
|
||||
ColumnName = "C",
|
||||
RowIndex = rowIndex,
|
||||
Text = kurse.Item2,
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBroder
|
||||
});
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
rowIndex++;
|
||||
}
|
||||
SaveExcel(info);
|
||||
|
@ -48,8 +48,9 @@ namespace HospitalBusinessLogic.OfficePackage
|
||||
}
|
||||
});
|
||||
}
|
||||
SaveWord(info);
|
||||
|
||||
}
|
||||
SaveWord(info);
|
||||
}
|
||||
/// <summary>
|
||||
/// Создание doc-файла
|
||||
|
@ -13,6 +13,6 @@ namespace HospitalBusinessLogic.OfficePackage.HelperModels
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public DateTime DateFrom { get; set; }
|
||||
public DateTime DateTo { get; set; }
|
||||
public List<ReportRecipeMedicineViewModel> RecipeMedicine { get; set; } = new();
|
||||
public List<ReportMedicinesViewModel> RecipeMedicine { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
using HospitalBusinessLogic.BusinessLogics;
|
||||
using HospitalBusinessLogic.OfficePackage;
|
||||
using HospitalBusinessLogic.OfficePackage.Implements;
|
||||
using HospitalContracts.BusinessLogicsContracts;
|
||||
using HospitalContracts.StoragesContracts;
|
||||
using HospitalDataBaseImplements;
|
||||
@ -27,6 +29,11 @@ builder.Services.AddTransient<IMedicinesLogic, MedicinesLogic>();
|
||||
builder.Services.AddTransient<IProceduresLogic, ProceduresLogic>();
|
||||
builder.Services.AddTransient<IKurseLogic, KurseLogic>();
|
||||
builder.Services.AddTransient<IRecipesLogic, RecipesLogic>();
|
||||
builder.Services.AddTransient<IReportLogic, ReportLogic>();
|
||||
|
||||
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
@ -44,6 +51,7 @@ builder.Services.AddSwaggerGen(c =>
|
||||
|
||||
var app = builder.Build();
|
||||
LoaderFromXML.LoadSymptoms();
|
||||
LoaderFromXML.LoadKurses();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
|
@ -12,7 +12,7 @@ namespace HospitalContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public string Duration { get; set; } = string.Empty;
|
||||
public int CountInDay { get; set; }
|
||||
public Dictionary<int, IMedicinesModel> KurseMedicine
|
||||
public Dictionary<int, IMedicinesModel> KurseMedicines
|
||||
{
|
||||
get;
|
||||
set;
|
||||
|
@ -20,7 +20,7 @@ namespace HospitalContracts.BusinessLogicsContracts
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
List<ReportRecipeMedicineViewModel> GetRecipeMedicine(ReportBindingModel model);
|
||||
List<ReportMedicinesViewModel> GetRecipeMedicine(ReportBindingModel model);
|
||||
/// <summary>
|
||||
/// Сохранение компонент в файл-Word
|
||||
/// </summary>
|
||||
|
@ -16,7 +16,7 @@ namespace HospitalContracts.ViewModels
|
||||
public string Duration { get; set; } = string.Empty;
|
||||
[DisplayName("Срок приема")]
|
||||
public int CountInDay { get; set; }
|
||||
public Dictionary<int, IMedicinesModel> KurseMedicine
|
||||
public Dictionary<int, IMedicinesModel> KurseMedicines
|
||||
{
|
||||
get;
|
||||
set;
|
||||
@ -24,9 +24,9 @@ namespace HospitalContracts.ViewModels
|
||||
|
||||
public KurseViewModel() { }
|
||||
[JsonConstructor]
|
||||
public KurseViewModel(Dictionary<int, MedicinesViewModel> KurseMedicine)
|
||||
public KurseViewModel(Dictionary<int, MedicinesViewModel> KurseMedicines)
|
||||
{
|
||||
this.KurseMedicine = KurseMedicine.ToDictionary(x => x.Key, x => x.Value as IMedicinesModel);
|
||||
this.KurseMedicines = KurseMedicines.ToDictionary(x => x.Key, x => x.Value as IMedicinesModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace HospitalContracts.ViewModels
|
||||
{
|
||||
public class ReportRecipeMedicineViewModel
|
||||
public class ReportMedicinesViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTime DateCreate { get; set; }
|
@ -60,12 +60,13 @@ namespace HospitalDataBaseImplements.Implements
|
||||
|
||||
public KurseViewModel? Insert(KurseBindingModel model)
|
||||
{
|
||||
var newKurse = Kurses.Create(model);
|
||||
using var context = new HospitalDatabase();
|
||||
var newKurse = Kurses.Create(context, model);
|
||||
if (newKurse == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new HospitalDatabase();
|
||||
|
||||
context.Kurse.Add(newKurse);
|
||||
context.SaveChanges();
|
||||
return context.Kurse
|
||||
@ -77,6 +78,9 @@ namespace HospitalDataBaseImplements.Implements
|
||||
public KurseViewModel? Update(KurseBindingModel model)
|
||||
{
|
||||
using var context = new HospitalDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var kurse = context.Kurse.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (kurse == null)
|
||||
{
|
||||
@ -84,7 +88,18 @@ namespace HospitalDataBaseImplements.Implements
|
||||
}
|
||||
kurse.Update(model);
|
||||
context.SaveChanges();
|
||||
if (model.KurseMedicines != null)
|
||||
{
|
||||
kurse.UpdateMedicines(context, model);
|
||||
}
|
||||
transaction.Commit();
|
||||
return kurse.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace HospitalDataBaseImplements
|
||||
{
|
||||
// private static readonly string IllnessFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XMLData\\Illness.xml");
|
||||
private static readonly string SymptomsFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XMLData\\Symptoms.xml");
|
||||
// private static readonly string KursesFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XMLData\\Kurses.xml");
|
||||
private static readonly string KursesFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XMLData\\Kurses.xml");
|
||||
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||
{
|
||||
@ -40,23 +40,23 @@ namespace HospitalDataBaseImplements
|
||||
|
||||
//}
|
||||
/// <summary>
|
||||
/// Чтение лечений из XML-файла
|
||||
/// Чтение курсов из XML-файла
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
//public static void LoadKurses() // (запуск после загрузки симптомов)
|
||||
//{
|
||||
// using var context = new HospitalDatabase();
|
||||
// if (context.Kurse.ToList().Count > 0)
|
||||
// return;
|
||||
// //var list = LoadData(KursesFileName, "Kurses", x => Kurses.Create(context, x)!)!;
|
||||
// //list.ForEach(x =>
|
||||
// //{
|
||||
// // context.Kurse.Add(x);
|
||||
// //});
|
||||
// //context.SaveChanges();
|
||||
//}
|
||||
public static void LoadKurses() // (запуск после загрузки симптомов)
|
||||
{
|
||||
using var context = new HospitalDatabase();
|
||||
if (context.Kurse.ToList().Count > 0)
|
||||
return;
|
||||
var list = LoadData(KursesFileName, "Kurses", x => Kurses.Create(context, x)!)!;
|
||||
list.ForEach(x =>
|
||||
{
|
||||
context.Kurse.Add(x);
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
/// <summary>
|
||||
/// Чтение поцедур из XML-файла
|
||||
/// Чтение симптомов из XML-файла
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static void LoadSymptoms()// (запуск после старта программы)
|
||||
|
@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace HospitalDataBaseImplements.Migrations
|
||||
{
|
||||
[DbContext(typeof(HospitalDatabase))]
|
||||
[Migration("20230525103233_InitialCreate")]
|
||||
[Migration("20230620143135_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -117,6 +117,29 @@ namespace HospitalDataBaseImplements.Migrations
|
||||
b.ToTable("IllnessSymptomses");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HospitalDataBaseImplements.Models.KurseMedicines", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("KurseId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("MedicineId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("KurseId");
|
||||
|
||||
b.HasIndex("MedicineId");
|
||||
|
||||
b.ToTable("KurseMedicines");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HospitalDataBaseImplements.Models.Kurses", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@ -132,17 +155,8 @@ namespace HospitalDataBaseImplements.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("MedicinesId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("MedicinesName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("MedicinesId");
|
||||
|
||||
b.ToTable("Kurse");
|
||||
});
|
||||
|
||||
@ -336,15 +350,23 @@ namespace HospitalDataBaseImplements.Migrations
|
||||
b.Navigation("Symptoms");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HospitalDataBaseImplements.Models.Kurses", b =>
|
||||
modelBuilder.Entity("HospitalDataBaseImplements.Models.KurseMedicines", b =>
|
||||
{
|
||||
b.HasOne("HospitalDataBaseImplements.Models.Medicines", "Medicines")
|
||||
.WithMany()
|
||||
.HasForeignKey("MedicinesId")
|
||||
b.HasOne("HospitalDataBaseImplements.Models.Kurses", "Kurse")
|
||||
.WithMany("Medicines")
|
||||
.HasForeignKey("KurseId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Medicines");
|
||||
b.HasOne("HospitalDataBaseImplements.Models.Medicines", "Medicine")
|
||||
.WithMany("KurseMedicines")
|
||||
.HasForeignKey("MedicineId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Kurse");
|
||||
|
||||
b.Navigation("Medicine");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HospitalDataBaseImplements.Models.Medicines", b =>
|
||||
@ -436,10 +458,14 @@ namespace HospitalDataBaseImplements.Migrations
|
||||
modelBuilder.Entity("HospitalDataBaseImplements.Models.Kurses", b =>
|
||||
{
|
||||
b.Navigation("IllnessKurses");
|
||||
|
||||
b.Navigation("Medicines");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HospitalDataBaseImplements.Models.Medicines", b =>
|
||||
{
|
||||
b.Navigation("KurseMedicines");
|
||||
|
||||
b.Navigation("Procedures");
|
||||
});
|
||||
|
@ -40,6 +40,20 @@ namespace HospitalDataBaseImplements.Migrations
|
||||
table.PrimaryKey("PK_Illnesses", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Kurse",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Duration = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
CountInDay = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Kurse", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Symptomses",
|
||||
columns: table => new
|
||||
@ -96,6 +110,32 @@ namespace HospitalDataBaseImplements.Migrations
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "IllnessKurse",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
IllnessId = table.Column<int>(type: "int", nullable: false),
|
||||
KurseId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_IllnessKurse", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_IllnessKurse_Illnesses_IllnessId",
|
||||
column: x => x.IllnessId,
|
||||
principalTable: "Illnesses",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_IllnessKurse_Kurse_KurseId",
|
||||
column: x => x.KurseId,
|
||||
principalTable: "Kurse",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "IllnessSymptomses",
|
||||
columns: table => new
|
||||
@ -152,22 +192,26 @@ namespace HospitalDataBaseImplements.Migrations
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Kurse",
|
||||
name: "KurseMedicines",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
MedicinesId = table.Column<int>(type: "int", nullable: false),
|
||||
MedicinesName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Duration = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
CountInDay = table.Column<int>(type: "int", nullable: false)
|
||||
MedicineId = table.Column<int>(type: "int", nullable: false),
|
||||
KurseId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Kurse", x => x.Id);
|
||||
table.PrimaryKey("PK_KurseMedicines", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Kurse_Medicines_MedicinesId",
|
||||
column: x => x.MedicinesId,
|
||||
name: "FK_KurseMedicines_Kurse_KurseId",
|
||||
column: x => x.KurseId,
|
||||
principalTable: "Kurse",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_KurseMedicines_Medicines_MedicineId",
|
||||
column: x => x.MedicineId,
|
||||
principalTable: "Medicines",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
@ -225,32 +269,6 @@ namespace HospitalDataBaseImplements.Migrations
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "IllnessKurse",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
IllnessId = table.Column<int>(type: "int", nullable: false),
|
||||
KurseId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_IllnessKurse", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_IllnessKurse_Illnesses_IllnessId",
|
||||
column: x => x.IllnessId,
|
||||
principalTable: "Illnesses",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_IllnessKurse_Kurse_KurseId",
|
||||
column: x => x.KurseId,
|
||||
principalTable: "Kurse",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_IllnessKurse_IllnessId",
|
||||
table: "IllnessKurse",
|
||||
@ -272,9 +290,14 @@ namespace HospitalDataBaseImplements.Migrations
|
||||
column: "SymptomsId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Kurse_MedicinesId",
|
||||
table: "Kurse",
|
||||
column: "MedicinesId");
|
||||
name: "IX_KurseMedicines_KurseId",
|
||||
table: "KurseMedicines",
|
||||
column: "KurseId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_KurseMedicines_MedicineId",
|
||||
table: "KurseMedicines",
|
||||
column: "MedicineId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Medicines_ClientId",
|
||||
@ -326,17 +349,23 @@ namespace HospitalDataBaseImplements.Migrations
|
||||
migrationBuilder.DropTable(
|
||||
name: "IllnessSymptomses");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "KurseMedicines");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ProcedureMedicine");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "RecipesProcedures");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Illnesses");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Kurse");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Illnesses");
|
||||
name: "Medicines");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Procedures");
|
||||
@ -345,13 +374,10 @@ namespace HospitalDataBaseImplements.Migrations
|
||||
name: "Recipes");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Medicines");
|
||||
name: "Clients");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Symptomses");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Clients");
|
||||
}
|
||||
}
|
||||
}
|
@ -114,6 +114,29 @@ namespace HospitalDataBaseImplements.Migrations
|
||||
b.ToTable("IllnessSymptomses");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HospitalDataBaseImplements.Models.KurseMedicines", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("KurseId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("MedicineId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("KurseId");
|
||||
|
||||
b.HasIndex("MedicineId");
|
||||
|
||||
b.ToTable("KurseMedicines");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HospitalDataBaseImplements.Models.Kurses", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@ -129,17 +152,8 @@ namespace HospitalDataBaseImplements.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("MedicinesId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("MedicinesName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("MedicinesId");
|
||||
|
||||
b.ToTable("Kurse");
|
||||
});
|
||||
|
||||
@ -333,15 +347,23 @@ namespace HospitalDataBaseImplements.Migrations
|
||||
b.Navigation("Symptoms");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HospitalDataBaseImplements.Models.Kurses", b =>
|
||||
modelBuilder.Entity("HospitalDataBaseImplements.Models.KurseMedicines", b =>
|
||||
{
|
||||
b.HasOne("HospitalDataBaseImplements.Models.Medicines", "Medicines")
|
||||
.WithMany()
|
||||
.HasForeignKey("MedicinesId")
|
||||
b.HasOne("HospitalDataBaseImplements.Models.Kurses", "Kurse")
|
||||
.WithMany("Medicines")
|
||||
.HasForeignKey("KurseId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Medicines");
|
||||
b.HasOne("HospitalDataBaseImplements.Models.Medicines", "Medicine")
|
||||
.WithMany("KurseMedicines")
|
||||
.HasForeignKey("MedicineId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Kurse");
|
||||
|
||||
b.Navigation("Medicine");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HospitalDataBaseImplements.Models.Medicines", b =>
|
||||
@ -433,10 +455,14 @@ namespace HospitalDataBaseImplements.Migrations
|
||||
modelBuilder.Entity("HospitalDataBaseImplements.Models.Kurses", b =>
|
||||
{
|
||||
b.Navigation("IllnessKurses");
|
||||
|
||||
b.Navigation("Medicines");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HospitalDataBaseImplements.Models.Medicines", b =>
|
||||
{
|
||||
b.Navigation("KurseMedicines");
|
||||
|
||||
b.Navigation("Procedures");
|
||||
});
|
||||
|
||||
|
@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
||||
using HospitalDataModels.Models;
|
||||
using HospitalContracts.BindingModels;
|
||||
using HospitalContracts.ViewModels;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace HospitalDataBaseImplements.Models
|
||||
{
|
||||
@ -25,41 +26,49 @@ namespace HospitalDataBaseImplements.Models
|
||||
private Dictionary<int, IMedicinesModel>? _kurseMedicine = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, IMedicinesModel> KurseMedicine
|
||||
public Dictionary<int, IMedicinesModel> KurseMedicines
|
||||
{
|
||||
get
|
||||
{
|
||||
using var context = new HospitalDatabase();
|
||||
if (_kurseMedicine == null)
|
||||
{
|
||||
_kurseMedicine = Medicines
|
||||
.ToDictionary(rec => rec.MedicineId, rec =>
|
||||
rec.Medicine as IMedicinesModel);
|
||||
.ToDictionary(x => x.MedicineId, x =>
|
||||
(context.Medicines.FirstOrDefault(y => y.Id == x.MedicineId)! as IMedicinesModel));
|
||||
}
|
||||
return _kurseMedicine;
|
||||
}
|
||||
}
|
||||
[ForeignKey("KurseId")]
|
||||
public virtual List<KurseMedicines> Medicines { get; set; } = new();
|
||||
public static Kurses? Create(KurseBindingModel model)
|
||||
public static Kurses? Create(HospitalDatabase context, XElement element)
|
||||
{
|
||||
if (model == null)
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Kurses()
|
||||
{
|
||||
Id = model.Id,
|
||||
Duration = model.Duration,
|
||||
CountInDay = model.CountInDay
|
||||
Duration = element.Element("Duration")!.Value,
|
||||
CountInDay = Convert.ToInt32(element.Element("CountInDay")!.Value),
|
||||
Medicines = element.Element("Medicines")!.Elements("MedicineId").Select(x => new KurseMedicines
|
||||
{
|
||||
Medicine = context.Medicines.First(y => y.Id == Convert.ToInt32(x.Value))
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public static Kurses Create(KurseViewModel model)
|
||||
public static Kurses Create(HospitalDatabase context, KurseBindingModel model)
|
||||
{
|
||||
return new Kurses
|
||||
{
|
||||
Id = model.Id,
|
||||
Duration = model.Duration,
|
||||
CountInDay = model.CountInDay
|
||||
CountInDay = model.CountInDay,
|
||||
Medicines = model.KurseMedicines.Select(x => new KurseMedicines
|
||||
{
|
||||
Medicine = context.Medicines.First(y => y.Id == x.Key)
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public void Update(KurseBindingModel model)
|
||||
@ -75,7 +84,30 @@ namespace HospitalDataBaseImplements.Models
|
||||
{
|
||||
Id = Id,
|
||||
Duration = Duration,
|
||||
CountInDay = CountInDay
|
||||
CountInDay = CountInDay,
|
||||
KurseMedicines = KurseMedicines
|
||||
};
|
||||
}
|
||||
public void UpdateMedicines(HospitalDatabase context, KurseBindingModel model)
|
||||
{
|
||||
var kurseMedicine = context.KurseMedicines.Where(rec => rec.KurseId == model.Id).ToList();
|
||||
if (kurseMedicine != null && kurseMedicine.Count > 0)
|
||||
{
|
||||
context.KurseMedicines.RemoveRange(kurseMedicine.Where(rec
|
||||
=> !model.KurseMedicines.ContainsKey(rec.MedicineId)));
|
||||
context.SaveChanges();
|
||||
}
|
||||
var kurse = context.Kurse.First(x => x.Id == Id);
|
||||
var existingMedicineIds = kurseMedicine?.Select(x => x.MedicineId).ToList();
|
||||
foreach (var rec in model.KurseMedicines)
|
||||
{
|
||||
context.KurseMedicines.Add(new KurseMedicines
|
||||
{
|
||||
Kurse = kurse,
|
||||
Medicine = context.Medicines.First(x => x.Id == rec.Key),
|
||||
});
|
||||
}
|
||||
context.SaveChanges();
|
||||
_kurseMedicine = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,9 @@ namespace HospitalDataBaseImplements.Models
|
||||
public virtual Client Client { get; set; }
|
||||
[ForeignKey("MedicineId")]
|
||||
public virtual List<ProcedureMedicine> Procedures { get; set; } = new();
|
||||
|
||||
[ForeignKey("MedicineId")]
|
||||
public virtual List<KurseMedicines> KurseMedicines { get; set; } = new();
|
||||
public static Medicines? Create(MedicinesBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
|
@ -10,6 +10,6 @@ namespace HospitalDataModels.Models
|
||||
{
|
||||
string Duration { get; }
|
||||
int CountInDay { get; }
|
||||
Dictionary<int, IMedicinesModel> KurseMedicine { get; }
|
||||
Dictionary<int, IMedicinesModel> KurseMedicines { get; }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user