2024-04-29 21:47:21 +04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using PolyclinicContracts.BindingModels;
|
2024-04-29 20:23:37 +04:00
|
|
|
|
using PolyclinicContracts.SearchModels;
|
|
|
|
|
using PolyclinicContracts.StoragesContracts;
|
|
|
|
|
using PolyclinicContracts.ViewModels;
|
2024-04-29 21:47:21 +04:00
|
|
|
|
using PolyclinicDatabaseImplement.Models;
|
|
|
|
|
using SecuritySystemDatabaseImplement;
|
2024-04-28 20:10:45 +04:00
|
|
|
|
|
|
|
|
|
namespace PolyclinicDatabaseImplement.Implements
|
|
|
|
|
{
|
|
|
|
|
public class SymptomStorage : ISymptomStorage
|
|
|
|
|
{
|
2024-04-29 20:23:37 +04:00
|
|
|
|
public SymptomViewModel? Delete(SymptomBindingModel model)
|
|
|
|
|
{
|
2024-04-29 21:47:21 +04:00
|
|
|
|
using var context = new PolyclinicDatabase();
|
|
|
|
|
var element = context.Symptomes.FirstOrDefault(rec => rec.Id == model.Id);
|
|
|
|
|
if (element != null)
|
|
|
|
|
{
|
|
|
|
|
context.Symptomes.Remove(element);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return element.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
2024-04-29 20:23:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SymptomViewModel? GetElement(SymptomSearchModel model)
|
|
|
|
|
{
|
2024-04-29 21:47:21 +04:00
|
|
|
|
return GetFilteredList(model).FirstOrDefault();
|
2024-04-29 20:23:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<SymptomViewModel> GetFilteredList(SymptomSearchModel model)
|
|
|
|
|
{
|
2024-04-29 21:47:21 +04:00
|
|
|
|
var elements = GetFullList();
|
|
|
|
|
foreach (var prop in model.GetType().GetProperties())
|
|
|
|
|
{
|
|
|
|
|
if (model.GetType().GetProperty(prop.Name)?.GetValue(model, null) != null)
|
|
|
|
|
{
|
|
|
|
|
elements = elements.Where(x => x.GetType().GetProperty(prop.Name)?.GetValue(x, null) == model.GetType().GetProperty(prop.Name)?.GetValue(model, null)).ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return elements;
|
2024-04-29 20:23:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<SymptomViewModel> GetFullList()
|
|
|
|
|
{
|
2024-04-29 21:47:21 +04:00
|
|
|
|
using var context = new PolyclinicDatabase();
|
|
|
|
|
return context.Symptomes
|
|
|
|
|
.Include(x => x.Diagnoses)
|
|
|
|
|
.ThenInclude(x => x.Diagnose)
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
2024-04-29 20:23:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SymptomViewModel? Insert(SymptomBindingModel model)
|
|
|
|
|
{
|
2024-04-29 21:47:21 +04:00
|
|
|
|
using var context = new PolyclinicDatabase();
|
|
|
|
|
var element = Symptom.Create(context, model);
|
|
|
|
|
if (element == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
context.Symptomes.Add(element);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return element.GetViewModel;
|
2024-04-29 20:23:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SymptomViewModel? Update(SymptomBindingModel model)
|
|
|
|
|
{
|
2024-04-29 21:47:21 +04:00
|
|
|
|
using var context = new PolyclinicDatabase();
|
|
|
|
|
var element = context.Symptomes.FirstOrDefault(x => x.Id == model.Id);
|
|
|
|
|
if (element == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
element.Update(model);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return element.GetViewModel;
|
2024-04-29 20:23:37 +04:00
|
|
|
|
}
|
2024-04-28 20:10:45 +04:00
|
|
|
|
}
|
|
|
|
|
}
|