From ae806f04b4d9be897c1662d32ab563d4200e530c Mon Sep 17 00:00:00 2001 From: goblinrf Date: Tue, 23 Apr 2024 23:47:00 +0400 Subject: [PATCH] =?UTF-8?q?=D1=87=D1=82=D0=BE-=D1=82=D0=BE=20=D1=81=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DinerDataBaseImplement/Models/Animal.cs | 29 ++++++++++++++----- .../DinerDataBaseImplement/Models/Visit.cs | 12 ++++++++ .../Models/VisitAnimal.cs | 24 +++++++++++++++ .../VetClinicDatabase.cs | 9 ++++-- .../BindingModels/AnimalBindingModel.cs | 3 +- .../SearchModels/AnimalSearchModel.cs | 3 +- .../ViewModels/AnimalViewModel.cs | 2 +- .../ViewModels/VisitViewModel.cs | 3 +- .../VetClinicDataModels/Models/IAdminModel.cs | 4 +-- .../Models/IAnimalModel.cs | 6 ++-- .../Models/IVaccinationModel.cs | 4 +-- .../VetClinicDataModels/Models/IVisitModel.cs | 8 ++--- 12 files changed, 81 insertions(+), 26 deletions(-) create mode 100644 VetClinic/DinerDataBaseImplement/Models/Visit.cs create mode 100644 VetClinic/DinerDataBaseImplement/Models/VisitAnimal.cs diff --git a/VetClinic/DinerDataBaseImplement/Models/Animal.cs b/VetClinic/DinerDataBaseImplement/Models/Animal.cs index 7c8d256..194ed37 100644 --- a/VetClinic/DinerDataBaseImplement/Models/Animal.cs +++ b/VetClinic/DinerDataBaseImplement/Models/Animal.cs @@ -18,7 +18,7 @@ namespace VetClinicDataBaseImplement.Models [Required] public int AdminId { get; set; } [Required] - public int VisitId { get; set; } + public List? _visitAnimals = null; [Required] public string AnimalName { get; set; }= string.Empty; @@ -27,16 +27,26 @@ namespace VetClinicDataBaseImplement.Models //public virtual Visit Visit { get; set; } public virtual Admin Admin { get; set; } - //public virtual Visut Visit { get; set; } + public virtual Visit Visit { get; set; } //public virtual Vaccination Vaccination { get; set; } - // [ForeignKey("AnimalId")] - //public virtual List Visits { get; set; } = new(); + [ForeignKey("AnimalId")] + public virtual List Visits { get; set; } = new(); //[ForeignKey("AnimalId")] //public virtual List Vaccinations { get; set; } = new(); - - public static Animal? Create(AnimalBindingModel? model) + public List VisitAnimals + { + get + { + if (_visitAnimals == null) + { + _visitAnimals = Visits.Select(recPC => recPC.Visit as IVisitModel).ToList(); + } + return _visitAnimals; + } + } + public static Animal? Create(VetClinicDatabase context, AnimalBindingModel? model) { if (model == null) { @@ -45,7 +55,10 @@ namespace VetClinicDataBaseImplement.Models return new Animal() { Id = model.Id, - VisitId = model.VisitId, + Visits = model.VisitAnimals.Select(x => new VisitAnimal + { + Id = x.Id + }).ToList(), AdminId = model.AdminId, //VaccinationId = model.VaccinationId AnimalName = model.AnimalName, @@ -65,7 +78,7 @@ namespace VetClinicDataBaseImplement.Models public AnimalViewModel GetViewModel => new() { Id = Id, - VisitId = VisitId, + VisitAnimals = VisitAnimals, AdminId = AdminId, //VaccinationId = VaccinationId AnimalName = AnimalName, diff --git a/VetClinic/DinerDataBaseImplement/Models/Visit.cs b/VetClinic/DinerDataBaseImplement/Models/Visit.cs new file mode 100644 index 0000000..9cd620e --- /dev/null +++ b/VetClinic/DinerDataBaseImplement/Models/Visit.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VetClinicDataBaseImplement.Models +{ + public class Visit + { + } +} diff --git a/VetClinic/DinerDataBaseImplement/Models/VisitAnimal.cs b/VetClinic/DinerDataBaseImplement/Models/VisitAnimal.cs new file mode 100644 index 0000000..0093b3a --- /dev/null +++ b/VetClinic/DinerDataBaseImplement/Models/VisitAnimal.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VetClinicDataBaseImplement.Models; + +namespace VetClinicDataBaseImplement.Models +{ + public class VisitAnimal + { + public int Id { get; set; } + [Required] + public int AnimalId { get; set; } + [Required] + public int VisittId { get; set; } + + public virtual Animal Animal { get; set; } = new(); + public virtual Visit Visit { get; set; } = new(); + } +} diff --git a/VetClinic/DinerDataBaseImplement/VetClinicDatabase.cs b/VetClinic/DinerDataBaseImplement/VetClinicDatabase.cs index d66b522..6fc17d9 100644 --- a/VetClinic/DinerDataBaseImplement/VetClinicDatabase.cs +++ b/VetClinic/DinerDataBaseImplement/VetClinicDatabase.cs @@ -1,6 +1,8 @@ using VetClinicDataBaseImplement.Models; using Microsoft.EntityFrameworkCore; + + namespace VetClinicDataBaseImplement { public class VetClinicDatabase : DbContext @@ -15,7 +17,8 @@ namespace VetClinicDataBaseImplement } public virtual DbSet Animals { set; get; } public virtual DbSet Admins { set; get; } - // public virtual DbSet Visits { set; get; } - // public virtual DbSet Vaccinations { set; get; } - } + public virtual DbSet VisitAnimals { set; get; } + public virtual DbSet Visits { set; get; } + // public virtual DbSet Vaccinations { set; get; } + } } diff --git a/VetClinic/VetClinicContracts/BindingModels/AnimalBindingModel.cs b/VetClinic/VetClinicContracts/BindingModels/AnimalBindingModel.cs index 2fc3c99..9ac53fe 100644 --- a/VetClinic/VetClinicContracts/BindingModels/AnimalBindingModel.cs +++ b/VetClinic/VetClinicContracts/BindingModels/AnimalBindingModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using VetClinicDataModels.Models; namespace VetClinicContracts.BindingModels { @@ -10,7 +11,7 @@ namespace VetClinicContracts.BindingModels { public int Id { get; set; } public int AdminId { get; set; } - public int VisitId { get; set; } + public List VisitAnimals { get; set; } = new(); public string AnimalName { get; set; } = string.Empty; public string? Family { get; set; } = string.Empty; diff --git a/VetClinic/VetClinicContracts/SearchModels/AnimalSearchModel.cs b/VetClinic/VetClinicContracts/SearchModels/AnimalSearchModel.cs index 1ab0a81..971c1b7 100644 --- a/VetClinic/VetClinicContracts/SearchModels/AnimalSearchModel.cs +++ b/VetClinic/VetClinicContracts/SearchModels/AnimalSearchModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using VetClinicDataModels.Models; namespace VetClinicContracts.SearchModels { @@ -11,7 +12,7 @@ namespace VetClinicContracts.SearchModels public int? Id { get; set; } public int? AdminId { get; set; } - public int? VisitId { get; set; } + public List Visits { get; set; } = new(); public string? AnimalName { get; set; } diff --git a/VetClinic/VetClinicContracts/ViewModels/AnimalViewModel.cs b/VetClinic/VetClinicContracts/ViewModels/AnimalViewModel.cs index 068aba3..b123df3 100644 --- a/VetClinic/VetClinicContracts/ViewModels/AnimalViewModel.cs +++ b/VetClinic/VetClinicContracts/ViewModels/AnimalViewModel.cs @@ -13,7 +13,7 @@ namespace VetClinicContracts.ViewModels public int Id { get; set; } public int AdminId { get; set; } - public int VisitId { get; set; } + public List VisitAnimals { get; set; } = new(); [DisplayName("Имя животного")] public string AnimalName { get; set; } = string.Empty; diff --git a/VetClinic/VetClinicContracts/ViewModels/VisitViewModel.cs b/VetClinic/VetClinicContracts/ViewModels/VisitViewModel.cs index 156822d..ffda9cc 100644 --- a/VetClinic/VetClinicContracts/ViewModels/VisitViewModel.cs +++ b/VetClinic/VetClinicContracts/ViewModels/VisitViewModel.cs @@ -22,5 +22,6 @@ namespace VetClinicContracts.ViewModels [DisplayName("Дата визита")] public DateTime DateVisit { get; set; } - } + public List VisitAnimals { get; set; } = new(); + } } diff --git a/VetClinic/VetClinicDataModels/Models/IAdminModel.cs b/VetClinic/VetClinicDataModels/Models/IAdminModel.cs index 38b2aab..918d3d0 100644 --- a/VetClinic/VetClinicDataModels/Models/IAdminModel.cs +++ b/VetClinic/VetClinicDataModels/Models/IAdminModel.cs @@ -1,8 +1,8 @@  namespace VetClinicDataModels.Models { - public interface IAdminModel - { + public interface IAdminModel : IId + { string AdminFIO { get; } string Email { get; } string Password { get; } diff --git a/VetClinic/VetClinicDataModels/Models/IAnimalModel.cs b/VetClinic/VetClinicDataModels/Models/IAnimalModel.cs index 1a392b1..d3e0bb0 100644 --- a/VetClinic/VetClinicDataModels/Models/IAnimalModel.cs +++ b/VetClinic/VetClinicDataModels/Models/IAnimalModel.cs @@ -6,10 +6,10 @@ using System.Threading.Tasks; namespace VetClinicDataModels.Models { - public interface IAnimalModel - { + public interface IAnimalModel : IId + { int AdminId { get; } - int VisitId { get; } + List VisitAnimals { get; } string AnimalName { get; } string? Family { get; } } diff --git a/VetClinic/VetClinicDataModels/Models/IVaccinationModel.cs b/VetClinic/VetClinicDataModels/Models/IVaccinationModel.cs index cf1c1e2..9c49474 100644 --- a/VetClinic/VetClinicDataModels/Models/IVaccinationModel.cs +++ b/VetClinic/VetClinicDataModels/Models/IVaccinationModel.cs @@ -6,8 +6,8 @@ using System.Threading.Tasks; namespace VetClinicDataModels.Models { - public interface IVaccinationModel - { + public interface IVaccinationModel : IId + { int AnimalId { get; } string NameVaccination { get; } diff --git a/VetClinic/VetClinicDataModels/Models/IVisitModel.cs b/VetClinic/VetClinicDataModels/Models/IVisitModel.cs index ec07c25..b82bf57 100644 --- a/VetClinic/VetClinicDataModels/Models/IVisitModel.cs +++ b/VetClinic/VetClinicDataModels/Models/IVisitModel.cs @@ -6,13 +6,13 @@ using System.Threading.Tasks; namespace VetClinicDataModels.Models { - public interface IVisitModel - { + public interface IVisitModel : IId + { int Id { get;} int ServiceId { get; } - int AdminId { get; } string NameVisit { get;} DateTime DateVisit { get; } - } + List VisitAnimals { get; } + } }