Создал все классы моделей бд, нужно их реализовать
This commit is contained in:
parent
289fd1c593
commit
ac9f4b87ce
101
Polyclinic/PolyclinicDatabaseImplement/Models/Course.cs
Normal file
101
Polyclinic/PolyclinicDatabaseImplement/Models/Course.cs
Normal file
@ -0,0 +1,101 @@
|
||||
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 Course : ICourseModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int DaysCount { get; set; }
|
||||
[Required]
|
||||
public int PillsPerDay { get; set; }
|
||||
public string Comment { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public int RecipeId { get; set; }
|
||||
public virtual Recipe Recipe { get; set; } = new();
|
||||
[ForeignKey("CourseId")]
|
||||
public virtual List<CourseDiagnose> Diagnoses { get; set; } = new();
|
||||
private Dictionary<int, IDiagnoseModel>? _courseDiagnoses = null;
|
||||
public Dictionary<int, IDiagnoseModel> CourseDiagnoses
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_courseDiagnoses == null)
|
||||
{
|
||||
_courseDiagnoses = Diagnoses.ToDictionary(
|
||||
courseDiagnose => courseDiagnose.DiagnoseId,
|
||||
courseDiagnose => courseDiagnose.Diagnose as IDiagnoseModel
|
||||
);
|
||||
}
|
||||
return _courseDiagnoses;
|
||||
}
|
||||
}
|
||||
|
||||
public static Course Create(SecuritySystemDatabase context, CourseBindingModel model)
|
||||
{
|
||||
return new Course()
|
||||
{
|
||||
Id = model.Id,
|
||||
DaysCount = model.DaysCount,
|
||||
PillsPerDay = model.PillsPerDay,
|
||||
Comment = model.Comment,
|
||||
RecipeId = model.RecipeId,
|
||||
Diagnoses = model.CourseDiagnoses.Select(courseDiagnose => new CourseDiagnose
|
||||
{
|
||||
Diagnose = context.Diagnoses.First(diagnose => diagnose.Id == courseDiagnose.Key)
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(CourseBindingModel model)
|
||||
{
|
||||
DaysCount = model.DaysCount;
|
||||
PillsPerDay = model.PillsPerDay;
|
||||
Comment = model.Comment;
|
||||
RecipeId = model.RecipeId;
|
||||
}
|
||||
|
||||
public CourseViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
CourseName = CourseName,
|
||||
Price = Price,
|
||||
CourseDiagnoses = CourseDiagnoses
|
||||
};
|
||||
|
||||
public void UpdateDiagnoses(SecuritySystemDatabase 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace PolyclinicDatabaseImplement.Models
|
||||
{
|
||||
public class CourseDiagnose
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int CourseId { get; set; }
|
||||
[Required]
|
||||
public int DiagnoseId { get; set; }
|
||||
public virtual Course Course { get; set; } = new();
|
||||
public virtual Diagnose Diagnose { get; set; } = new();
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ namespace PolyclinicDatabaseImplement.Models
|
||||
[Required]
|
||||
public int UserId { get; set; }
|
||||
public int Id { get; set; }
|
||||
public virtual User? User { get; set; }
|
||||
public virtual User User { get; set; } = new();
|
||||
|
||||
public static Diagnose? Create(DiagnoseBindingModel? model)
|
||||
{
|
||||
|
13
Polyclinic/PolyclinicDatabaseImplement/Models/Medicament.cs
Normal file
13
Polyclinic/PolyclinicDatabaseImplement/Models/Medicament.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using PolyclinicDataModels.Models;
|
||||
|
||||
namespace PolyclinicDatabaseImplement.Models
|
||||
{
|
||||
public class Medicament : IMedicamentModel
|
||||
{
|
||||
public string Name => throw new NotImplementedException();
|
||||
public string Comment => throw new NotImplementedException();
|
||||
public int ProcedureId => throw new NotImplementedException();
|
||||
public int SymptomId => throw new NotImplementedException();
|
||||
public int Id => throw new NotImplementedException();
|
||||
}
|
||||
}
|
12
Polyclinic/PolyclinicDatabaseImplement/Models/Procedure.cs
Normal file
12
Polyclinic/PolyclinicDatabaseImplement/Models/Procedure.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using PolyclinicDataModels.Models;
|
||||
|
||||
namespace PolyclinicDatabaseImplement.Models
|
||||
{
|
||||
public class Procedure : IProcedureModel
|
||||
{
|
||||
public string Name => throw new NotImplementedException();
|
||||
public string Comment => throw new NotImplementedException();
|
||||
public Dictionary<int, ICourseModel> ProcedureCourses => throw new NotImplementedException();
|
||||
public int Id => throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace PolyclinicDatabaseImplement.Models
|
||||
{
|
||||
public class ProcedureRecipe
|
||||
{
|
||||
}
|
||||
}
|
12
Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs
Normal file
12
Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using PolyclinicDataModels.Models;
|
||||
|
||||
namespace PolyclinicDatabaseImplement.Models
|
||||
{
|
||||
public class Recipe : IRecipeModel
|
||||
{
|
||||
public int ProceduresCount { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public string Comment { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public Dictionary<int, IRecipeModel> ProcedureRecipes => throw new NotImplementedException();
|
||||
public int Id => throw new NotImplementedException();
|
||||
}
|
||||
}
|
12
Polyclinic/PolyclinicDatabaseImplement/Models/Symptom.cs
Normal file
12
Polyclinic/PolyclinicDatabaseImplement/Models/Symptom.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using PolyclinicDataModels.Models;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace PolyclinicDatabaseImplement.Models
|
||||
{
|
||||
public class SymptomDiagnose
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace PolyclinicDatabaseImplement.Models
|
||||
{
|
||||
public class SymptomRecipe
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user