2024-04-29 21:47:21 +04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-05-01 11:20:58 +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 DiagnoseStorage : IDiagnoseStorage
|
|
|
|
|
{
|
2024-04-29 20:23:37 +04:00
|
|
|
|
public DiagnoseViewModel? Delete(DiagnoseBindingModel model)
|
|
|
|
|
{
|
2024-04-29 21:47:21 +04:00
|
|
|
|
using var context = new PolyclinicDatabase();
|
|
|
|
|
var element = context.Diagnoses.FirstOrDefault(rec => rec.Id == model.Id);
|
|
|
|
|
if (element != null)
|
|
|
|
|
{
|
|
|
|
|
context.Diagnoses.Remove(element);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return element.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
2024-04-29 20:23:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DiagnoseViewModel? GetElement(DiagnoseSearchModel model)
|
|
|
|
|
{
|
2024-04-29 21:47:21 +04:00
|
|
|
|
return GetFilteredList(model).FirstOrDefault();
|
2024-04-29 20:23:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<DiagnoseViewModel> GetFilteredList(DiagnoseSearchModel model)
|
|
|
|
|
{
|
2024-04-29 21:47:21 +04:00
|
|
|
|
var elements = GetFullList();
|
2024-05-01 11:20:58 +04:00
|
|
|
|
if (model.Id != null)
|
2024-04-29 21:47:21 +04:00
|
|
|
|
{
|
2024-05-01 11:20:58 +04:00
|
|
|
|
elements = elements.Where(x => x.Id == model.Id.Value).ToList();
|
|
|
|
|
}
|
|
|
|
|
if (!model.Name.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
elements = elements.Where(x => x.Name == model.Name).ToList();
|
|
|
|
|
}
|
|
|
|
|
if (model.UserId != null)
|
|
|
|
|
{
|
|
|
|
|
elements = elements.Where(x => x.UserId == model.UserId.Value).ToList();
|
|
|
|
|
}
|
|
|
|
|
if (model.From != null)
|
|
|
|
|
{
|
|
|
|
|
elements = elements.Where(x => x.DateStartDiagnose >= model.From.Value).ToList();
|
|
|
|
|
}
|
|
|
|
|
if (model.To != null)
|
|
|
|
|
{
|
2024-05-01 11:40:13 +04:00
|
|
|
|
elements = elements
|
|
|
|
|
.Where(x => x.DateStartDiagnose <= model.To.Value)
|
|
|
|
|
.Where(x => x.DateStopDiagnose != null)
|
|
|
|
|
.Where(x => x.DateStopDiagnose <= model.To.Value)
|
|
|
|
|
.ToList();
|
2024-04-29 21:47:21 +04:00
|
|
|
|
}
|
|
|
|
|
return elements;
|
2024-04-29 20:23:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<DiagnoseViewModel> GetFullList()
|
|
|
|
|
{
|
2024-04-29 21:47:21 +04:00
|
|
|
|
using var context = new PolyclinicDatabase();
|
|
|
|
|
return context.Diagnoses
|
|
|
|
|
.Include(x => x.User)
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
2024-04-29 20:23:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DiagnoseViewModel? Insert(DiagnoseBindingModel model)
|
|
|
|
|
{
|
2024-04-29 21:47:21 +04:00
|
|
|
|
var element = Diagnose.Create(model);
|
|
|
|
|
if (element == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
using var context = new PolyclinicDatabase();
|
|
|
|
|
context.Diagnoses.Add(element);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return element.GetViewModel;
|
2024-04-29 20:23:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DiagnoseViewModel? Update(DiagnoseBindingModel model)
|
|
|
|
|
{
|
2024-04-29 21:47:21 +04:00
|
|
|
|
using var context = new PolyclinicDatabase();
|
|
|
|
|
var element = context.Diagnoses.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
|
|
|
|
}
|
|
|
|
|
}
|