Сделал модели (все равно придется допиливать)
This commit is contained in:
parent
445b9e3220
commit
17d4058b9b
58
VetClinic/DinerDataBaseImplement/Models/Guidance.cs
Normal file
58
VetClinic/DinerDataBaseImplement/Models/Guidance.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VetClinicContracts.BindingModels;
|
||||
using VetClinicContracts.ViewModels;
|
||||
using VetClinicDataModels.Models;
|
||||
|
||||
namespace VetClinicDataBaseImplement.Models
|
||||
{
|
||||
public class Guidance : IGuidanceModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public int ServiceId { get; private set; }
|
||||
public virtual Service Service { get; private set; }
|
||||
[Required]
|
||||
public string Text { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public DateTime Date { get; private set; }
|
||||
public static Guidance? Create(VetClinicDatabase context, GuidanceBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Guidance()
|
||||
{
|
||||
Id = model.Id,
|
||||
ServiceId = model.ServiceId,
|
||||
Text = model.Text,
|
||||
Date = model.Date,
|
||||
Service = context.Services.FirstOrDefault(x => x.Id == model.ServiceId),
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(GuidanceBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Text = model.Text;
|
||||
Date = model.Date;
|
||||
}
|
||||
|
||||
public GuidanceViewModel GetViewModel => new()
|
||||
{
|
||||
ServiceId = ServiceId,
|
||||
Text = Text,
|
||||
Date = Date,
|
||||
Id = Id,
|
||||
ServiceName = Service.ServiceName
|
||||
};
|
||||
}
|
||||
}
|
98
VetClinic/DinerDataBaseImplement/Models/Medicine.cs
Normal file
98
VetClinic/DinerDataBaseImplement/Models/Medicine.cs
Normal file
@ -0,0 +1,98 @@
|
||||
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 VetClinicDataModels.Models;
|
||||
using VetClinicContracts.BindingModels;
|
||||
using VetClinicContracts.ViewModels;
|
||||
|
||||
namespace VetClinicDataBaseImplement.Models
|
||||
{
|
||||
public class Medicine : IMedicineModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string MedicineName { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public int PharmacistId { get; set; }
|
||||
public virtual Pharmacist Pharmacist { get; private set; }
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
private Dictionary<int, IAnimalModel>? _medicineAnimals =
|
||||
null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IAnimalModel> MedicineAnimals
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_medicineAnimals == null)
|
||||
{
|
||||
_medicineAnimals = Animals
|
||||
.ToDictionary(recPC => recPC.AnimalId, recPC =>
|
||||
recPC.Animal as IAnimalModel);
|
||||
}
|
||||
return _medicineAnimals;
|
||||
}
|
||||
}
|
||||
[ForeignKey("MedicineId")]
|
||||
public virtual List<MedicineAnimal> Animals { get; set; } = new();
|
||||
[ForeignKey("MedicineId")]
|
||||
public virtual List<ServiceMedicine> Services { get; set; } = new();
|
||||
public static Medicine Create(VetClinicDatabase context,
|
||||
MedicineBindingModel model)
|
||||
{
|
||||
return new Medicine()
|
||||
{
|
||||
Id = model.Id,
|
||||
MedicineName = model.MedicineName,
|
||||
Price = model.Price,
|
||||
Animals = model.MedicineAnimals.Select(x => new
|
||||
MedicineAnimal
|
||||
{
|
||||
Animal = context.Animals.First(y => y.Id == x.Key),
|
||||
}).ToList(),
|
||||
Pharmacist = context.Pharmacists.First(x => x.Id == model.PharmacistId)
|
||||
};
|
||||
}
|
||||
public void Update(MedicineBindingModel model)
|
||||
{
|
||||
MedicineName = model.MedicineName;
|
||||
Price = model.Price;
|
||||
}
|
||||
public MedicineViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
MedicineName = MedicineName,
|
||||
Price = Price,
|
||||
MedicineAnimals = MedicineAnimals,
|
||||
PharmacistFIO = Pharmacist.PharmacistFIO
|
||||
};
|
||||
public void UpdateComponents(VetClinicDatabase context,
|
||||
MedicineBindingModel model)
|
||||
{
|
||||
var medicineAnimals = context.MedicineAnimals.Where(rec =>
|
||||
rec.MedicineId == model.Id).ToList();
|
||||
if (medicineAnimals != null && medicineAnimals.Count > 0)
|
||||
{
|
||||
context.MedicineAnimals.RemoveRange(medicineAnimals.Where(rec
|
||||
=> !model.MedicineAnimals.ContainsKey(rec.AnimalId)));
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
var medicine = context.Medicines.First(x => x.Id == Id);
|
||||
foreach (var pc in model.MedicineAnimals)
|
||||
{
|
||||
context.MedicineAnimals.Add(new MedicineAnimal
|
||||
{
|
||||
Medicine = medicine,
|
||||
Animal = context.Animals.First(x => x.Id == pc.Key),
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_medicineAnimals = null;
|
||||
}
|
||||
}
|
||||
}
|
21
VetClinic/DinerDataBaseImplement/Models/MedicineAnimal.cs
Normal file
21
VetClinic/DinerDataBaseImplement/Models/MedicineAnimal.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VetClinicDataBaseImplement.Models
|
||||
{
|
||||
public class MedicineAnimal
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int MedicineId { get; set; }
|
||||
[Required]
|
||||
public int AnimalId { get; set; }
|
||||
public virtual Medicine Medicine { get; set; } = new();
|
||||
public virtual Animal Animal { get; set; } = new();
|
||||
}
|
||||
}
|
73
VetClinic/DinerDataBaseImplement/Models/Pharmacist.cs
Normal file
73
VetClinic/DinerDataBaseImplement/Models/Pharmacist.cs
Normal file
@ -0,0 +1,73 @@
|
||||
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 VetClinicContracts.BindingModels;
|
||||
using VetClinicContracts.ViewModels;
|
||||
using VetClinicDataModels.Models;
|
||||
|
||||
namespace VetClinicDataBaseImplement.Models
|
||||
{
|
||||
public class Pharmacist : IPharmacistModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string PharmacistFIO { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
[ForeignKey("PharmacistId")]
|
||||
public virtual List<Medicine> Medicines { get; set; } =
|
||||
new();
|
||||
[ForeignKey("PharmacistId")]
|
||||
public virtual List<Service> Services { get; set; } =
|
||||
new();
|
||||
|
||||
public static Pharmacist? Create(PharmacistBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Pharmacist()
|
||||
{
|
||||
Id = model.Id,
|
||||
PharmacistFIO = model.PharmacistFIO,
|
||||
Email = model.Email,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
|
||||
public static Pharmacist Create(PharmacistViewModel model)
|
||||
{
|
||||
return new Pharmacist()
|
||||
{
|
||||
Id = model.Id,
|
||||
PharmacistFIO = model.PharmacistFIO,
|
||||
Email = model.Email,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
public void Update( PharmacistBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PharmacistFIO = model.PharmacistFIO;
|
||||
Email = model.Email;
|
||||
Password = model.Password;
|
||||
}
|
||||
public PharmacistBindingModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
PharmacistFIO = PharmacistFIO,
|
||||
Email = Email,
|
||||
Password = Password
|
||||
};
|
||||
}
|
||||
}
|
107
VetClinic/DinerDataBaseImplement/Models/Service.cs
Normal file
107
VetClinic/DinerDataBaseImplement/Models/Service.cs
Normal file
@ -0,0 +1,107 @@
|
||||
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 VetClinicDataModels.Models;
|
||||
using VetClinicContracts.BindingModels;
|
||||
using VetClinicContracts.ViewModels;
|
||||
|
||||
namespace VetClinicDataBaseImplement.Models
|
||||
{
|
||||
public class Service : IServiceModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string ServiceName { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
[Required]
|
||||
public int PharmacistId { get; set; }
|
||||
public virtual Pharmacist Pharmacist { get; private set; }
|
||||
private Dictionary<int, (IMedicineModel, int)>? _serviceMedicines =
|
||||
null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IMedicineModel, int)> ServiceMedicines
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_serviceMedicines == null)
|
||||
{
|
||||
_serviceMedicines = Medicines
|
||||
.ToDictionary(recPC => recPC.MedicineId, recPC =>
|
||||
(recPC.Medicine as IMedicineModel, recPC.Count));
|
||||
}
|
||||
return _serviceMedicines;
|
||||
}
|
||||
}
|
||||
[ForeignKey("ServiceId")]
|
||||
public virtual List<ServiceMedicine> Medicines { get; set; } = new();
|
||||
[ForeignKey("ServiceId")]
|
||||
public virtual List<VisitService> Visits { get; set; } = new();
|
||||
[ForeignKey("ServiceId")]
|
||||
public virtual List<Guidance> Guidances { get; set; } = new();
|
||||
public static Service Create(VetClinicDatabase context,
|
||||
ServiceBindingModel model)
|
||||
{
|
||||
return new Service()
|
||||
{
|
||||
Id = model.Id,
|
||||
ServiceName = model.ServiceName,
|
||||
Price = model.Price,
|
||||
Medicines = model.ServiceMedicines.Select(x => new
|
||||
ServiceMedicine
|
||||
{
|
||||
Medicine = context.Medicines.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public void Update(ServiceBindingModel model)
|
||||
{
|
||||
ServiceName = model.ServiceName;
|
||||
Price = model.Price;
|
||||
}
|
||||
public ServiceViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ServiceName = ServiceName,
|
||||
Price = Price,
|
||||
ServiceMedicines = ServiceMedicines
|
||||
};
|
||||
public void UpdateMedicines(VetClinicDatabase context,
|
||||
ServiceBindingModel model)
|
||||
{
|
||||
var serviceMedicines = context.ServiceMedicines.Where(rec =>
|
||||
rec.ServiceId == model.Id).ToList();
|
||||
if (serviceMedicines != null && serviceMedicines.Count > 0)
|
||||
{
|
||||
context.ServiceMedicines.RemoveRange(serviceMedicines.Where(rec
|
||||
=> !model.ServiceMedicines.ContainsKey(rec.MedicineId)));
|
||||
|
||||
context.SaveChanges();
|
||||
foreach (var updateComponent in serviceMedicines)
|
||||
{
|
||||
updateComponent.Count =
|
||||
model.ServiceMedicines[updateComponent.MedicineId].Item2;
|
||||
model.ServiceMedicines.Remove(updateComponent.MedicineId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var service = context.Services.First(x => x.Id == Id);
|
||||
foreach (var pc in model.ServiceMedicines)
|
||||
{
|
||||
context.ServiceMedicines.Add(new ServiceMedicine
|
||||
{
|
||||
Service = service,
|
||||
Medicine = context.Medicines.First(x => x.Id == pc.Key),
|
||||
Count = pc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_serviceMedicines = null;
|
||||
}
|
||||
}
|
||||
}
|
23
VetClinic/DinerDataBaseImplement/Models/ServiceMedicine.cs
Normal file
23
VetClinic/DinerDataBaseImplement/Models/ServiceMedicine.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VetClinicDataBaseImplement.Models
|
||||
{
|
||||
public class ServiceMedicine
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int ServiceId { get; set; }
|
||||
[Required]
|
||||
public int MedicineId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Service Service { get; set; } = new();
|
||||
public virtual Medicine Medicine { get; set; } = new();
|
||||
}
|
||||
}
|
@ -15,7 +15,13 @@ namespace VetClinicDataBaseImplement
|
||||
}
|
||||
public virtual DbSet<Animal> Animals { set; get; }
|
||||
public virtual DbSet<Admin> Admins { set; get; }
|
||||
// public virtual DbSet<Visit> Visits { set; get; }
|
||||
// public virtual DbSet<Vaccination> Vaccinations { set; get; }
|
||||
}
|
||||
// public virtual DbSet<Visit> Visits { set; get; }
|
||||
// public virtual DbSet<Vaccination> Vaccinations { set; get; }
|
||||
public virtual DbSet<Pharmacist> Pharmacists { set; get; }
|
||||
public virtual DbSet<Service> Services { set; get; }
|
||||
public virtual DbSet<Medicine> Medicines { set; get; }
|
||||
public virtual DbSet<ServiceMedicine> ServiceMedicines { set; get; }
|
||||
public virtual DbSet<MedicineAnimal> MedicineAnimals { set; get; }
|
||||
public virtual DbSet<Guidance> Guidances { set; get; }
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace VetClinicContracts.BindingModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string MedicineName { get; set; } = string.Empty;
|
||||
public int Price { get; set; }
|
||||
public double Price { get; set; }
|
||||
public int PharmacistId { get; set; }
|
||||
public Dictionary<int, IAnimalModel> MedicineAnimals { get; set; } = new();
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace VetClinicContracts.BindingModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ServiceName { get; set; } = string.Empty;
|
||||
public int Price { get; set; }
|
||||
public double Price { get; set; }
|
||||
public int PharmacistId { get; set; }
|
||||
public Dictionary<int, (IMedicineModel, int)> ServiceMedicines { get; set; } = new();
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace VetClinicContracts.ViewModels
|
||||
[DisplayName("Название медикамента")]
|
||||
public string MedicineName { get; set; } = string.Empty;
|
||||
[DisplayName("Цена медикамента")]
|
||||
public int Price { get; set; }
|
||||
public double Price { get; set; }
|
||||
[DisplayName("Фармацевт")]
|
||||
public string PharmacistFIO { get; set; } = string.Empty;
|
||||
public int PharmacistId { get; set; }
|
||||
|
@ -14,7 +14,7 @@ namespace VetClinicContracts.ViewModels
|
||||
[DisplayName("Название услуги")]
|
||||
public string ServiceName { get; set; } = string.Empty;
|
||||
[DisplayName("Цена услуги")]
|
||||
public int Price { get; set; }
|
||||
public double Price { get; set; }
|
||||
[DisplayName("Фармацевт")]
|
||||
public string PharmacistFIO { get; set; } = string.Empty;
|
||||
public int PharmacistId { get; set; }
|
||||
|
@ -9,7 +9,7 @@ namespace VetClinicDataModels.Models
|
||||
public interface IMedicineModel : IId
|
||||
{
|
||||
string MedicineName { get; }
|
||||
int Price { get; }
|
||||
double Price { get; }
|
||||
int PharmacistId { get; }
|
||||
Dictionary<int, IAnimalModel> MedicineAnimals { get; }
|
||||
}
|
||||
|
@ -6,10 +6,10 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace VetClinicDataModels.Models
|
||||
{
|
||||
public interface IServiceModel : IId
|
||||
public interface IServiceModel : IId
|
||||
{
|
||||
string ServiceName { get; }
|
||||
int Price { get; }
|
||||
double Price { get; }
|
||||
int PharmacistId { get; }
|
||||
Dictionary<int, (IMedicineModel, int)> ServiceMedicines { get; }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user