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; MedicationId = model.MedicationId; } public ServiceViewModel GetViewModel => new() { Id = Id, Name = Name, Cost = Cost, MedicationId = MedicationId, MedicationName = Medication.Name }; } }