Реализовал хранилища курса, диагноза и симптома
This commit is contained in:
parent
78632a7fb1
commit
5e0c6f97a3
@ -1,7 +1,10 @@
|
||||
using PolyclinicContracts.BindingModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PolyclinicContracts.BindingModels;
|
||||
using PolyclinicContracts.SearchModels;
|
||||
using PolyclinicContracts.StoragesContracts;
|
||||
using PolyclinicContracts.ViewModels;
|
||||
using PolyclinicDatabaseImplement.Models;
|
||||
using SecuritySystemDatabaseImplement;
|
||||
|
||||
namespace PolyclinicDatabaseImplement.Implements
|
||||
{
|
||||
@ -9,32 +12,70 @@ namespace PolyclinicDatabaseImplement.Implements
|
||||
{
|
||||
public CourseViewModel? Delete(CourseBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new PolyclinicDatabase();
|
||||
var element = context.Courses.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Courses.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public CourseViewModel? GetElement(CourseSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return GetFilteredList(model).FirstOrDefault();
|
||||
}
|
||||
|
||||
public List<CourseViewModel> GetFilteredList(CourseSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
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;
|
||||
}
|
||||
|
||||
public List<CourseViewModel> GetFullList()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new PolyclinicDatabase();
|
||||
return context.Courses
|
||||
.Include(x => x.Recipe)
|
||||
.Include(x => x.Diagnoses)
|
||||
.ThenInclude(x => x.Diagnose)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public CourseViewModel? Insert(CourseBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new PolyclinicDatabase();
|
||||
var element = Course.Create(context, model);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Courses.Add(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
public CourseViewModel? Update(CourseBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new PolyclinicDatabase();
|
||||
var element = context.Courses.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
element.Update(model);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
using PolyclinicContracts.BindingModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PolyclinicContracts.BindingModels;
|
||||
using PolyclinicContracts.SearchModels;
|
||||
using PolyclinicContracts.StoragesContracts;
|
||||
using PolyclinicContracts.ViewModels;
|
||||
using PolyclinicDatabaseImplement.Models;
|
||||
using SecuritySystemDatabaseImplement;
|
||||
|
||||
namespace PolyclinicDatabaseImplement.Implements
|
||||
{
|
||||
@ -9,32 +12,68 @@ namespace PolyclinicDatabaseImplement.Implements
|
||||
{
|
||||
public DiagnoseViewModel? Delete(DiagnoseBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
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;
|
||||
}
|
||||
|
||||
public DiagnoseViewModel? GetElement(DiagnoseSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return GetFilteredList(model).FirstOrDefault();
|
||||
}
|
||||
|
||||
public List<DiagnoseViewModel> GetFilteredList(DiagnoseSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
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;
|
||||
}
|
||||
|
||||
public List<DiagnoseViewModel> GetFullList()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new PolyclinicDatabase();
|
||||
return context.Diagnoses
|
||||
.Include(x => x.User)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public DiagnoseViewModel? Insert(DiagnoseBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var element = Diagnose.Create(model);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new PolyclinicDatabase();
|
||||
context.Diagnoses.Add(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
public DiagnoseViewModel? Update(DiagnoseBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
using PolyclinicContracts.BindingModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PolyclinicContracts.BindingModels;
|
||||
using PolyclinicContracts.SearchModels;
|
||||
using PolyclinicContracts.StoragesContracts;
|
||||
using PolyclinicContracts.ViewModels;
|
||||
using PolyclinicDatabaseImplement.Models;
|
||||
using SecuritySystemDatabaseImplement;
|
||||
|
||||
namespace PolyclinicDatabaseImplement.Implements
|
||||
{
|
||||
@ -9,32 +12,69 @@ namespace PolyclinicDatabaseImplement.Implements
|
||||
{
|
||||
public SymptomViewModel? Delete(SymptomBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
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;
|
||||
}
|
||||
|
||||
public SymptomViewModel? GetElement(SymptomSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return GetFilteredList(model).FirstOrDefault();
|
||||
}
|
||||
|
||||
public List<SymptomViewModel> GetFilteredList(SymptomSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
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;
|
||||
}
|
||||
|
||||
public List<SymptomViewModel> GetFullList()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
using var context = new PolyclinicDatabase();
|
||||
return context.Symptomes
|
||||
.Include(x => x.Diagnoses)
|
||||
.ThenInclude(x => x.Diagnose)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public SymptomViewModel? Insert(SymptomBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
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;
|
||||
}
|
||||
|
||||
public SymptomViewModel? Update(SymptomBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ namespace PolyclinicDatabaseImplement.Models
|
||||
[ForeignKey("CourseId")]
|
||||
public virtual List<CourseDiagnose> Diagnoses { get; set; } = new();
|
||||
private Dictionary<int, IDiagnoseModel>? _courseDiagnoses = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IDiagnoseModel> CourseDiagnoses
|
||||
{
|
||||
get
|
||||
|
Loading…
Reference in New Issue
Block a user