вливаю всё, что было создано на 5, 6, 7 этапах в ветку main #12

Merged
ekallin merged 180 commits from stage7_user_web_interface_prototype into main 2024-05-01 19:15:20 +04:00
10 changed files with 297 additions and 45 deletions
Showing only changes of commit 78632a7fb1 - Show all commits

View File

@ -1,8 +1,40 @@
using PolyclinicContracts.StoragesContracts;
using PolyclinicContracts.BindingModels;
using PolyclinicContracts.SearchModels;
using PolyclinicContracts.StoragesContracts;
using PolyclinicContracts.ViewModels;
namespace PolyclinicDatabaseImplement.Implements
{
public class CourseStorage : ICourseStorage
{
public CourseViewModel? Delete(CourseBindingModel model)
{
throw new NotImplementedException();
}
public CourseViewModel? GetElement(CourseSearchModel model)
{
throw new NotImplementedException();
}
public List<CourseViewModel> GetFilteredList(CourseSearchModel model)
{
throw new NotImplementedException();
}
public List<CourseViewModel> GetFullList()
{
throw new NotImplementedException();
}
public CourseViewModel? Insert(CourseBindingModel model)
{
throw new NotImplementedException();
}
public CourseViewModel? Update(CourseBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -1,8 +1,40 @@
using PolyclinicContracts.StoragesContracts;
using PolyclinicContracts.BindingModels;
using PolyclinicContracts.SearchModels;
using PolyclinicContracts.StoragesContracts;
using PolyclinicContracts.ViewModels;
namespace PolyclinicDatabaseImplement.Implements
{
public class DiagnoseStorage : IDiagnoseStorage
{
public DiagnoseViewModel? Delete(DiagnoseBindingModel model)
{
throw new NotImplementedException();
}
public DiagnoseViewModel? GetElement(DiagnoseSearchModel model)
{
throw new NotImplementedException();
}
public List<DiagnoseViewModel> GetFilteredList(DiagnoseSearchModel model)
{
throw new NotImplementedException();
}
public List<DiagnoseViewModel> GetFullList()
{
throw new NotImplementedException();
}
public DiagnoseViewModel? Insert(DiagnoseBindingModel model)
{
throw new NotImplementedException();
}
public DiagnoseViewModel? Update(DiagnoseBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -1,8 +1,40 @@
using PolyclinicContracts.StoragesContracts;
using PolyclinicContracts.BindingModels;
using PolyclinicContracts.SearchModels;
using PolyclinicContracts.StoragesContracts;
using PolyclinicContracts.ViewModels;
namespace PolyclinicDatabaseImplement.Implements
{
public class SymptomStorage : ISymptomStorage
{
public SymptomViewModel? Delete(SymptomBindingModel model)
{
throw new NotImplementedException();
}
public SymptomViewModel? GetElement(SymptomSearchModel model)
{
throw new NotImplementedException();
}
public List<SymptomViewModel> GetFilteredList(SymptomSearchModel model)
{
throw new NotImplementedException();
}
public List<SymptomViewModel> GetFullList()
{
throw new NotImplementedException();
}
public SymptomViewModel? Insert(SymptomBindingModel model)
{
throw new NotImplementedException();
}
public SymptomViewModel? Update(SymptomBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -1,8 +1,76 @@
using PolyclinicContracts.StoragesContracts;
using Microsoft.IdentityModel.Tokens;
using PolyclinicContracts.BindingModels;
using PolyclinicContracts.SearchModels;
using PolyclinicContracts.StoragesContracts;
using PolyclinicContracts.ViewModels;
using PolyclinicDatabaseImplement.Models;
using SecuritySystemDatabaseImplement;
namespace PolyclinicDatabaseImplement.Implements
{
public class UserStorage : IUserStorage
{
public UserViewModel? Delete(UserBindingModel model)
{
using var context = new PolyclinicDatabase();
var element = context.Users.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Users.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public UserViewModel? GetElement(UserSearchModel model)
{
return GetFilteredList(model).FirstOrDefault();
}
public List<UserViewModel> GetFilteredList(UserSearchModel model)
{
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<UserViewModel> GetFullList()
{
using var context = new PolyclinicDatabase();
return context.Users.Select(x => x.GetViewModel).ToList();
}
public UserViewModel? Insert(UserBindingModel model)
{
var element = User.Create(model);
if (element == null)
{
return null;
}
using var context = new PolyclinicDatabase();
context.Users.Add(element);
context.SaveChanges();
return element.GetViewModel;
}
public UserViewModel? Update(UserBindingModel model)
{
using var context = new PolyclinicDatabase();
var element = context.Users.FirstOrDefault(x => x.Id == model.Id);
if (element == null)
{
return null;
}
element.Update(model);
context.SaveChanges();
return element.GetViewModel;
}
}
}

View File

@ -72,32 +72,25 @@ namespace PolyclinicDatabaseImplement.Models
public void UpdateDiagnoses(PolyclinicDatabase context, CourseBindingModel model)
{
//var courseDiagnoses = context.CourseDiagnoses.Where(rec => rec.CourseId == model.Id).ToList();
//if (courseDiagnoses != null && courseDiagnoses.Count > 0)
//{
// // удалили те, которых нет в модели
// context.CourseDiagnoses.RemoveRange(courseDiagnoses.Where(rec => !model.CourseDiagnoses.ContainsKey(rec.DiagnoseId)));
// context.SaveChanges();
// // обновили количество у существующих записей
// foreach (var updateDiagnose in courseDiagnoses)
// {
// updateDiagnose.Count = model.CourseDiagnoses[updateDiagnose.DiagnoseId].Item2;
// model.CourseDiagnoses.Remove(updateDiagnose.DiagnoseId);
// }
// context.SaveChanges();
//}
//var course = context.Courses.First(x => x.Id == Id);
//foreach (var pc in model.CourseDiagnoses)
//{
// context.CourseDiagnoses.Add(new CourseDiagnose
// {
// Course = course,
// Diagnose = context.Diagnoses.First(x => x.Id == pc.Key),
// Count = pc.Value.Item2
// });
// context.SaveChanges();
//}
//_courseDiagnoses = null;
var courseDiagnoses = context.CourseDiagnoses.Where(rec => rec.CourseId == model.Id).ToList();
if (courseDiagnoses != null && courseDiagnoses.Count > 0)
{
// удалили те, которых нет в модели
context.CourseDiagnoses.RemoveRange(courseDiagnoses
.Where(rec => !model.CourseDiagnoses.ContainsKey(rec.DiagnoseId)));
context.SaveChanges();
}
var course = context.Courses.First(x => x.Id == Id);
foreach (var pc in model.CourseDiagnoses)
{
context.CourseDiagnoses.Add(new CourseDiagnose
{
Course = course,
Diagnose = context.Diagnoses.First(x => x.Id == pc.Key),
});
context.SaveChanges();
}
_courseDiagnoses = null;
}
}
}

View File

@ -5,13 +5,11 @@ namespace PolyclinicDatabaseImplement.Models
public class ProcedureRecipe
{
public int Id { get; set; }
[Required]
public int ProcedureId { get; set; }
[Required]
public int RecipeId { get; set; }
public virtual Procedure Procedure { get; set; }
public virtual Recipe Recipe { get; set; }
public virtual Procedure Procedure { get; set; } = new();
public virtual Recipe Recipe { get; set; } = new();
}
}

View File

@ -1,12 +1,87 @@
using PolyclinicDataModels.Models;
using PolyclinicContracts.BindingModels;
using PolyclinicContracts.ViewModels;
using PolyclinicDataModels.Models;
using SecuritySystemDatabaseImplement;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace PolyclinicDatabaseImplement.Models
{
public class Symptom : ISymptomModel
{
public string Name => throw new NotImplementedException();
public string Comment => throw new NotImplementedException();
public Dictionary<int, IDiagnoseModel> SymptomDiagnoses => throw new NotImplementedException();
public int Id => throw new NotImplementedException();
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public string Comment { get; set; } = string.Empty;
[ForeignKey("SymptomId")]
public virtual List<SymptomDiagnose> Diagnoses { get; set; } = new();
private Dictionary<int, IDiagnoseModel>? _symptomDiagnoses = null;
[NotMapped]
public Dictionary<int, IDiagnoseModel> SymptomDiagnoses
{
get
{
if (_symptomDiagnoses == null)
{
_symptomDiagnoses = Diagnoses.ToDictionary(
symptomDiagnose => symptomDiagnose.DiagnoseId,
symptomDiagnose => symptomDiagnose.Diagnose as IDiagnoseModel
);
}
return _symptomDiagnoses;
}
}
public int Id { get; set; }
public static Symptom Create(PolyclinicDatabase context, SymptomBindingModel model)
{
return new Symptom()
{
Id = model.Id,
Name = model.Name,
Comment = model.Comment,
Diagnoses = model.SymptomDiagnoses.Select(symptomDiagnose => new SymptomDiagnose
{
Diagnose = context.Diagnoses.First(diagnose => diagnose.Id == symptomDiagnose.Key)
}).ToList()
};
}
public void Update(SymptomBindingModel model)
{
Comment = model.Comment;
Name = model.Name;
}
public SymptomViewModel GetViewModel => new()
{
Id = Id,
Comment = Comment,
Name = Name,
SymptomDiagnoses = SymptomDiagnoses
};
public void UpdateDiagnoses(PolyclinicDatabase context, SymptomBindingModel model)
{
var symptomDiagnoses = context.SymptomDiagnoses.Where(rec => rec.SymptomId == model.Id).ToList();
if (symptomDiagnoses != null && symptomDiagnoses.Count > 0)
{
// удалили те, которых нет в модели
context.SymptomDiagnoses.RemoveRange(symptomDiagnoses
.Where(rec => !model.SymptomDiagnoses.ContainsKey(rec.DiagnoseId)));
context.SaveChanges();
}
var course = context.Symptomes.First(x => x.Id == Id);
foreach (var pc in model.SymptomDiagnoses)
{
context.SymptomDiagnoses.Add(new SymptomDiagnose
{
Symptom = course,
Diagnose = context.Diagnoses.First(x => x.Id == pc.Key),
});
context.SaveChanges();
}
_symptomDiagnoses = null;
}
}
}

View File

@ -1,6 +1,15 @@
namespace PolyclinicDatabaseImplement.Models
using System.ComponentModel.DataAnnotations;
namespace PolyclinicDatabaseImplement.Models
{
public class SymptomDiagnose
{
public int Id { get; set; }
[Required]
public int SymptomId { get; set; }
[Required]
public int DiagnoseId { get; set; }
public virtual Symptom Symptom { get; set; } = new();
public virtual Diagnose Diagnose { get; set; } = new();
}
}

View File

@ -1,6 +1,15 @@
namespace PolyclinicDatabaseImplement.Models
using System.ComponentModel.DataAnnotations;
namespace PolyclinicDatabaseImplement.Models
{
public class SymptomRecipe
{
public int Id { get; set; }
[Required]
public int SymptomId { get; set; }
[Required]
public int RecipeId { get; set; }
public virtual Symptom Symptom { get; set; } = new();
public virtual Recipe Recipe { get; set; } = new();
}
}

View File

@ -13,13 +13,17 @@ namespace SecuritySystemDatabaseImplement
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<User> Users { set; get; }
public virtual DbSet<Diagnose> Diagnoses { set; get; }
public virtual DbSet<Course> Courses { set; get; }
public virtual DbSet<CourseDiagnose> CourseDiagnoses { set; get; }
public virtual DbSet<Recipe> Recipes { set; get; }
public virtual DbSet<Procedure> Procedures { set; get; }
public virtual DbSet<Diagnose> Diagnoses { set; get; }
public virtual DbSet<Medicament> Medicaments { set; get; }
public virtual DbSet<Procedure> Procedures { set; get; }
public virtual DbSet<ProcedureRecipe> ProcedureRecipes { set; get; }
public virtual DbSet<Recipe> Recipes { set; get; }
public virtual DbSet<Symptom> Symptomes { set; get; }
public virtual DbSet<SymptomDiagnose> SymptomDiagnoses { set; get; }
public virtual DbSet<SymptomRecipe> SymptomRecipes { set; get; }
public virtual DbSet<User> Users { set; get; }
}
}