Время так скоротечно
This commit is contained in:
parent
9e6e84b6b9
commit
f6a10e629a
@ -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
|
||||
|
@ -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<int, IMedicationModel> AnimalMedications { get; set; } = new();
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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<int, IAnimalModel> VisitAnimals { get; set; } = new();
|
||||
|
||||
public Dictionary<int, IServiceModel> VisitServices { get; set; } = new();
|
||||
}
|
||||
}
|
@ -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<AnimalViewModel>? ReadList(AnimalSearchModel? model);
|
||||
|
||||
AnimalViewModel? ReadElement(AnimalSearchModel model);
|
||||
|
||||
bool Create(AnimalBindingModel model);
|
||||
|
||||
bool Update(AnimalBindingModel model);
|
||||
|
||||
bool Delete(AnimalBindingModel model);
|
||||
}
|
||||
}
|
@ -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<MedicationViewModel>? ReadList(MedicationSearchModel? model);
|
||||
|
||||
MedicationViewModel? ReadElement(MedicationSearchModel model);
|
||||
|
||||
bool Create(MedicationBindingModel model);
|
||||
|
||||
bool Update(MedicationBindingModel model);
|
||||
|
||||
bool Delete(MedicationBindingModel model);
|
||||
}
|
||||
}
|
@ -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<ServiceViewModel>? ReadList(ServiceSearchModel? model);
|
||||
|
||||
ServiceViewModel? ReadElement(ServiceSearchModel model);
|
||||
|
||||
bool Create(ServiceBindingModel model);
|
||||
|
||||
bool Update(ServiceBindingModel model);
|
||||
|
||||
bool Delete(ServiceBindingModel model);
|
||||
}
|
||||
}
|
@ -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<UserViewModel>? ReadList(UserSearchModel? model);
|
||||
|
||||
UserViewModel? ReadElement(UserSearchModel model);
|
||||
|
||||
bool Create(UserBindingModel model);
|
||||
|
||||
bool Update(UserBindingModel model);
|
||||
|
||||
bool Delete(UserBindingModel model);
|
||||
}
|
||||
}
|
@ -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<VaccinationViewModel>? ReadList(VaccinationSearchModel? model);
|
||||
|
||||
VaccinationViewModel? ReadElement(VaccinationSearchModel model);
|
||||
|
||||
bool Create(VaccinationBindingModel model);
|
||||
|
||||
bool Update(VaccinationBindingModel model);
|
||||
|
||||
bool Delete(VaccinationBindingModel model);
|
||||
}
|
||||
}
|
@ -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<VisitViewModel>? ReadList(VisitSearchModel? model);
|
||||
|
||||
VisitViewModel? ReadElement(VisitSearchModel model);
|
||||
|
||||
bool Create(VisitBindingModel model);
|
||||
|
||||
bool Update(VisitBindingModel model);
|
||||
|
||||
bool Delete(VaccinationBindingModel model);
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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<AnimalViewModel> GetFullList();
|
||||
|
||||
List<AnimalViewModel> GetFilteredList(AnimalSearchModel model);
|
||||
|
||||
AnimalViewModel? GetElement(AnimalSearchModel model);
|
||||
|
||||
AnimalViewModel? Insert(AnimalBindingModel model);
|
||||
|
||||
AnimalViewModel? Update(AnimalBindingModel model);
|
||||
|
||||
AnimalViewModel? Delete(AnimalBindingModel model);
|
||||
}
|
||||
}
|
@ -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<MedicationViewModel> GetFullList();
|
||||
|
||||
List<MedicationViewModel> GetFilteredList(MedicationSearchModel model);
|
||||
|
||||
MedicationViewModel? GetElement(MedicationSearchModel model);
|
||||
|
||||
MedicationViewModel? Insert(MedicationBindingModel model);
|
||||
|
||||
MedicationViewModel? Update(MedicationBindingModel model);
|
||||
|
||||
MedicationViewModel? Delete(MedicationBindingModel model);
|
||||
}
|
||||
}
|
@ -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<ServiceViewModel> GetFullList();
|
||||
|
||||
List<ServiceViewModel> GetFilteredList(ServiceSearchModel model);
|
||||
|
||||
ServiceViewModel? GetElement(ServiceSearchModel model);
|
||||
|
||||
ServiceViewModel? Insert(ServiceBindingModel model);
|
||||
|
||||
ServiceViewModel? Update(ServiceBindingModel model);
|
||||
|
||||
ServiceViewModel? Delete(ServiceBindingModel model);
|
||||
}
|
||||
}
|
@ -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<UserViewModel> GetFullList();
|
||||
|
||||
List<UserViewModel> GetFilteredList(UserSearchModel model);
|
||||
|
||||
UserViewModel? GetElement(UserSearchModel model);
|
||||
|
||||
UserViewModel? Insert(UserBindingModel model);
|
||||
|
||||
UserViewModel? Update(UserBindingModel model);
|
||||
|
||||
UserViewModel? Delete(UserBindingModel model);
|
||||
}
|
||||
}
|
@ -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<VaccinationViewModel> GetFullList();
|
||||
|
||||
List<VaccinationViewModel> GetFilteredList(VaccinationSearchModel model);
|
||||
|
||||
VaccinationViewModel? GetElement(VaccinationSearchModel model);
|
||||
|
||||
VaccinationViewModel? Insert(VaccinationBindingModel model);
|
||||
|
||||
VaccinationViewModel? Update(VaccinationBindingModel model);
|
||||
|
||||
VaccinationViewModel? Delete(VaccinationBindingModel model);
|
||||
}
|
||||
}
|
@ -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<VisitViewModel> GetFullList();
|
||||
|
||||
List<VisitViewModel> GetFilteredList(VisitSearchModel model);
|
||||
|
||||
VisitViewModel? GetElement(VisitSearchModel model);
|
||||
|
||||
VisitViewModel? Insert(VisitBindingModel model);
|
||||
|
||||
VisitViewModel? Update(VisitBindingModel model);
|
||||
|
||||
VisitViewModel? Delete(VisitBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VeterinaryClinicDataModels\VeterinaryClinicDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -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<int, IMedicationModel> AnimalMedications { get; set; } = new();
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<int, IAnimalModel> VisitAnimals { get; set; } = new();
|
||||
|
||||
public Dictionary<int, IServiceModel> VisitServices { get; set; } = new();
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
7
VeterinaryClinic/VeterinaryClinicDataModels/IId.cs
Normal file
7
VeterinaryClinic/VeterinaryClinicDataModels/IId.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace VeterinaryClinicDataModels
|
||||
{
|
||||
public interface IId
|
||||
{
|
||||
int Id { get; }
|
||||
}
|
||||
}
|
@ -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<int, IMedicationModel> AnimalMedications { get; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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<int, IAnimalModel> VisitAnimals { get; }
|
||||
|
||||
Dictionary<int, IServiceModel> VisitServices { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
@ -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<AnimalViewModel> 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<AnimalViewModel> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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<MedicationViewModel> 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<MedicationViewModel> 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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<ServiceViewModel> 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<ServiceViewModel> 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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<UserViewModel> 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<UserViewModel> 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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<VaccinationViewModel> 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<VaccinationViewModel> 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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<VisitViewModel> 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<VisitViewModel> 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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<AnimalMedication> Medications { get; set; } = new();
|
||||
|
||||
private Dictionary<int, IMedicationModel>? _animalMedications { get; set; } = new();
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, IMedicationModel> 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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
|
||||
};
|
||||
}
|
||||
}
|
@ -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
|
||||
};
|
||||
}
|
||||
}
|
@ -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
|
||||
};
|
||||
}
|
||||
}
|
@ -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
|
||||
};
|
||||
}
|
||||
}
|
@ -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<VisitAnimal> Animals { get; set; } = new();
|
||||
|
||||
private Dictionary<int, IAnimalModel>? _visitAnimals = null;
|
||||
|
||||
public Dictionary<int, IAnimalModel> VisitAnimals {
|
||||
get
|
||||
{
|
||||
if (_visitAnimals == null)
|
||||
{
|
||||
_visitAnimals = Animals
|
||||
.ToDictionary(recVA => recVA.AnimalId, recVA => (recVA.Animal as IAnimalModel));
|
||||
}
|
||||
return _visitAnimals;
|
||||
}
|
||||
}
|
||||
|
||||
[ForeignKey("ServiceId")]
|
||||
public virtual List<VisitService> Services { get; set; } = new();
|
||||
|
||||
private Dictionary<int, IServiceModel>? _visitServices = null;
|
||||
|
||||
public Dictionary<int, IServiceModel> 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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<Animal> Animals { set; get; }
|
||||
public virtual DbSet<AnimalMedication> AnimalMedications { set; get; }
|
||||
public virtual DbSet<Medication> Medications { set; get; }
|
||||
public virtual DbSet<Service> Services { set; get; }
|
||||
public virtual DbSet<User> Users { set; get; }
|
||||
public virtual DbSet<Vaccination> Vaccinations { set; get; }
|
||||
public virtual DbSet<Visit> Visits { set; get; }
|
||||
public virtual DbSet<VisitAnimal> VisitAnimals { set; get; }
|
||||
public virtual DbSet<VisitService> VisitServices { set; get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VeterinaryClinicContracts\VeterinaryClinicContracts.csproj" />
|
||||
<ProjectReference Include="..\VeterinaryClinicDataModels\VeterinaryClinicDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user