2023-04-06 21:56:38 +04:00
|
|
|
|
using HospitalContracts.BindingModels;
|
|
|
|
|
using HospitalContracts.SearchModels;
|
|
|
|
|
using HospitalContracts.StoragesContracts;
|
|
|
|
|
using HospitalContracts.ViewModels;
|
|
|
|
|
using HospitalDataBaseImplements.Models;
|
|
|
|
|
using System;
|
2023-04-05 23:24:58 +04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace HospitalDataBaseImplements.Implements
|
|
|
|
|
{
|
2023-04-06 21:56:38 +04:00
|
|
|
|
public class SymptomsStorage : ISymptomsStorage
|
2023-04-05 23:24:58 +04:00
|
|
|
|
{
|
2023-04-06 21:56:38 +04:00
|
|
|
|
public List<SymptomsViewModel> GetFullList()
|
|
|
|
|
{
|
|
|
|
|
using var context = new HospitalDatabase();
|
|
|
|
|
return context.Symptomses
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
public List<SymptomsViewModel> GetFilteredList(SymptomsSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(model.SymptomName))
|
|
|
|
|
{
|
|
|
|
|
return new();
|
|
|
|
|
}
|
|
|
|
|
using var context = new HospitalDatabase();
|
|
|
|
|
return context.Symptomses
|
|
|
|
|
.Where(x => x.SymptomName.Contains(model.SymptomName))
|
|
|
|
|
.Select(x => x.GetViewModel)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
public SymptomsViewModel? GetElement(SymptomsSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(model.SymptomName) && !model.Id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
using var context = new HospitalDatabase();
|
|
|
|
|
return context.Symptomses
|
|
|
|
|
.FirstOrDefault(x =>
|
|
|
|
|
(!string.IsNullOrEmpty(model.SymptomName) && x.SymptomName ==
|
|
|
|
|
model.SymptomName) ||
|
|
|
|
|
(model.Id.HasValue && x.Id == model.Id))
|
|
|
|
|
?.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
public SymptomsViewModel? Insert(SymptomsBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
var newSymptoms = Symptoms.Create(model);
|
|
|
|
|
if (newSymptoms == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
using var context = new HospitalDatabase();
|
|
|
|
|
context.Symptomses.Add(newSymptoms);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return newSymptoms.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
public SymptomsViewModel? Update(SymptomsBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
using var context = new HospitalDatabase();
|
|
|
|
|
var symptom = context.Symptomses.FirstOrDefault(x => x.Id == model.Id);
|
|
|
|
|
if (symptom == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
symptom.Update(model);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return symptom.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
public SymptomsViewModel? Delete(SymptomsBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
using var context = new HospitalDatabase();
|
|
|
|
|
var element = context.Symptomses.FirstOrDefault(rec => rec.Id == model.Id);
|
|
|
|
|
if (element != null)
|
|
|
|
|
{
|
|
|
|
|
context.Symptomses.Remove(element);
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return element.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2023-04-05 23:24:58 +04:00
|
|
|
|
}
|
|
|
|
|
}
|