CourseWork_BankYouBankrupt/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Card.cs
2023-04-01 16:30:10 +04:00

59 lines
1.6 KiB
C#

using BankYouBankruptContracts.BindingModels;
using BankYouBankruptContracts.ViewModels;
using BankYouBankruptDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankYouBankruptDatabaseImplement.Models
{
public class Card : ICardModel
{
public int Id { get; set; }
[Required]
public int ClientID { get; set; }
public virtual Client Client { get; set; } = new();
[Required]
public int AccountId { get; set; }
[Required]
public string Number { get; set; } = String.Empty;
[Required]
public string CVC { get; set; }
[Required]
public DateTime Period { get; set; } = DateTime.Now;
public CardViewModel GetViewModel => new()
{
Id = Id,
ClientID = ClientID,
ClientSurname = Client.Surname,
Number = Number,
Period = Period,
CVC = CVC
};
public static Card Create(BankYouBancruptDatabase context, CardBindingModel model)
{
return new Card()
{
Id = model.Id,
ClientID = model.ClientID,
Client = context.Clients.First(x => x.Id == model.ClientID),
Number = model.Number,
Period = model.Period,
CVC = model.CVC
};
}
public void Update(CardBindingModel model)
{
Period = model.Period;
}
}
}