using BankDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; using BankContracts.BindingModels; using BankContracts.ViewModels; namespace BankDatabaseImplement.Models { public class Program : IProgramModel { public int Id { get; set; } [Required] public string ProgramName { get; set; } = string.Empty; [Required] public double InterestRate { get; set; } [ForeignKey("ProgramId")] public virtual List Currencies { get; set; } = new(); [ForeignKey("ProgramId")] public virtual List Clients { get; set; } = new(); [ForeignKey("ProgramId")] public virtual List Terms { get; set; } = new(); private Dictionary? _programCurrencies { get; set; } = null; [NotMapped] public Dictionary ProgramCurrencies { get { if (_programCurrencies == null) { _programCurrencies = Currencies.ToDictionary( x => x.CurrencyId, x => (x.Currency as ICurrencyModel) ); } return _programCurrencies; } } public static Program? Create(ProgramBindingModel model) { if (model == null) return null; return new Program { Id = model.Id, ProgramName = model.ProgramName, InterestRate = model.InterestRate, }; } public void Update(ProgramBindingModel model) { if (model == null) return; Id = model.Id; ProgramName = model.ProgramName; InterestRate = model.InterestRate; } public ProgramViewModel GetViewModel => new() { Id = Id, ProgramName = ProgramName, InterestRate = InterestRate, }; } }