вроде как добавила реализацию хранилища для медикаментов
This commit is contained in:
parent
8e6cdea8fe
commit
4bf51abf26
@ -1,8 +1,99 @@
|
||||
using PolyclinicContracts.StoragesContracts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PolyclinicContracts.BindingModels;
|
||||
using PolyclinicContracts.SearchModels;
|
||||
using PolyclinicContracts.StoragesContracts;
|
||||
using PolyclinicContracts.ViewModels;
|
||||
using PolyclinicDatabaseImplement.Models;
|
||||
using SecuritySystemDatabaseImplement;
|
||||
|
||||
namespace PolyclinicDatabaseImplement.Implements
|
||||
{
|
||||
public class MedicamentStorage : IMedicamentStorage
|
||||
{
|
||||
public List<MedicamentViewModel> GetFullList()
|
||||
{
|
||||
using var context = new PolyclinicDatabase();
|
||||
return context.Medicaments
|
||||
.Include(x => x.Symptom)
|
||||
.Include(x => x.Procedure)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<MedicamentViewModel> GetFilteredList(MedicamentSearchModel model)
|
||||
{
|
||||
using var context = new PolyclinicDatabase();
|
||||
|
||||
if (!model.Id.HasValue || !string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
return context.Medicaments
|
||||
.Where(x => x.Id == model.Id || model.Name == x.Name)
|
||||
.Include(x => x.Symptom)
|
||||
.Include(x => x.Procedure)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public MedicamentViewModel? GetElement(MedicamentSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new PolyclinicDatabase();
|
||||
return context.Medicaments
|
||||
.Include(x => x.Symptom)
|
||||
.Include(x => x.Procedure)
|
||||
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public MedicamentViewModel? Insert(MedicamentBindingModel model)
|
||||
{
|
||||
using var context = new PolyclinicDatabase();
|
||||
|
||||
var newMedicament = Medicament.Create(model);
|
||||
if(newMedicament == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Medicaments.Add(newMedicament);
|
||||
context.SaveChanges();
|
||||
return context.Medicaments
|
||||
.Include(x => x.Symptom)
|
||||
.Include(x => x.Procedure)
|
||||
.FirstOrDefault(x => x.Id == newMedicament.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public MedicamentViewModel? Update(MedicamentBindingModel model)
|
||||
{
|
||||
using var context = new PolyclinicDatabase();
|
||||
var medicament = context.Medicaments.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (medicament == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
medicament.Update(model);
|
||||
context.SaveChanges();
|
||||
return context.Medicaments
|
||||
.Include(x => x.Symptom)
|
||||
.Include(x => x.Procedure)
|
||||
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
public MedicamentViewModel? Delete(MedicamentBindingModel model)
|
||||
{
|
||||
using var context = new PolyclinicDatabase();
|
||||
var element = context.Medicaments.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Medicaments.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,10 @@ namespace PolyclinicDatabaseImplement.Models
|
||||
[Required]
|
||||
public int SymptomId { get; set; }
|
||||
|
||||
public static Medicament Create(PolyclinicDatabase database, MedicamentBindingModel bindingModel)
|
||||
public virtual Symptom? Symptom { get; set; }
|
||||
public virtual Procedure? Procedure { get; set; }
|
||||
|
||||
public static Medicament Create(MedicamentBindingModel bindingModel)
|
||||
{
|
||||
return new Medicament()
|
||||
{
|
||||
|
@ -19,6 +19,7 @@ namespace SecuritySystemDatabaseImplement
|
||||
public virtual DbSet<CourseDiagnose> CourseDiagnoses { set; get; }
|
||||
public virtual DbSet<Recipe> Recipes { set; get; }
|
||||
public virtual DbSet<Procedure> Procedures { set; get; }
|
||||
public virtual DbSet<Medicament> Medicaments { set; get; }
|
||||
public virtual DbSet<ProcedureRecipe> ProcedureRecipes { set; get; }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user