2024-04-29 21:47:21 +04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-05-28 13:55:03 +04:00
|
|
|
|
using Microsoft.IdentityModel.Tokens;
|
2024-04-29 21:47:21 +04:00
|
|
|
|
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();
|
2024-05-28 13:55:03 +04:00
|
|
|
|
if (model.Id != null)
|
2024-04-29 21:47:21 +04:00
|
|
|
|
{
|
2024-05-28 13:55:03 +04:00
|
|
|
|
elements = elements.Where(x => x.Id == model.Id).ToList();
|
|
|
|
|
}
|
|
|
|
|
if (!model.Name.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
elements = elements.Where(x => x.Name == model.Name).ToList();
|
2024-04-29 21:47:21 +04:00
|
|
|
|
}
|
|
|
|
|
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();
|
2024-05-28 13:55:03 +04:00
|
|
|
|
using var transaction = context.Database.BeginTransaction();
|
|
|
|
|
try
|
2024-04-29 21:47:21 +04:00
|
|
|
|
{
|
2024-05-28 13:55:03 +04:00
|
|
|
|
var element = context.Symptomes.FirstOrDefault(x => x.Id == model.Id);
|
|
|
|
|
if (element == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
element.Update(model);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
element.UpdateDiagnoses(context, model);
|
|
|
|
|
transaction.Commit();
|
|
|
|
|
return element.GetViewModel;
|
2024-04-29 21:47:21 +04:00
|
|
|
|
}
|
2024-05-28 13:55:03 +04:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
transaction.Rollback();
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-29 20:23:37 +04:00
|
|
|
|
}
|
2024-04-28 20:10:45 +04:00
|
|
|
|
}
|
|
|
|
|
}
|