Доработки для корректной работы
This commit is contained in:
parent
9c4bb0ad59
commit
bdd7ea44f6
@ -6,6 +6,10 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HospitalDataModels\HospitalDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -5,5 +5,7 @@
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int? ApothecaryId { get; set; }
|
||||
|
||||
public int[]? Ids { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using HospitalDataModels.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace HospitalContracts.ViewModels
|
||||
@ -10,5 +11,13 @@ namespace HospitalContracts.ViewModels
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public Dictionary<int, IMedicineModel> ProcedureMedicines { get; set; } = new();
|
||||
|
||||
public ProcedureViewModel() { }
|
||||
|
||||
[JsonConstructor]
|
||||
public ProcedureViewModel(Dictionary<int, MedicineViewModel> ProcedureMedicines)
|
||||
{
|
||||
this.ProcedureMedicines = ProcedureMedicines.ToDictionary(x => x.Key, x => x.Value as IMedicineModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using HospitalDataModels.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -21,5 +22,13 @@ namespace HospitalContracts.ViewModels
|
||||
public Dictionary<int, IMedicineModel> RecipeMedicines { get; set; } = new();
|
||||
|
||||
public Dictionary<int, ITreatmentModel> RecipeTreatments { get; set; } = new();
|
||||
public RecipeViewModel() { }
|
||||
|
||||
[JsonConstructor]
|
||||
public RecipeViewModel(Dictionary<int, MedicineViewModel> RecipeMedicines, Dictionary<int, TreatmentViewModel> RecipeTreatments)
|
||||
{
|
||||
this.RecipeMedicines = RecipeMedicines.ToDictionary(x => x.Key, x => x.Value as IMedicineModel);
|
||||
this.RecipeTreatments = RecipeTreatments.ToDictionary(x => x.Key, x => x.Value as ITreatmentModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,13 +25,13 @@ namespace HospitalDatabaseImplement.Implements
|
||||
|
||||
public List<MedicineViewModel> GetFilteredList(MedicineSearchModel model)
|
||||
{
|
||||
if (!model.ApothecaryId.HasValue)
|
||||
if (!model.ApothecaryId.HasValue && model.Ids == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new HospitalDatabase();
|
||||
return context.Medicines.Include(x => x.Apothecary)
|
||||
.Where(x => x.ApothecaryId == model.ApothecaryId)
|
||||
.Where(x => x.ApothecaryId == model.ApothecaryId || (model.Ids != null && model.Ids.Contains(x.Id)))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ namespace HospitalDatabaseImplement.Models
|
||||
|
||||
public void Update(PrescriptionBindingModel model)
|
||||
{
|
||||
Date = model.Date;
|
||||
Number = model.Number;
|
||||
}
|
||||
public PrescriptionViewModel GetViewModel => new()
|
||||
{
|
||||
|
@ -91,15 +91,19 @@ namespace HospitalDatabaseImplement.Models
|
||||
context.SaveChanges();
|
||||
}
|
||||
var procedure = context.Procedures.First(x => x.Id == Id);
|
||||
var existingMedicineIds = procedureMedicines?.Select(x => x.MedicineId).ToList();
|
||||
foreach (var pm in model.ProcedureMedicines)
|
||||
{
|
||||
context.ProcedureMedicines.Add(new ProcedureMedicine
|
||||
if (existingMedicineIds != null && !existingMedicineIds.Contains(pm.Key))
|
||||
{
|
||||
Procedure = procedure,
|
||||
Medicine = context.Medicines.First(x => x.Id == pm.Key),
|
||||
});
|
||||
context.SaveChanges();
|
||||
context.ProcedureMedicines.Add(new ProcedureMedicine
|
||||
{
|
||||
Procedure = procedure,
|
||||
Medicine = context.Medicines.First(x => x.Id == pm.Key),
|
||||
});
|
||||
}
|
||||
}
|
||||
context.SaveChanges();
|
||||
_procedureMedicines = null;
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ namespace HospitalDatabaseImplement.Models
|
||||
[Required]
|
||||
public int ApothecaryId { get; private set; }
|
||||
|
||||
public virtual Apothecary Apothecary { get; set; }
|
||||
public virtual Apothecary? Apothecary { get; set; }
|
||||
|
||||
private Dictionary<int, IMedicineModel>? _recipeMedicines = null;
|
||||
|
||||
@ -82,7 +82,6 @@ namespace HospitalDatabaseImplement.Models
|
||||
public void Update(RecipeBindingModel model)
|
||||
{
|
||||
Name = model.Name;
|
||||
Date = model.Date;
|
||||
}
|
||||
public RecipeViewModel GetViewModel => new()
|
||||
{
|
||||
@ -90,7 +89,9 @@ namespace HospitalDatabaseImplement.Models
|
||||
Name = Name,
|
||||
Date = Date,
|
||||
ApothecaryId = ApothecaryId,
|
||||
ApothecaryLogin = Apothecary.Login
|
||||
ApothecaryLogin = Apothecary?.Login,
|
||||
RecipeMedicines = RecipeMedicines,
|
||||
RecipeTreatments = RecipeTreatments
|
||||
};
|
||||
|
||||
public void UpdateMedicines(HospitalDatabase context, RecipeBindingModel model)
|
||||
@ -103,15 +104,20 @@ namespace HospitalDatabaseImplement.Models
|
||||
context.SaveChanges();
|
||||
}
|
||||
var recipe = context.Recipes.First(x => x.Id == Id);
|
||||
var existingMedicineIds = recipeMedicines?.Select(x => x.MedicineId).ToList();
|
||||
foreach (var rec in model.RecipeMedicines)
|
||||
{
|
||||
context.RecipeMedicines.Add(new RecipeMedicine
|
||||
{
|
||||
Recipe = recipe,
|
||||
Medicine = context.Medicines.First(x => x.Id == rec.Key),
|
||||
});
|
||||
context.SaveChanges();
|
||||
|
||||
if (existingMedicineIds != null && !existingMedicineIds.Contains(rec.Key))
|
||||
{
|
||||
context.RecipeMedicines.Add(new RecipeMedicine
|
||||
{
|
||||
Recipe = recipe,
|
||||
Medicine = context.Medicines.First(x => x.Id == rec.Key),
|
||||
});
|
||||
}
|
||||
}
|
||||
context.SaveChanges();
|
||||
_recipeMedicines = null;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user