Исполнитель: сделал модели хранилища
This commit is contained in:
parent
bbe1f57823
commit
5491e8378a
@ -68,6 +68,10 @@ namespace VeterinaryBusinessLogic.BusinessLogic
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.Sum <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum));
|
||||
}
|
||||
if (model.DatePurchase <= DateTime.Now)
|
||||
{
|
||||
throw new ArgumentNullException("Дата покупки не должна быть в прошлом", nameof(model.DatePurchase));
|
||||
|
@ -8,6 +8,7 @@ namespace VeterinaryContracts.BindingModels
|
||||
public int OwnerId { get; set; }
|
||||
public int DrugId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public DateTime DatePurchase { get; set; }
|
||||
public Dictionary<int, (IPetModel, int)> PurchasePet { get; set; } = new();
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ namespace VeterinaryContracts.ViewModels
|
||||
public int DrugId { get; set; }
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; set; }
|
||||
[DisplayName("Сумма")]
|
||||
public double Sum { get; set; }
|
||||
[DisplayName("Дата покупки")]
|
||||
public DateTime DatePurchase { get; set; }
|
||||
public Dictionary<int, (IPetModel, int)> PurchasePet { get; set; } = new();
|
||||
|
@ -5,7 +5,8 @@
|
||||
int OwnerId { get; }
|
||||
int DrugId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
DateTime DatePurchase { get; }
|
||||
Dictionary<int, (IPetModel, int)> PurchasePet { get; }
|
||||
Dictionary<int, IPetModel> PurchasePet { get; }
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,6 @@
|
||||
int OwnerId { get; }
|
||||
int? DoctorId { get; }
|
||||
DateTime DateVisit { get; }
|
||||
Dictionary<int, (IPetModel, int)> VisitPet { get; }
|
||||
Dictionary<int, IPetModel> VisitPet { get; }
|
||||
}
|
||||
}
|
||||
|
64
VeterinaryView/VeterinaryDatabaseImplement/Models/Owner.cs
Normal file
64
VeterinaryView/VeterinaryDatabaseImplement/Models/Owner.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
|
||||
namespace VeterinaryDatabaseImplement.Models
|
||||
{
|
||||
public class Owner : IOwnerModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string OwnerFIO { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Login { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
[ForeignKey("OwnerId")]
|
||||
public virtual List<Pet> Pets { get; set; } = new();
|
||||
public virtual List<Visit> Visits { get; set; } = new();
|
||||
public virtual List<Purchase> Purchases { get; set; } = new();
|
||||
public static Owner? Create(OwnerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Owner()
|
||||
{
|
||||
Id = model.Id,
|
||||
OwnerFIO = model.OwnerFIO,
|
||||
Login = model.Login,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
public static Owner Create(OwnerViewModel model)
|
||||
{
|
||||
return new Owner()
|
||||
{
|
||||
Id = model.Id,
|
||||
OwnerFIO = model.OwnerFIO,
|
||||
Login = model.Login,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
public void Update(OwnerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
OwnerFIO = model.OwnerFIO;
|
||||
Login = model.Login;
|
||||
Password = model.Password;
|
||||
}
|
||||
public OwnerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
OwnerFIO = OwnerFIO,
|
||||
Login = Login,
|
||||
Password = Password
|
||||
};
|
||||
}
|
||||
}
|
70
VeterinaryView/VeterinaryDatabaseImplement/Models/Pet.cs
Normal file
70
VeterinaryView/VeterinaryDatabaseImplement/Models/Pet.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
|
||||
namespace VeterinaryDatabaseImplement.Models
|
||||
{
|
||||
public class Pet : IPetModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public int OwnerId { get; private set; }
|
||||
[Required]
|
||||
public string PetName { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string PetType { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string PetBreed { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string PetGender { get; private set; } = string.Empty;
|
||||
[ForeignKey("PetId")]
|
||||
public virtual List<VisitPet> VisitPets { get; set; } = new();
|
||||
public static Pet? Create(PetBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Pet()
|
||||
{
|
||||
Id = model.Id,
|
||||
PetName = model.PetName,
|
||||
PetType = model.PetType,
|
||||
PetBreed = model.PetBreed,
|
||||
PetGender = model.PetGender
|
||||
};
|
||||
}
|
||||
public static Pet Create(PetViewModel model)
|
||||
{
|
||||
return new Pet
|
||||
{
|
||||
Id = model.Id,
|
||||
PetName = model.PetName,
|
||||
PetType = model.PetType,
|
||||
PetBreed = model.PetBreed,
|
||||
PetGender = model.PetGender
|
||||
};
|
||||
}
|
||||
public void Update(PetBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PetName = model.PetName;
|
||||
PetType = model.PetType;
|
||||
PetBreed = model.PetBreed;
|
||||
PetGender = model.PetGender;
|
||||
}
|
||||
public PetViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
PetName = PetName,
|
||||
PetType = PetType,
|
||||
PetBreed = PetBreed,
|
||||
PetGender = PetGender
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryDataModels;
|
||||
|
||||
namespace VeterinaryDatabaseImplement.Models
|
||||
{
|
||||
public class Purchase : IPurchaseModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public int OwnerId { get; private set; }
|
||||
[Required]
|
||||
public int DrugId { get; private set; }
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
[Required]
|
||||
public double Sum { get; private set; }
|
||||
[Required]
|
||||
public DateTime DatePurchase { get; private set; }
|
||||
private Dictionary<int, IPetModel>? _purchasePet = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IPetModel> PurchasePet
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_purchasePet == null)
|
||||
{
|
||||
_purchasePet = Pets
|
||||
.ToDictionary(recPC => recPC.PetId, recPC =>
|
||||
(recPC.Pet as IPetModel));
|
||||
}
|
||||
return _purchasePet;
|
||||
}
|
||||
}
|
||||
[ForeignKey("PurchaseId")]
|
||||
public virtual List<PurchasePet> Pets { get; set; } = new();
|
||||
[ForeignKey("PurchaseId")]
|
||||
public virtual List<Drug> Drugs { get; set; } = new();
|
||||
public static Purchase? Create(VeterenaryDatabase context, PurchaseBindingModel model)
|
||||
{
|
||||
return new Purchase()
|
||||
{
|
||||
Id = model.Id,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
OwnerId = model.OwnerId,
|
||||
DrugId = model.DrugId,
|
||||
DatePurchase = model.DatePurchase
|
||||
Pets = model.PurchasePet.Select(x => new PurchasePet
|
||||
{
|
||||
Pet = context.Pets.First(y => y.Id == x.Key),
|
||||
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public PurchaseViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
OwnerId = OwnerId,
|
||||
DrugId = DrugId,
|
||||
DatePurchase = DatePurchase
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace VeterinaryDatabaseImplement.Models
|
||||
{
|
||||
public class PurchasePet
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int PurchaseId { get; set; }
|
||||
[Required]
|
||||
public int PetId { get; set; }
|
||||
public virtual Purchase Purchase { get; set; } = new();
|
||||
public virtual Pet Pet { get; set; } = new();
|
||||
}
|
||||
}
|
58
VeterinaryView/VeterinaryDatabaseImplement/Models/Visit.cs
Normal file
58
VeterinaryView/VeterinaryDatabaseImplement/Models/Visit.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryDataModels;
|
||||
|
||||
namespace VeterinaryDatabaseImplement.Models
|
||||
{
|
||||
public class Visit : IVisitModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public int OwnerId { get; private set; }
|
||||
[Required]
|
||||
public int? DoctorId { get; private set; }
|
||||
[Required]
|
||||
public DateTime DateVisit { get; private set; }
|
||||
private Dictionary<int, IPetModel>? _visitPet = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IPetModel> VisitPet
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_visitPet == null)
|
||||
{
|
||||
_visitPet = Pets
|
||||
.ToDictionary(recPC => recPC.PetId, recPC =>
|
||||
(recPC.Pet as IPetModel));
|
||||
}
|
||||
return _visitPet;
|
||||
}
|
||||
}
|
||||
[ForeignKey("VisitId")]
|
||||
public virtual List<VisitPet> Pets { get; set; } = new();
|
||||
public static Visit? Create(VisitVeterenaryDatabase context, VisitBindingModel model)
|
||||
{
|
||||
return new Visit()
|
||||
{
|
||||
Id = model.Id,
|
||||
OwnerId = model.OwnerId,
|
||||
DoctorId = model.DoctorId,
|
||||
DateVisit = model.DateVisit,
|
||||
Pets = model.VisitPet.Select(x => new VisitPet
|
||||
{
|
||||
Pet = context.Pets.First(y => y.Id == x.Key),
|
||||
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public VisitViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
OwnerId = OwnerId,
|
||||
DoctorId = DoctorId,
|
||||
DateVisit = DateVisit
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace VeterinaryDatabaseImplement.Models
|
||||
{
|
||||
public class VisitPet
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int VisitId { get; set; }
|
||||
[Required]
|
||||
public int PetId { get; set; }
|
||||
public virtual Visit Visit { get; set; } = new();
|
||||
public virtual Pet Pet { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using VeterinaryDatabaseImplement.Models;
|
||||
|
||||
namespace VeterinaryDatabaseImplement
|
||||
{
|
||||
public class VeterenaryDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=VeterenaryDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"
|
||||
);
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
public virtual DbSet<Doctor> Doctors { set; get; }
|
||||
public virtual DbSet<Drug> Drugs { set; get; }
|
||||
public virtual DbSet<Medication> Medication { set; get; }
|
||||
public virtual DbSet<Service> Services { set; get; }
|
||||
public virtual DbSet<ServiceMedication> ServiceMedicationes { set; get; }
|
||||
public virtual DbSet<DrugMedication> DrugMedicationes{ set; get; }
|
||||
public virtual DbSet<Owner> Owners { set; get; }
|
||||
public virtual DbSet<Pet> Pets { set; get; }
|
||||
public virtual DbSet<Visit> Visits { set; get; }
|
||||
public virtual DbSet<Purchase> Purchases { set; get; }
|
||||
public virtual DbSet<VisitPet> VisitPets { set; get; }
|
||||
public virtual DbSet<PurchasePet> PurchasePets { set; get; }
|
||||
}
|
||||
}
|
@ -12,8 +12,16 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\" />
|
||||
<Folder Include="Implements\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.16" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.16" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.16">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Loading…
Reference in New Issue
Block a user