67 lines
2.1 KiB
C#
67 lines
2.1 KiB
C#
|
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<ProgramCurrency> Currencies { get; set; } = new();
|
|||
|
[ForeignKey("ProgramId")]
|
|||
|
public virtual List<ClientProgram> Clients { get; set; } = new();
|
|||
|
[ForeignKey("ProgramId")]
|
|||
|
public virtual List<Term> Terms { get; set; } = new();
|
|||
|
private Dictionary<int, ICurrencyModel>?
|
|||
|
_programCurrencies
|
|||
|
{ get; set; } = null;
|
|||
|
[NotMapped]
|
|||
|
public Dictionary<int, ICurrencyModel> 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,
|
|||
|
};
|
|||
|
}
|
|||
|
}
|