добавила юзера в процедуру, реализовала модель процедура и процедураРецепт для хранилища данных
This commit is contained in:
parent
03bb104df1
commit
a7c7600073
@ -5,9 +5,10 @@ namespace PolyclinicContracts.BindingModels
|
|||||||
public class ProcedureBindingModel : IProcedureModel
|
public class ProcedureBindingModel : IProcedureModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
public int UserId { get; set; }
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
public string Comment { get; set; } = string.Empty;
|
public string Comment { get; set; } = string.Empty;
|
||||||
public Dictionary<int, ICourseModel> ProcedureCourses { get; set; } = new();
|
public Dictionary<int, IRecipeModel> ProcedureRecipes { get; set; } = new();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,11 +6,11 @@ namespace PolyclinicContracts.ViewModels
|
|||||||
public class ProcedureViewModel : IProcedureModel
|
public class ProcedureViewModel : IProcedureModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
public int UserId { get; set; }
|
||||||
[DisplayName("Название процедуры")]
|
[DisplayName("Название процедуры")]
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
[DisplayName("Комментарий")]
|
[DisplayName("Комментарий")]
|
||||||
public string Comment { get; set; } = string.Empty;
|
public string Comment { get; set; } = string.Empty;
|
||||||
public Dictionary<int, ICourseModel> ProcedureCourses { get; set; } = new();
|
public Dictionary<int, IRecipeModel> ProcedureRecipes { get; set; } = new();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,6 +4,7 @@
|
|||||||
{
|
{
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
string Comment { get; }
|
string Comment { get; }
|
||||||
Dictionary<int, ICourseModel> ProcedureCourses { get; }
|
int UserId { get; }
|
||||||
|
Dictionary<int, IRecipeModel> ProcedureRecipes { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,12 +1,92 @@
|
|||||||
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
|
namespace PolyclinicDatabaseImplement.Models
|
||||||
{
|
{
|
||||||
public class Procedure : IProcedureModel
|
public class Procedure : IProcedureModel
|
||||||
{
|
{
|
||||||
public string Name => throw new NotImplementedException();
|
public int Id { get; set; }
|
||||||
public string Comment => throw new NotImplementedException();
|
|
||||||
public Dictionary<int, ICourseModel> ProcedureCourses => throw new NotImplementedException();
|
[Required]
|
||||||
public int Id => throw new NotImplementedException();
|
public int UserId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string Comment { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
private Dictionary<int, IRecipeModel>? _procedureRecipes = null;
|
||||||
|
|
||||||
|
[ForeignKey("ProcedureId")]
|
||||||
|
public virtual List<ProcedureRecipe> Recipes { get; set; } = new();
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, IRecipeModel> ProcedureRecipes
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if(_procedureRecipes == null)
|
||||||
|
{
|
||||||
|
_procedureRecipes = Recipes.ToDictionary(recPC => recPC.RecipeId, recPC => (recPC.Recipe as IRecipeModel));
|
||||||
|
}
|
||||||
|
return _procedureRecipes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Procedure Create(PolyclinicDatabase database, ProcedureBindingModel bindingModel)
|
||||||
|
{
|
||||||
|
return new Procedure()
|
||||||
|
{
|
||||||
|
Id = bindingModel.Id,
|
||||||
|
UserId = bindingModel.UserId,
|
||||||
|
Name = bindingModel.Name,
|
||||||
|
Comment = bindingModel.Comment,
|
||||||
|
Recipes = bindingModel.ProcedureRecipes.Select(x => new ProcedureRecipe
|
||||||
|
{
|
||||||
|
Recipe = database.Recipes.First(y => y.Id == x.Key)
|
||||||
|
}).ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ProcedureBindingModel bindingModel)
|
||||||
|
{
|
||||||
|
Name = bindingModel.Name;
|
||||||
|
Comment = bindingModel.Comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProcedureViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
Name = Name,
|
||||||
|
UserId = UserId,
|
||||||
|
Comment = Comment,
|
||||||
|
};
|
||||||
|
|
||||||
|
public void UpdateRecipes(PolyclinicDatabase database, ProcedureBindingModel bindingModel)
|
||||||
|
{
|
||||||
|
var ProcedureRecipes = database.ProcedureRecipes.Where(x => x.ProcedureId == bindingModel.Id).ToList();
|
||||||
|
|
||||||
|
if(ProcedureRecipes != null)
|
||||||
|
{
|
||||||
|
// удалили те, которых нет в модели
|
||||||
|
database.ProcedureRecipes.RemoveRange(ProcedureRecipes.Where(rec => !bindingModel.ProcedureRecipes.ContainsKey(rec.RecipeId)));
|
||||||
|
database.SaveChanges();
|
||||||
|
}
|
||||||
|
var Procedure = database.Procedures.First(x => x.Id == bindingModel.Id);
|
||||||
|
foreach (var pc in bindingModel.ProcedureRecipes)
|
||||||
|
{
|
||||||
|
database.ProcedureRecipes.Add(new ProcedureRecipe
|
||||||
|
{
|
||||||
|
Procedure = Procedure,
|
||||||
|
Recipe = database.Recipes.First(x => x.Id == pc.Key)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_procedureRecipes = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,17 @@
|
|||||||
namespace PolyclinicDatabaseImplement.Models
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace PolyclinicDatabaseImplement.Models
|
||||||
{
|
{
|
||||||
public class ProcedureRecipe
|
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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,5 +17,8 @@ namespace SecuritySystemDatabaseImplement
|
|||||||
public virtual DbSet<Diagnose> Diagnoses { set; get; }
|
public virtual DbSet<Diagnose> Diagnoses { set; get; }
|
||||||
public virtual DbSet<Course> Courses { set; get; }
|
public virtual DbSet<Course> Courses { set; get; }
|
||||||
public virtual DbSet<CourseDiagnose> CourseDiagnoses { 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<ProcedureRecipe> ProcedureRecipes { set; get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user