CourseWork_Bank/Bank/BankDatabaseImplement/Models/Currency.cs

55 lines
1.3 KiB
C#

using BankDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using BankContracts.BindingModels;
using BankContracts.ViewModels;
namespace BankDatabaseImplement.Models
{
public class Currency : ICurrencyModel
{
public int Id { get; set; }
[Required]
public string Name { get; set; }
public static Currency? Create(BankDatabase context, CurrencyBindingModel model)
{
if (model == null)
{
return null;
}
return new Currency()
{
Id = model.Id,
Name = model.Name,
};
}
public static Currency? Create(BankDatabase context, CurrencyViewModel model)
{
return new Currency()
{
Id = model.Id,
Name = model.Name,
};
}
public void Update(CurrencyBindingModel? model)
{
if (model == null)
{
return;
}
Name = model.Name;
}
public CurrencyViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
};
}
}