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 HospitalDataModels.Models; using HospitalContracts.BindingModels; using HospitalContracts.ViewModels; namespace HospitalDataBaseImplements.Models { public class Kurses : IKurseModel { public int Id { get; private set; } [ForeignKey("MedicinesId")] public int MedicinesId { get; private set; } public virtual Medicines Medicines { get; set; } = new(); public string MedicinesName { get; private set; } = string.Empty; [Required] public string Duration { get; private set; } = string.Empty; [Required] public int CountInDay { get; private set; } [ForeignKey("KurseId")] public virtual List IllnessKurses { get; set; } = new(); public static Kurses? Create(KurseBindingModel model) { if (model == null) { return null; } return new Kurses() { Id = model.Id, MedicinesId = model.MedicinesId, MedicinesName = model.MedicinesName, Duration = model.Duration, CountInDay = model.CountInDay }; } public static Kurses Create(KurseViewModel model) { return new Kurses { Id = model.Id, MedicinesId = model.MedicinesId, MedicinesName = model.MedicinesName, Duration = model.Duration, CountInDay = model.CountInDay }; } public void Update(KurseBindingModel model) { if (model == null) { return; } MedicinesName = model.MedicinesName; Duration = model.Duration; CountInDay = model.CountInDay; } public KurseViewModel GetViewModel => new() { Id = Id, MedicinesId = MedicinesId, MedicinesName = MedicinesName, Duration = Duration, CountInDay = CountInDay }; } }