PIbd-23_Elatomtsev_L.K._Cou.../Bank/BankDatabaseImplement/Models/Currency.cs

49 lines
1.5 KiB
C#
Raw Normal View History

using BankDataModels.Models;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using BankContracts.BindingModels;
using BankContracts.ViewModels;
using Microsoft.EntityFrameworkCore;
using System.Numerics;
namespace BankDatabaseImplement.Models
{
public class Currency : ICurrencyModel
{
public int Id { get; set; }
[Required]
public string CurrencyName { get; set; } = string.Empty;
[Required]
public double Course { get; set; }
[ForeignKey("CurrencyId")]
public virtual List<DepositCurrency> Deposits { get; set; } = new();
[ForeignKey("CurrencyId")]
public virtual List<ProgramCurrency> Programs { get; set; } = new();
public static Currency? Create(CurrencyBindingModel model)
{
if (model == null)
return null;
return new Currency
{
Id = model.Id,
CurrencyName = model.CurrencyName,
Course = model.Course,
};
}
public void Update(CurrencyBindingModel model)
{
if (model == null)
return;
Id = model.Id;
CurrencyName = model.CurrencyName;
Course = model.Course;
}
public CurrencyViewModel GetViewModel => new()
{
Id = Id,
CurrencyName = CurrencyName,
Course = Course,
};
}
}