diff --git a/VeterinaryClinic/VeterinaryClinic.sln b/VeterinaryClinic/VeterinaryClinic.sln index 97a9f3d..e704da6 100644 --- a/VeterinaryClinic/VeterinaryClinic.sln +++ b/VeterinaryClinic/VeterinaryClinic.sln @@ -5,6 +5,12 @@ VisualStudioVersion = 17.8.34330.188 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VeterinaryClinicWebApp", "VeterinaryClinicWebApp\VeterinaryClinicWebApp.csproj", "{97D6A5FF-C23C-409C-BA88-2E071E0E4CCB}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VeterinaryClinicDataModels", "VeterinaryClinicDataModels\VeterinaryClinicDataModels.csproj", "{DC72FB31-B63C-459B-9F7C-40738982C301}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VeterinaryClinicContracts", "VeterinaryClinicContracts\VeterinaryClinicContracts.csproj", "{250EA581-B1A8-4D0F-8019-B10ABDC8E99E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VeterinaryClinicDatabaseImplement", "VeterinaryClinicDatabaseImplement\VeterinaryClinicDatabaseImplement.csproj", "{BC172585-14F2-4484-8855-F00019F5EA5F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +21,18 @@ Global {97D6A5FF-C23C-409C-BA88-2E071E0E4CCB}.Debug|Any CPU.Build.0 = Debug|Any CPU {97D6A5FF-C23C-409C-BA88-2E071E0E4CCB}.Release|Any CPU.ActiveCfg = Release|Any CPU {97D6A5FF-C23C-409C-BA88-2E071E0E4CCB}.Release|Any CPU.Build.0 = Release|Any CPU + {DC72FB31-B63C-459B-9F7C-40738982C301}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DC72FB31-B63C-459B-9F7C-40738982C301}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DC72FB31-B63C-459B-9F7C-40738982C301}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DC72FB31-B63C-459B-9F7C-40738982C301}.Release|Any CPU.Build.0 = Release|Any CPU + {250EA581-B1A8-4D0F-8019-B10ABDC8E99E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {250EA581-B1A8-4D0F-8019-B10ABDC8E99E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {250EA581-B1A8-4D0F-8019-B10ABDC8E99E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {250EA581-B1A8-4D0F-8019-B10ABDC8E99E}.Release|Any CPU.Build.0 = Release|Any CPU + {BC172585-14F2-4484-8855-F00019F5EA5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BC172585-14F2-4484-8855-F00019F5EA5F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BC172585-14F2-4484-8855-F00019F5EA5F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BC172585-14F2-4484-8855-F00019F5EA5F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/AnimalBindingModel.cs b/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/AnimalBindingModel.cs new file mode 100644 index 0000000..0dbddd7 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/AnimalBindingModel.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicDataModels.Models; + +namespace VeterinaryClinicContracts.BindingModels +{ + public class AnimalBindingModel : IAnimalModel + { + public int Id { get; set; } + + public string Type { get; set; } = string.Empty; + + public string Breed { get; set; } = string.Empty; + + public int Age { get; set; } + + public int UserId { get; set; } + + public Dictionary AnimalMedications { get; set; } = new(); + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/MedicationBindingModel.cs b/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/MedicationBindingModel.cs new file mode 100644 index 0000000..2ab7180 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/MedicationBindingModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicDataModels.Models; + +namespace VeterinaryClinicContracts.BindingModels +{ + public class MedicationBindingModel : IMedicationModel + { + public int Id { get; set; } + + public string Name { get; set; } = string.Empty; + + public string Description { get; set; } = string.Empty; + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/ServiceBindingModel.cs b/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/ServiceBindingModel.cs new file mode 100644 index 0000000..42461c7 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/ServiceBindingModel.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicDataModels.Models; + +namespace VeterinaryClinicContracts.BindingModels +{ + public class ServiceBindingModel : IServiceModel + { + public int Id { get; set; } + + public string Name { get; set; } = string.Empty; + + public int Cost { get; set; } + + public int MedicationId { get; set; } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/UserBindingModel.cs b/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/UserBindingModel.cs new file mode 100644 index 0000000..9ee0388 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/UserBindingModel.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicDataModels.Enums; +using VeterinaryClinicDataModels.Models; + +namespace VeterinaryClinicContracts.BindingModels +{ + public class UserBindingModel : IUserModel + { + public int Id { get; set; } + + public string FullName { get; set; } = string.Empty; + + public string Phone { get; set; } = string.Empty; + + public string Email { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + public UserRole Role { get; set; } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/VaccinationBindingModel.cs b/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/VaccinationBindingModel.cs new file mode 100644 index 0000000..f5638da --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/VaccinationBindingModel.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicDataModels.Models; + +namespace VeterinaryClinicContracts.BindingModels +{ + public class VaccinationBindingModel : IVaccinationModel + { + public int Id { get; set; } + + public string Name { get; set; } = string.Empty; + + public DateTime DateInjection { get; set; } + + public string ValidityPeriod { get; set; } = string.Empty; + + public int UserId { get; set; } + + public int AnimalId { get; set; } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/VisitBindingModel.cs b/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/VisitBindingModel.cs new file mode 100644 index 0000000..a8c2fa9 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/BindingModels/VisitBindingModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicDataModels.Models; + +namespace VeterinaryClinicContracts.BindingModels +{ + public class VisitBindingModel : IVisitModel + { + public int Id { get; set; } + + public DateTime Date { get; set; } + + public int UserId { get; set; } + + public Dictionary VisitAnimals { get; set; } = new(); + + public Dictionary VisitServices { get; set; } = new(); + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/BusinessLogicsContracts/IAnimalLogic.cs b/VeterinaryClinic/VeterinaryClinicContracts/BusinessLogicsContracts/IAnimalLogic.cs new file mode 100644 index 0000000..5f1e536 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/BusinessLogicsContracts/IAnimalLogic.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicContracts.ViewModels; + +namespace VeterinaryClinicContracts.BusinessLogicsContracts +{ + public interface IAnimalLogic + { + List? ReadList(AnimalSearchModel? model); + + AnimalViewModel? ReadElement(AnimalSearchModel model); + + bool Create(AnimalBindingModel model); + + bool Update(AnimalBindingModel model); + + bool Delete(AnimalBindingModel model); + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/BusinessLogicsContracts/IMedicationLogic.cs b/VeterinaryClinic/VeterinaryClinicContracts/BusinessLogicsContracts/IMedicationLogic.cs new file mode 100644 index 0000000..ee9312b --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/BusinessLogicsContracts/IMedicationLogic.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicContracts.ViewModels; + +namespace VeterinaryClinicContracts.BusinessLogicsContracts +{ + public interface IMedicationLogic + { + List? ReadList(MedicationSearchModel? model); + + MedicationViewModel? ReadElement(MedicationSearchModel model); + + bool Create(MedicationBindingModel model); + + bool Update(MedicationBindingModel model); + + bool Delete(MedicationBindingModel model); + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/BusinessLogicsContracts/IServiceLogic.cs b/VeterinaryClinic/VeterinaryClinicContracts/BusinessLogicsContracts/IServiceLogic.cs new file mode 100644 index 0000000..31311c9 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/BusinessLogicsContracts/IServiceLogic.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicContracts.ViewModels; + +namespace VeterinaryClinicContracts.BusinessLogicsContracts +{ + public interface IServiceLogic + { + List? ReadList(ServiceSearchModel? model); + + ServiceViewModel? ReadElement(ServiceSearchModel model); + + bool Create(ServiceBindingModel model); + + bool Update(ServiceBindingModel model); + + bool Delete(ServiceBindingModel model); + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/BusinessLogicsContracts/IUserLogic.cs b/VeterinaryClinic/VeterinaryClinicContracts/BusinessLogicsContracts/IUserLogic.cs new file mode 100644 index 0000000..4d066ed --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/BusinessLogicsContracts/IUserLogic.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicContracts.ViewModels; + +namespace VeterinaryClinicContracts.BusinessLogicsContracts +{ + public interface IUserLogic + { + List? ReadList(UserSearchModel? model); + + UserViewModel? ReadElement(UserSearchModel model); + + bool Create(UserBindingModel model); + + bool Update(UserBindingModel model); + + bool Delete(UserBindingModel model); + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/BusinessLogicsContracts/IVaccinationLogic.cs b/VeterinaryClinic/VeterinaryClinicContracts/BusinessLogicsContracts/IVaccinationLogic.cs new file mode 100644 index 0000000..fedb957 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/BusinessLogicsContracts/IVaccinationLogic.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicContracts.ViewModels; + +namespace VeterinaryClinicContracts.BusinessLogicsContracts +{ + public interface IVaccinationLogic + { + List? ReadList(VaccinationSearchModel? model); + + VaccinationViewModel? ReadElement(VaccinationSearchModel model); + + bool Create(VaccinationBindingModel model); + + bool Update(VaccinationBindingModel model); + + bool Delete(VaccinationBindingModel model); + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/BusinessLogicsContracts/IVisitLogic.cs b/VeterinaryClinic/VeterinaryClinicContracts/BusinessLogicsContracts/IVisitLogic.cs new file mode 100644 index 0000000..d342804 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/BusinessLogicsContracts/IVisitLogic.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicContracts.ViewModels; + +namespace VeterinaryClinicContracts.BusinessLogicsContracts +{ + public interface IVisitLogic + { + List? ReadList(VisitSearchModel? model); + + VisitViewModel? ReadElement(VisitSearchModel model); + + bool Create(VisitBindingModel model); + + bool Update(VisitBindingModel model); + + bool Delete(VaccinationBindingModel model); + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/SearchModels/AnimalSearchModel.cs b/VeterinaryClinic/VeterinaryClinicContracts/SearchModels/AnimalSearchModel.cs new file mode 100644 index 0000000..53d4518 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/SearchModels/AnimalSearchModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VeterinaryClinicContracts.SearchModels +{ + public class AnimalSearchModel + { + public int? Id { get; set; } + + public string? Type { get; set; } + + public string? Breed { get; set; } + + public int? Age { get; set; } + + public int? UserId { get; set; } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/SearchModels/MedicationSearchModel.cs b/VeterinaryClinic/VeterinaryClinicContracts/SearchModels/MedicationSearchModel.cs new file mode 100644 index 0000000..8f68110 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/SearchModels/MedicationSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VeterinaryClinicContracts.SearchModels +{ + public class MedicationSearchModel + { + public int? Id { get; set; } + + public string? Name { get; set; } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/SearchModels/ServiceSearchModel.cs b/VeterinaryClinic/VeterinaryClinicContracts/SearchModels/ServiceSearchModel.cs new file mode 100644 index 0000000..eefdffa --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/SearchModels/ServiceSearchModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VeterinaryClinicContracts.SearchModels +{ + public class ServiceSearchModel + { + public int? Id { get; set; } + + public string? Name { get; set; } + + public int? MedicationId { get; set; } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/SearchModels/UserSearchModel.cs b/VeterinaryClinic/VeterinaryClinicContracts/SearchModels/UserSearchModel.cs new file mode 100644 index 0000000..f72022c --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/SearchModels/UserSearchModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VeterinaryClinicContracts.SearchModels +{ + public class UserSearchModel + { + public int? Id { get; set; } + + public string? FullName { get; set; } + + public string? Phone { get; set; } + + public string? Email { get; set; } + + public string? Password { get; set; } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/SearchModels/VaccinationSearchModel.cs b/VeterinaryClinic/VeterinaryClinicContracts/SearchModels/VaccinationSearchModel.cs new file mode 100644 index 0000000..a31200c --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/SearchModels/VaccinationSearchModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VeterinaryClinicContracts.SearchModels +{ + public class VaccinationSearchModel + { + public int? Id { get; set; } + + public string? Name { get; set; } + + public int? UserId { get; set; } + + public int? AnimalId { get; set; } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/SearchModels/VisitSearchModel.cs b/VeterinaryClinic/VeterinaryClinicContracts/SearchModels/VisitSearchModel.cs new file mode 100644 index 0000000..672be9f --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/SearchModels/VisitSearchModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VeterinaryClinicContracts.SearchModels +{ + public class VisitSearchModel + { + public int? Id { get; set; } + + public int? UserId { get; set; } + + public DateTime? DateFrom { get; set; } + + public DateTime? DateTo { get; set; } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/StoragesContracts/IAnimalStorage.cs b/VeterinaryClinic/VeterinaryClinicContracts/StoragesContracts/IAnimalStorage.cs new file mode 100644 index 0000000..8dad21d --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/StoragesContracts/IAnimalStorage.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicContracts.ViewModels; + +namespace VeterinaryClinicContracts.StoragesContracts +{ + public interface IAnimalStorage + { + List GetFullList(); + + List GetFilteredList(AnimalSearchModel model); + + AnimalViewModel? GetElement(AnimalSearchModel model); + + AnimalViewModel? Insert(AnimalBindingModel model); + + AnimalViewModel? Update(AnimalBindingModel model); + + AnimalViewModel? Delete(AnimalBindingModel model); + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/StoragesContracts/IMedicationStorage.cs b/VeterinaryClinic/VeterinaryClinicContracts/StoragesContracts/IMedicationStorage.cs new file mode 100644 index 0000000..7aa75f8 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/StoragesContracts/IMedicationStorage.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicContracts.ViewModels; + +namespace VeterinaryClinicContracts.StoragesContracts +{ + public interface IMedicationStorage + { + List GetFullList(); + + List GetFilteredList(MedicationSearchModel model); + + MedicationViewModel? GetElement(MedicationSearchModel model); + + MedicationViewModel? Insert(MedicationBindingModel model); + + MedicationViewModel? Update(MedicationBindingModel model); + + MedicationViewModel? Delete(MedicationBindingModel model); + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/StoragesContracts/IServiceStorage.cs b/VeterinaryClinic/VeterinaryClinicContracts/StoragesContracts/IServiceStorage.cs new file mode 100644 index 0000000..e938ce7 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/StoragesContracts/IServiceStorage.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicContracts.ViewModels; + +namespace VeterinaryClinicContracts.StoragesContracts +{ + public interface IServiceStorage + { + List GetFullList(); + + List GetFilteredList(ServiceSearchModel model); + + ServiceViewModel? GetElement(ServiceSearchModel model); + + ServiceViewModel? Insert(ServiceBindingModel model); + + ServiceViewModel? Update(ServiceBindingModel model); + + ServiceViewModel? Delete(ServiceBindingModel model); + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/StoragesContracts/IUserStorage.cs b/VeterinaryClinic/VeterinaryClinicContracts/StoragesContracts/IUserStorage.cs new file mode 100644 index 0000000..dea2ad8 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/StoragesContracts/IUserStorage.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicContracts.ViewModels; + +namespace VeterinaryClinicContracts.StoragesContracts +{ + public interface IUserStorage + { + List GetFullList(); + + List GetFilteredList(UserSearchModel model); + + UserViewModel? GetElement(UserSearchModel model); + + UserViewModel? Insert(UserBindingModel model); + + UserViewModel? Update(UserBindingModel model); + + UserViewModel? Delete(UserBindingModel model); + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/StoragesContracts/IVaccinationStorage.cs b/VeterinaryClinic/VeterinaryClinicContracts/StoragesContracts/IVaccinationStorage.cs new file mode 100644 index 0000000..68fde2c --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/StoragesContracts/IVaccinationStorage.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicContracts.ViewModels; + +namespace VeterinaryClinicContracts.StoragesContracts +{ + public interface IVaccinationStorage + { + List GetFullList(); + + List GetFilteredList(VaccinationSearchModel model); + + VaccinationViewModel? GetElement(VaccinationSearchModel model); + + VaccinationViewModel? Insert(VaccinationBindingModel model); + + VaccinationViewModel? Update(VaccinationBindingModel model); + + VaccinationViewModel? Delete(VaccinationBindingModel model); + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/StoragesContracts/IVisitStorage.cs b/VeterinaryClinic/VeterinaryClinicContracts/StoragesContracts/IVisitStorage.cs new file mode 100644 index 0000000..24b001e --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/StoragesContracts/IVisitStorage.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicContracts.ViewModels; + +namespace VeterinaryClinicContracts.StoragesContracts +{ + public interface IVisitStorage + { + List GetFullList(); + + List GetFilteredList(VisitSearchModel model); + + VisitViewModel? GetElement(VisitSearchModel model); + + VisitViewModel? Insert(VisitBindingModel model); + + VisitViewModel? Update(VisitBindingModel model); + + VisitViewModel? Delete(VisitBindingModel model); + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/VeterinaryClinicContracts.csproj b/VeterinaryClinic/VeterinaryClinicContracts/VeterinaryClinicContracts.csproj new file mode 100644 index 0000000..73dbf19 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/VeterinaryClinicContracts.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/VeterinaryClinic/VeterinaryClinicContracts/ViewModels/AnimalViewModel.cs b/VeterinaryClinic/VeterinaryClinicContracts/ViewModels/AnimalViewModel.cs new file mode 100644 index 0000000..b3b03ea --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/ViewModels/AnimalViewModel.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicDataModels.Models; + +namespace VeterinaryClinicContracts.ViewModels +{ + public class AnimalViewModel : IAnimalModel + { + public int Id { get; set; } + + [DisplayName("Вид животного")] + public string Type { get; set; } = string.Empty; + + [DisplayName("Порода")] + public string Breed { get; set; } = string.Empty; + + [DisplayName("Возраст")] + public int Age { get; set; } + + public int UserId { get; set; } + + [DisplayName("ФИО пользователя")] + public string UserFullName { get; set; } = string.Empty; + + public Dictionary AnimalMedications { get; set; } = new(); + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/ViewModels/MedicationViewModel.cs b/VeterinaryClinic/VeterinaryClinicContracts/ViewModels/MedicationViewModel.cs new file mode 100644 index 0000000..d64d502 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/ViewModels/MedicationViewModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicDataModels.Models; + +namespace VeterinaryClinicContracts.ViewModels +{ + public class MedicationViewModel: IMedicationModel + { + public int Id { get; set; } + + [DisplayName("Название медикамента")] + public string Name { get; set; } = string.Empty; + + [DisplayName("Описание")] + public string Description { get; set; } = string.Empty; + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/ViewModels/ServiceViewModel.cs b/VeterinaryClinic/VeterinaryClinicContracts/ViewModels/ServiceViewModel.cs new file mode 100644 index 0000000..01d09c8 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/ViewModels/ServiceViewModel.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicDataModels.Models; + +namespace VeterinaryClinicContracts.ViewModels +{ + public class ServiceViewModel : IServiceModel + { + public int Id { get; set; } + + [DisplayName("Название услуги")] + public string Name { get; set; } = string.Empty; + + [DisplayName("Стоимость")] + public int Cost { get; set; } + + public int MedicationId { get; set; } + + [DisplayName("Наименования медикамента")] + public string MedicationName { get; set; } = string.Empty; + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/ViewModels/UserViewModel.cs b/VeterinaryClinic/VeterinaryClinicContracts/ViewModels/UserViewModel.cs new file mode 100644 index 0000000..b478adf --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/ViewModels/UserViewModel.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicDataModels.Enums; +using VeterinaryClinicDataModels.Models; + +namespace VeterinaryClinicContracts.ViewModels +{ + public class UserViewModel : IUserModel + { + public int Id { get; set; } + + [DisplayName("ФИО")] + public string FullName { get; set; } = string.Empty; + + [DisplayName("Телефон")] + public string Phone { get; set; } = string.Empty; + + [DisplayName("Почта")] + public string Email { get; set; } = string.Empty; + + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + + [DisplayName("Роль")] + public UserRole Role { get; set; } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/ViewModels/VaccinationViewModel.cs b/VeterinaryClinic/VeterinaryClinicContracts/ViewModels/VaccinationViewModel.cs new file mode 100644 index 0000000..082cafe --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/ViewModels/VaccinationViewModel.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicDataModels.Models; + +namespace VeterinaryClinicContracts.ViewModels +{ + public class VaccinationViewModel : IVaccinationModel + { + public int Id { get; set; } + + [DisplayName("Название вакцины")] + public string Name { get; set; } = string.Empty; + + [DisplayName("Дата укола")] + public DateTime DateInjection { get; set; } + + [DisplayName("Срок действия")] + public string ValidityPeriod { get; set; } = string.Empty; + + public int UserId { get; set; } + + [DisplayName("ФИО пользователя")] + public string UserFullName { get; set; } = string.Empty; + + public int AnimalId { get; set; } + + [DisplayName("Порода животного")] + public string AnimalBreed { get; set; } = string.Empty; + } +} diff --git a/VeterinaryClinic/VeterinaryClinicContracts/ViewModels/VisitViewModel.cs b/VeterinaryClinic/VeterinaryClinicContracts/ViewModels/VisitViewModel.cs new file mode 100644 index 0000000..9f7daf1 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicContracts/ViewModels/VisitViewModel.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicDataModels.Models; + +namespace VeterinaryClinicContracts.ViewModels +{ + public class VisitViewModel : IVisitModel + { + public int Id { get; set; } + + [DisplayName("Дата визита")] + public DateTime Date { get; set; } + + public int UserId { get; set; } + + [DisplayName("ФИО пользователя")] + public string UserFullName { get; set; } = string.Empty; + + public Dictionary VisitAnimals { get; set; } = new(); + + public Dictionary VisitServices { get; set; } = new(); + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDataModels/Enums/UserRole.cs b/VeterinaryClinic/VeterinaryClinicDataModels/Enums/UserRole.cs new file mode 100644 index 0000000..76ee9ee --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDataModels/Enums/UserRole.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VeterinaryClinicDataModels.Enums +{ + public enum UserRole + { + Неизвестный = -1, + Администратор = 0, + Работник = 1, + Кладовщик = 2, + Клиент = 3 + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDataModels/IId.cs b/VeterinaryClinic/VeterinaryClinicDataModels/IId.cs new file mode 100644 index 0000000..f3e02e0 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace VeterinaryClinicDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDataModels/Models/IAnimalModel.cs b/VeterinaryClinic/VeterinaryClinicDataModels/Models/IAnimalModel.cs new file mode 100644 index 0000000..99e6105 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDataModels/Models/IAnimalModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VeterinaryClinicDataModels.Models +{ + public interface IAnimalModel : IId + { + string Type { get; } + + string Breed { get; } + + int Age { get; } + + int UserId { get; } + + Dictionary AnimalMedications { get; } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDataModels/Models/IMedicationModel.cs b/VeterinaryClinic/VeterinaryClinicDataModels/Models/IMedicationModel.cs new file mode 100644 index 0000000..adbd4e4 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDataModels/Models/IMedicationModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VeterinaryClinicDataModels.Models +{ + public interface IMedicationModel : IId + { + string Name { get; } + + string Description { get; } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDataModels/Models/IServiceModel.cs b/VeterinaryClinic/VeterinaryClinicDataModels/Models/IServiceModel.cs new file mode 100644 index 0000000..b0f68fc --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDataModels/Models/IServiceModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VeterinaryClinicDataModels.Models +{ + public interface IServiceModel : IId + { + string Name { get; } + + int Cost { get; } + + int MedicationId { get; } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDataModels/Models/IUserModel.cs b/VeterinaryClinic/VeterinaryClinicDataModels/Models/IUserModel.cs new file mode 100644 index 0000000..ae96087 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDataModels/Models/IUserModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicDataModels.Enums; + +namespace VeterinaryClinicDataModels.Models +{ + public interface IUserModel: IId + { + string FullName { get; } + + string Phone { get; } + + string Email { get; } + + string Password { get; } + + UserRole Role { get; } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDataModels/Models/IVaccinationModel.cs b/VeterinaryClinic/VeterinaryClinicDataModels/Models/IVaccinationModel.cs new file mode 100644 index 0000000..9852134 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDataModels/Models/IVaccinationModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VeterinaryClinicDataModels.Models +{ + public interface IVaccinationModel : IId + { + string Name { get; } + + DateTime DateInjection { get; } + + string ValidityPeriod { get; } + + int UserId { get; } + + int AnimalId { get; } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDataModels/Models/IVisitModel.cs b/VeterinaryClinic/VeterinaryClinicDataModels/Models/IVisitModel.cs new file mode 100644 index 0000000..45e17b9 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDataModels/Models/IVisitModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VeterinaryClinicDataModels.Models +{ + public interface IVisitModel : IId + { + DateTime Date { get; } + + int UserId { get; } + + Dictionary VisitAnimals { get; } + + Dictionary VisitServices { get; } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDataModels/VeterinaryClinicDataModels.csproj b/VeterinaryClinic/VeterinaryClinicDataModels/VeterinaryClinicDataModels.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDataModels/VeterinaryClinicDataModels.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/AnimalStorage.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/AnimalStorage.cs new file mode 100644 index 0000000..0a018c3 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/AnimalStorage.cs @@ -0,0 +1,122 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicContracts.StoragesContracts; +using VeterinaryClinicContracts.ViewModels; +using VeterinaryClinicDatabaseImplement.Models; + +namespace VeterinaryClinicDatabaseImplement.Implements +{ + public class AnimalStorage : IAnimalStorage + { + public AnimalViewModel? Delete(AnimalBindingModel model) + { + using var context = new VeterinaryClinicDatabase(); + var animal = context.Animals + .Include(x => x.User) + .Include(x => x.Medications) + .ThenInclude(x => x.Medication) + .FirstOrDefault(x => x.Id == model.Id); + if (animal == null) + { + return null; + } + + context.Animals.Remove(animal); + context.SaveChanges(); + return animal.GetViewModel; + } + + public AnimalViewModel? GetElement(AnimalSearchModel model) + { + using var context = new VeterinaryClinicDatabase(); + + if (model.Id.HasValue) + { + return context.Animals + .Include(x => x.User) + .Include(x => x.Medications) + .ThenInclude(x => x.Medication) + .FirstOrDefault(x => x.Id.Equals(model.Id)) + ?.GetViewModel; + } + + return null; + } + + public List GetFilteredList(AnimalSearchModel model) + { + using var context = new VeterinaryClinicDatabase(); + + if (!string.IsNullOrEmpty(model.Breed)) + { + return context.Animals + .Include(x => x.User) + .Include(x => x.Medications) + .ThenInclude(x => x.Medication) + .Where(x => x.Breed.Contains(model.Breed)) + .Select(x => x.GetViewModel) + .ToList(); + } + + return new(); + } + + public List GetFullList() + { + using var context = new VeterinaryClinicDatabase(); + return context.Animals + .Include(x => x.User) + .Include(x => x.Medications) + .ThenInclude(x => x.Medication) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public AnimalViewModel? Insert(AnimalBindingModel model) + { + using var context = new VeterinaryClinicDatabase(); + var newAnimal = Animal.Create(context, model); + if (newAnimal == null) + { + return null; + } + + context.Animals.Add(newAnimal); + context.SaveChanges(); + return newAnimal.GetViewModel; + } + + public AnimalViewModel? Update(AnimalBindingModel model) + { + using var context = new VeterinaryClinicDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var animal = context.Animals + .FirstOrDefault(x => x.Id == model.Id); + if (animal == null) + { + return null; + } + + animal.Update(model); + context.SaveChanges(); + animal.UpdateMedications(context, model); + transaction.Commit(); + return animal.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/MedicationStorage.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/MedicationStorage.cs new file mode 100644 index 0000000..77bd29b --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/MedicationStorage.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicContracts.StoragesContracts; +using VeterinaryClinicContracts.ViewModels; +using VeterinaryClinicDatabaseImplement.Models; + +namespace VeterinaryClinicDatabaseImplement.Implements +{ + public class MedicationStorage : IMedicationStorage + { + public MedicationViewModel? Delete(MedicationBindingModel model) + { + using var context = new VeterinaryClinicDatabase(); + var medication = context.Medications + .FirstOrDefault(x => x.Id.Equals(model.Id)); + if (medication == null) + { + return null; + } + + context.Medications.Remove(medication); + context.SaveChanges(); + return medication.GetViewModel; + } + + public MedicationViewModel? GetElement(MedicationSearchModel model) + { + using var context = new VeterinaryClinicDatabase(); + + if (model.Id.HasValue) + { + return context.Medications + .FirstOrDefault(x => x.Id.Equals(model.Id)) + ?.GetViewModel; + } + + return null; + } + + public List GetFilteredList(MedicationSearchModel model) + { + using var context = new VeterinaryClinicDatabase(); + if (!string.IsNullOrEmpty(model.Name)) + { + return context.Medications + .Where(x => x.Name.Contains(model.Name)) + .Select(x => x.GetViewModel) + .ToList(); + } + + return new(); + } + + public List GetFullList() + { + using var context = new VeterinaryClinicDatabase(); + return context.Medications + .Select(x => x.GetViewModel) + .ToList(); + } + + public MedicationViewModel? Insert(MedicationBindingModel model) + { + using var context = new VeterinaryClinicDatabase(); + var newMedication = Medication.Create(model); + if (newMedication == null) + { + return null; + } + + context.Medications.Add(newMedication); + context.SaveChanges(); + return newMedication.GetViewModel; + } + + public MedicationViewModel? Update(MedicationBindingModel model) + { + using var context = new VeterinaryClinicDatabase(); + var newMedication = context.Medications + .FirstOrDefault(x => x.Id.Equals(model.Id)); + if (newMedication == null) + { + return null; + } + + newMedication.Update(model); + context.SaveChanges(); + return newMedication.GetViewModel; + } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/ServiceStorage.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/ServiceStorage.cs new file mode 100644 index 0000000..e0694c5 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/ServiceStorage.cs @@ -0,0 +1,112 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicContracts.StoragesContracts; +using VeterinaryClinicContracts.ViewModels; +using VeterinaryClinicDatabaseImplement.Models; + +namespace VeterinaryClinicDatabaseImplement.Implements +{ + public class ServiceStorage : IServiceStorage + { + public ServiceViewModel? Delete(ServiceBindingModel model) + { + using var context = new VeterinaryClinicDatabase(); + var service = context.Services + .FirstOrDefault(x => x.Id == model.Id); + if (service == null) + { + return null; + } + + context.Services.Remove(service); + context.SaveChanges(); + return service.GetViewModel; + } + + public ServiceViewModel? GetElement(ServiceSearchModel model) + { + using var context = new VeterinaryClinicDatabase(); + + if (model.Id.HasValue) + { + return context.Services + .Include(x => x.Medication) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + + if (!string.IsNullOrEmpty(model.Name)) + { + return context.Services + .Include(x => x.Medication) + .FirstOrDefault(x => x.Name.Equals(model.Name)) + ?.GetViewModel; + } + + return null; + } + + public List GetFilteredList(ServiceSearchModel model) + { + using var database = new VeterinaryClinicDatabase(); + + if (!string.IsNullOrEmpty(model.Name)) + { + return database.Services + .Include(x => x.Medication) + .Where(x => x.Name.Contains(model.Name)) + .Select(x => x.GetViewModel) + .ToList(); + } + + return new(); + } + + public List GetFullList() + { + using var database = new VeterinaryClinicDatabase(); + + return database.Services + .Include(x => x.Medication) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public ServiceViewModel? Insert(ServiceBindingModel model) + { + using var context = new VeterinaryClinicDatabase(); + var newService = Service.Create(context, model); + + if (newService == null) + { + return null; + } + + context.Services.Add(newService); + context.SaveChanges(); + return newService.GetViewModel; + } + + public ServiceViewModel? Update(ServiceBindingModel model) + { + using var context = new VeterinaryClinicDatabase(); + var service = context.Services + .FirstOrDefault(x => x.Id == model.Id); + if (service == null) + { + return null; + } + + service.Update(model); + context.SaveChanges(); + return service.GetViewModel; + } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/UserStorage.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/UserStorage.cs new file mode 100644 index 0000000..dd87961 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/UserStorage.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicContracts.StoragesContracts; +using VeterinaryClinicContracts.ViewModels; +using VeterinaryClinicDatabaseImplement.Models; + +namespace VeterinaryClinicDatabaseImplement.Implements +{ + public class UserStorage : IUserStorage + { + public UserViewModel? Delete(UserBindingModel model) + { + using var context = new VeterinaryClinicDatabase(); + var user = context.Users + .FirstOrDefault(x => x.Id.Equals(model.Id)); + if (user == null) + { + return null; + } + + context.Users.Remove(user); + context.SaveChanges(); + return user.GetViewModel; + } + + public UserViewModel? GetElement(UserSearchModel model) + { + using var context = new VeterinaryClinicDatabase(); + + if (model.Id.HasValue) + { + return context.Users + .FirstOrDefault(x => x.Id.Equals(model.Id)) + ?.GetViewModel; + } + + if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password)) + { + return context.Users + .FirstOrDefault(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password)) + ?.GetViewModel; + } + + if (!string.IsNullOrEmpty(model.Phone)) + { + return context.Users + .FirstOrDefault(x => x.Phone.Equals(model.Phone)) + ?.GetViewModel; + } + + return null; + } + + public List GetFilteredList(UserSearchModel model) + { + using var context = new VeterinaryClinicDatabase(); + if (!string.IsNullOrEmpty(model.FullName)) + { + return context.Users + .Where(x => x.FullName.Contains(model.FullName)) + .Select(x => x.GetViewModel) + .ToList(); + } + + if (!string.IsNullOrEmpty(model.Email)) + { + return context.Users + .Where(x => x.Email.Contains(model.Email)) + .Select(x => x.GetViewModel) + .ToList(); + } + + return new(); + } + + public List GetFullList() + { + using var context = new VeterinaryClinicDatabase(); + return context.Users + .Select(x => x.GetViewModel) + .ToList(); + } + + public UserViewModel? Insert(UserBindingModel model) + { + using var context = new VeterinaryClinicDatabase(); + var newUser = User.Create(model); + if (newUser == null) + { + return null; + } + + context.Users.Add(newUser); + context.SaveChanges(); + return newUser.GetViewModel; + } + + public UserViewModel? Update(UserBindingModel model) + { + using var context = new VeterinaryClinicDatabase(); + var newUser = context.Users + .FirstOrDefault(x => x.Id.Equals(model.Id)); + if (newUser == null) + { + return null; + } + + newUser.Update(model); + context.SaveChanges(); + return newUser.GetViewModel; + } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/VaccinationStorage.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/VaccinationStorage.cs new file mode 100644 index 0000000..3c3017a --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/VaccinationStorage.cs @@ -0,0 +1,116 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicContracts.StoragesContracts; +using VeterinaryClinicContracts.ViewModels; +using VeterinaryClinicDatabaseImplement.Models; + +namespace VeterinaryClinicDatabaseImplement.Implements +{ + public class VaccinationStorage : IVaccinationStorage + { + public VaccinationViewModel? Delete(VaccinationBindingModel model) + { + using var context = new VeterinaryClinicDatabase(); + var vaccination = context.Vaccinations + .FirstOrDefault(x => x.Id == model.Id); + if (vaccination == null) + { + return null; + } + + context.Vaccinations.Remove(vaccination); + context.SaveChanges(); + return vaccination.GetViewModel; + } + + public VaccinationViewModel? GetElement(VaccinationSearchModel model) + { + using var context = new VeterinaryClinicDatabase(); + + if (model.Id.HasValue) + { + return context.Vaccinations + .Include(x => x.User) + .Include(x => x.Animal) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + + if (!string.IsNullOrEmpty(model.Name)) + { + return context.Vaccinations + .Include(x => x.User) + .Include(x => x.Animal) + .FirstOrDefault(x => x.Name.Equals(model.Name)) + ?.GetViewModel; + } + + return null; + } + + public List GetFilteredList(VaccinationSearchModel model) + { + using var database = new VeterinaryClinicDatabase(); + + if (!string.IsNullOrEmpty(model.Name)) + { + return database.Vaccinations + .Include(x => x.User) + .Include(x => x.Animal) + .Where(x => x.Name.Contains(model.Name)) + .Select(x => x.GetViewModel) + .ToList(); + } + + return new(); + } + + public List GetFullList() + { + using var database = new VeterinaryClinicDatabase(); + + return database.Vaccinations + .Include(x => x.User) + .Include(x => x.Animal) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public VaccinationViewModel? Insert(VaccinationBindingModel model) + { + using var context = new VeterinaryClinicDatabase(); + var newVaccination = Vaccination.Create(context, model); + + if (newVaccination == null) + { + return null; + } + + context.Vaccinations.Add(newVaccination); + context.SaveChanges(); + return newVaccination.GetViewModel; + } + + public VaccinationViewModel? Update(VaccinationBindingModel model) + { + using var context = new VeterinaryClinicDatabase(); + var vaccination = context.Vaccinations + .FirstOrDefault(x => x.Id == model.Id); + if (vaccination == null) + { + return null; + } + + vaccination.Update(model); + context.SaveChanges(); + return vaccination.GetViewModel; + } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/VisitStorage.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/VisitStorage.cs new file mode 100644 index 0000000..13565c7 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Implements/VisitStorage.cs @@ -0,0 +1,130 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.SearchModels; +using VeterinaryClinicContracts.StoragesContracts; +using VeterinaryClinicContracts.ViewModels; +using VeterinaryClinicDatabaseImplement.Models; + +namespace VeterinaryClinicDatabaseImplement.Implements +{ + public class VisitStorage : IVisitStorage + { + public List GetFullList() + { + using var context = new VeterinaryClinicDatabase(); + return context.Visits + .Include(x => x.User) + .Include(x => x.Animals) + .ThenInclude(x => x.Animal) + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(VisitSearchModel model) + { + using var context = new VeterinaryClinicDatabase(); + + if (model.DateFrom.HasValue && model.DateTo.HasValue) + { + return context.Visits + .Include(x => x.User) + .Include(x => x.Animals) + .ThenInclude(x => x.Animal) + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .Where(x => x.Date >= model.DateFrom && x.Date <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); + } + + return new(); + } + + public VisitViewModel? GetElement(VisitSearchModel model) + { + using var context = new VeterinaryClinicDatabase(); + + if (model.Id.HasValue) + { + return context.Visits + .Include(x => x.User) + .Include(x => x.Animals) + .ThenInclude(x => x.Animal) + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .FirstOrDefault(x => x.Id.Equals(model.Id)) + ?.GetViewModel; + } + + return null; + } + + public VisitViewModel? Insert(VisitBindingModel model) + { + using var context = new VeterinaryClinicDatabase(); + var newVisit = Visit.Create(context, model); + if (newVisit == null) + { + return null; + } + + context.Visits.Add(newVisit); + context.SaveChanges(); + return newVisit.GetViewModel; + } + + public VisitViewModel? Update(VisitBindingModel model) + { + using var context = new VeterinaryClinicDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var visit = context.Visits + .FirstOrDefault(x => x.Id == model.Id); + if (visit == null) + { + return null; + } + + visit.Update(model); + context.SaveChanges(); + visit.UpdateAnimals(context, model); + visit.UpdateMedication(context, model); + transaction.Commit(); + return visit.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + + public VisitViewModel? Delete(VisitBindingModel model) + { + using var context = new VeterinaryClinicDatabase(); + var visit = context.Visits + .Include(x => x.User) + .Include(x => x.Animals) + .ThenInclude(x => x.Animal) + .Include(x => x.Services) + .ThenInclude(x => x.Service) + .FirstOrDefault(x => x.Id == model.Id); + if (visit == null) + { + return null; + } + + context.Visits.Remove(visit); + context.SaveChanges(); + return visit.GetViewModel; + } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Animal.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Animal.cs new file mode 100644 index 0000000..76cae47 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Animal.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Numerics; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.ViewModels; +using VeterinaryClinicDataModels.Models; + +namespace VeterinaryClinicDatabaseImplement.Models +{ + public class Animal: IAnimalModel + { + public int Id { get; set; } + + [Required] + public string Type { get; set; } = string.Empty; + + [Required] + public string Breed { get; set; } = string.Empty; + + [Required] + public int Age { get; set; } + + [ForeignKey("UserId")] + public int UserId { get; set; } + + public virtual User User { get; set; } = new(); + + [ForeignKey("AnimalId")] + public virtual List Medications { get; set; } = new(); + + private Dictionary? _animalMedications { get; set; } = new(); + + [NotMapped] + public Dictionary AnimalMedications { get + { + if(_animalMedications == null) + _animalMedications = Medications.ToDictionary(recAM => recAM.MedicationId, recAM => (recAM.Medication as IMedicationModel)); + + return _animalMedications; + } + } + + public static Animal? Create(VeterinaryClinicDatabase context, AnimalBindingModel model) + { + if (model == null) + { + return null; + } + + return new Animal() + { + Id = model.Id, + Type = model.Type, + Breed = model.Breed, + Age = model.Age, + UserId = model.UserId, + User = context.Users + .First(x => x.Id == model.UserId), + Medications = model.AnimalMedications.Select(x => new AnimalMedication + { + Medication = context.Medications.First(y => y.Id == x.Key) + }).ToList() + }; + } + + public void Update(AnimalBindingModel model) + { + if (model == null) + { + return; + } + + Type = model.Type; + Breed = model.Breed; + Age = model.Age; + } + + public AnimalViewModel GetViewModel => new() + { + Id = Id, + Type = Type, + Breed = Breed, + Age = Age, + UserId = UserId, + UserFullName = User.FullName, + AnimalMedications = AnimalMedications + }; + + public void UpdateMedications(VeterinaryClinicDatabase context, AnimalBindingModel model) + { + var animalMedications = context.AnimalMedications.Where(rec => rec.AnimalId == model.Id).ToList(); + if (animalMedications != null && animalMedications.Count > 0) + { + context.AnimalMedications.RemoveRange(animalMedications.Where(rec => !model.AnimalMedications.ContainsKey(rec.MedicationId))); + context.SaveChanges(); + } + + var animal = context.Animals.First(x => x.Id == Id); + foreach (var pr in model.AnimalMedications) + { + context.AnimalMedications.Add(new AnimalMedication + { + Animal = animal, + Medication = context.Medications.First(x => x.Id == pr.Key) + }); + context.SaveChanges(); + } + _animalMedications = null; + } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/AnimalMedication.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/AnimalMedication.cs new file mode 100644 index 0000000..624cbf4 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/AnimalMedication.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VeterinaryClinicDatabaseImplement.Models +{ + public class AnimalMedication + { + public int Id { get; set; } + + [Required] + public int AnimalId { get; set; } + + [Required] + public int MedicationId { get; set; } + + public virtual Animal Animal { get; set; } = new(); + + public virtual Medication Medication { get; set; } = new(); + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Medication.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Medication.cs new file mode 100644 index 0000000..ea6a551 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Medication.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.ViewModels; +using VeterinaryClinicDataModels.Models; + +namespace VeterinaryClinicDatabaseImplement.Models +{ + public class Medication: IMedicationModel + { + public int Id { get; set; } + + [Required] + public string Name { get; set; } = string.Empty; + + public string Description { get; set; } = string.Empty; + + public static Medication? Create(MedicationBindingModel model) + { + if (model == null) + { + return null; + } + + return new Medication() + { + Id = model.Id, + Name = model.Name, + Description = model.Description + }; + } + + public void Update(MedicationBindingModel model) + { + if (model == null) + { + return; + } + + Name = model.Name; + Description = model.Description; + } + + public MedicationViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Description = Description + }; + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Service.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Service.cs new file mode 100644 index 0000000..e03e2d4 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Service.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicDataModels.Models; +using System.Numerics; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.ViewModels; + +namespace VeterinaryClinicDatabaseImplement.Models +{ + public class Service: IServiceModel + { + public int Id { get; set; } + + [Required] + public string Name { get; set; } = string.Empty; + + [Required] + public int Cost { get; set; } + + [ForeignKey("MedicationId")] + public int MedicationId { get; set; } + + public virtual Medication Medication { get; set; } = new(); + + public static Service? Create(VeterinaryClinicDatabase context, ServiceBindingModel model) + { + if (model == null) + { + return null; + } + + return new Service() + { + Id = model.Id, + Name = model.Name, + Cost = model.Cost, + MedicationId = model.MedicationId, + Medication = context.Medications + .First(x => x.Id == model.MedicationId), + }; + } + + public void Update(ServiceBindingModel model) + { + if (model == null) + { + return; + } + + Name = model.Name; + Cost = model.Cost; + } + + public ServiceViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Cost = Cost, + MedicationId = MedicationId, + MedicationName = Medication.Name + }; + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/User.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/User.cs new file mode 100644 index 0000000..72c465b --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/User.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Numerics; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.ViewModels; +using VeterinaryClinicDataModels.Enums; +using VeterinaryClinicDataModels.Models; + +namespace VeterinaryClinicDatabaseImplement.Models +{ + public class User: IUserModel + { + public int Id { get; set; } + + [Required] + public string FullName { get; set; } = string.Empty; + + [Required] + public string Phone { get; set; } = string.Empty; + + [Required] + public string Email { get; set; } = string.Empty; + + [Required] + public string Password { get; set; } = string.Empty; + + [Required] + public UserRole Role { get; set; } + + public static User? Create(UserBindingModel model) + { + if (model == null) + { + return null; + } + + return new User() + { + Id = model.Id, + FullName = model.FullName, + Phone = model.Phone, + Email = model.Email, + Password = model.Password, + Role = model.Role + }; + } + + public void Update(UserBindingModel model) + { + if (model == null) + { + return; + } + + FullName = model.FullName; + Phone = model.Phone; + Email = model.Email; + Password = model.Password; + Role = model.Role; + } + + public UserViewModel GetViewModel => new() + { + Id = Id, + FullName = FullName, + Phone = Phone, + Email = Email, + Password = Password, + Role = Role + }; + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Vaccination.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Vaccination.cs new file mode 100644 index 0000000..fe12042 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Vaccination.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Numerics; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.ViewModels; +using VeterinaryClinicDataModels.Models; + +namespace VeterinaryClinicDatabaseImplement.Models +{ + public class Vaccination: IVaccinationModel + { + public int Id { get; set; } + + [Required] + public string Name { get; set; } = string.Empty; + + [Required] + public DateTime DateInjection { get; set; } = DateTime.Now; + + [Required] + public string ValidityPeriod { get; set; } = string.Empty; + + [ForeignKey("UserId")] + public int UserId { get; set; } + + public virtual User User { get; set; } = new(); + + [ForeignKey("AnimalId")] + public int AnimalId { get; set; } + + public virtual Animal Animal { get; set; } = new(); + + public static Vaccination? Create(VeterinaryClinicDatabase context, VaccinationBindingModel model) + { + if (model == null) + { + return null; + } + + return new Vaccination() + { + Id = model.Id, + Name = model.Name, + DateInjection = model.DateInjection, + UserId = model.UserId, + User = context.Users + .First(x => x.Id == model.UserId), + AnimalId = model.AnimalId, + Animal = context.Animals + .First(x => x.Id == model.AnimalId) + }; + } + + public void Update(VaccinationBindingModel model) + { + if (model == null) + { + return; + } + + Name = model.Name; + DateInjection = model.DateInjection; + } + + public VaccinationViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + DateInjection = DateInjection, + UserId = UserId, + UserFullName = User.FullName, + AnimalId = Animal.Id, + AnimalBreed = Animal.Breed + }; + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Visit.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Visit.cs new file mode 100644 index 0000000..d58c839 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/Visit.cs @@ -0,0 +1,149 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VeterinaryClinicContracts.BindingModels; +using VeterinaryClinicContracts.ViewModels; +using VeterinaryClinicDataModels.Models; + +namespace VeterinaryClinicDatabaseImplement.Models +{ + public class Visit: IVisitModel + { + public int Id { get; set; } + + [Required] + public DateTime Date { get; set; } = DateTime.Now; + + [ForeignKey("UserId")] + public int UserId { get; set; } + + public virtual User User { get; set; } = new(); + + [ForeignKey("AnimalId")] + public virtual List Animals { get; set; } = new(); + + private Dictionary? _visitAnimals = null; + + public Dictionary VisitAnimals { + get + { + if (_visitAnimals == null) + { + _visitAnimals = Animals + .ToDictionary(recVA => recVA.AnimalId, recVA => (recVA.Animal as IAnimalModel)); + } + return _visitAnimals; + } + } + + [ForeignKey("ServiceId")] + public virtual List Services { get; set; } = new(); + + private Dictionary? _visitServices = null; + + public Dictionary VisitServices { + get + { + if (_visitServices == null) + { + _visitServices = Services + .ToDictionary(recVS => recVS.ServiceId, recVS => (recVS.Service as IServiceModel)); + } + return _visitServices; + } + } + + public static Visit? Create(VeterinaryClinicDatabase context, VisitBindingModel model) + { + if (model == null) + { + return null; + } + + return new Visit() + { + Id = model.Id, + Date = model.Date, + UserId = model.UserId, + User = context.Users + .First(x => x.Id == model.UserId), + Animals = model.VisitAnimals.Select(x => new VisitAnimal + { + Animal = context.Animals.First(y => y.Id == x.Key) + }).ToList(), + Services = model.VisitServices.Select(x => new VisitService + { + Service = context.Services.First(y => y.Id == x.Key) + }).ToList() + }; + } + + public void Update(VisitBindingModel model) + { + if (model == null) + { + return; + } + + Date = model.Date; + } + + public VisitViewModel GetViewModel => new() + { + Id = Id, + Date = Date, + UserId = UserId, + UserFullName = User.FullName, + VisitAnimals = VisitAnimals, + VisitServices = VisitServices + }; + + public void UpdateAnimals(VeterinaryClinicDatabase context, VisitBindingModel model) + { + var visitAnimals = context.VisitAnimals.Where(rec => rec.VisitId == model.Id).ToList(); + if (visitAnimals != null && visitAnimals.Count > 0) + { + context.VisitAnimals.RemoveRange(visitAnimals.Where(rec => !model.VisitAnimals.ContainsKey(rec.AnimalId))); + context.SaveChanges(); + } + + var visit = context.Visits.First(x => x.Id == Id); + foreach (var rm in model.VisitAnimals) + { + context.VisitAnimals.Add(new VisitAnimal + { + Visit = visit, + Animal = context.Animals.First(x => x.Id == rm.Key) + }); + context.SaveChanges(); + } + _visitAnimals = null; + } + + public void UpdateMedication(VeterinaryClinicDatabase context, VisitBindingModel model) + { + var visitServices = context.VisitServices.Where(rec => rec.VisitId == model.Id).ToList(); + if (visitServices != null && visitServices.Count > 0) + { + context.VisitServices.RemoveRange(visitServices.Where(rec => !model.VisitServices.ContainsKey(rec.ServiceId))); + context.SaveChanges(); + } + + var visit = context.Visits.First(x => x.Id == Id); + foreach (var rm in model.VisitServices) + { + context.VisitServices.Add(new VisitService + { + Visit = visit, + Service = context.Services.First(x => x.Id == rm.Key) + }); + context.SaveChanges(); + } + _visitServices = null; + } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/VisitAnimal.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/VisitAnimal.cs new file mode 100644 index 0000000..7434f02 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/VisitAnimal.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VeterinaryClinicDatabaseImplement.Models +{ + public class VisitAnimal + { + public int Id { get; set; } + + [Required] + public int VisitId { get; set; } + + [Required] + public int AnimalId { get; set; } + + public virtual Visit Visit { get; set; } = new(); + + public virtual Animal Animal { get; set; } = new(); + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/VisitService.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/VisitService.cs new file mode 100644 index 0000000..4e6de9d --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/Models/VisitService.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VeterinaryClinicDatabaseImplement.Models +{ + public class VisitService + { + public int Id { get; set; } + + [Required] + public int VisitId { get; set; } + + [Required] + public int ServiceId { get; set; } + + public virtual Visit Visit { get; set; } = new(); + + public virtual Service Service { get; set; } = new(); + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/VeterinaryClinicDatabase.cs b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/VeterinaryClinicDatabase.cs new file mode 100644 index 0000000..ea1af55 --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/VeterinaryClinicDatabase.cs @@ -0,0 +1,32 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Options; +using VeterinaryClinicDatabaseImplement.Models; + +namespace VeterinaryClinicDatabaseImplement +{ + public class VeterinaryClinicDatabase: DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=VeterinaryClinicDatabase;Username=postgres;Password=postgres"); + } + + base.OnConfiguring(optionsBuilder); + + AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); + AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true); + } + + public virtual DbSet Animals { set; get; } + public virtual DbSet AnimalMedications { set; get; } + public virtual DbSet Medications { set; get; } + public virtual DbSet Services { set; get; } + public virtual DbSet Users { set; get; } + public virtual DbSet Vaccinations { set; get; } + public virtual DbSet Visits { set; get; } + public virtual DbSet VisitAnimals { set; get; } + public virtual DbSet VisitServices { set; get; } + } +} diff --git a/VeterinaryClinic/VeterinaryClinicDatabaseImplement/VeterinaryClinicDatabaseImplement.csproj b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/VeterinaryClinicDatabaseImplement.csproj new file mode 100644 index 0000000..3c8f6fb --- /dev/null +++ b/VeterinaryClinic/VeterinaryClinicDatabaseImplement/VeterinaryClinicDatabaseImplement.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + +