using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using VeterinaryContracts.BindingModels; using VeterinaryContracts.ViewModels; using VeterinaryDataModels.Models; namespace VeterinaryDatabaseImplement.Models { public class Medication : IMedicationModel { public int Id { get; private set; } [Required] public string MedicationName { get; private set; } = string.Empty; [Required] public double Price { get; set; } [Required] public int DoctorId { get; private set; } [ForeignKey("MedicationId")] public virtual List Pets { get; set; } = new(); [ForeignKey("MedicationId")] public virtual List DrugServices { get; set; } = new(); [ForeignKey("MedicationId")] public virtual List DrugMedications { get; set; } = new(); [ForeignKey("MedicationId")] public virtual List ServiceMedications { get; set; } = new(); public static Medication? Create(VeterinaryDatabase context, MedicationBindingModel model) { if (model == null) { return null; } /*var justMedications = model.MedicationPets.Select(x => new MedicationPet { Pet = context.Pets.First(y => y.Id == x.Key) }).ToList();*/ return new Medication() { Id = model.Id, MedicationName = model.MedicationName, //Pets = justMedications, DoctorId = model.DoctorId, Price = model.Price }; } public static Medication Create(MedicationViewModel model) { return new Medication { Id = model.Id, MedicationName = model.MedicationName, DoctorId = model.DoctorId, Price = model.Price }; } public void Update(MedicationBindingModel model) { if (model == null) { return; } MedicationName = model.MedicationName; Price = model.Price; } public MedicationViewModel GetViewModel => new() { Id = Id, MedicationName = MedicationName, Price = Price, //MedicationPets = MedicationPets, DoctorId = DoctorId }; } }