PIbd-31_Putincev.D.M._COP_29/COP/PortalAccountsDatabaseImplement/Models/Interest.cs

49 lines
1.2 KiB
C#

using PortalAccountsContracts.BindingModels;
using PortalAccountsContracts.ViewModels;
using PortalAccountsDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace PortalAccountsDatabaseImplement.Models
{
public class Interest : IInterestModel
{
public int Id { get; private set; }
[Required]
public string Name { get; private set; } = string.Empty;
[ForeignKey("InterestId")]
public virtual List<Account> Accounts { get; set; } = new();
public static Interest? Create(InterestBindingModel model)
{
if (model == null)
{
return null;
}
return new Interest()
{
Id = model.Id,
Name = model.Name
};
}
public void Update(InterestBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
}
public InterestViewModel GetViewModel => new()
{
Id = Id,
Name = Name
};
}
}