CourseWork_BankYouBankrupt/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Card.cs

72 lines
1.8 KiB
C#
Raw Normal View History

2023-04-01 16:30:10 +04:00
using BankYouBankruptContracts.BindingModels;
using BankYouBankruptContracts.ViewModels;
using BankYouBankruptDataModels.Models;
2023-04-01 15:33:39 +04:00
using System;
using System.Collections.Generic;
2023-04-01 16:30:10 +04:00
using System.ComponentModel.DataAnnotations;
2023-04-01 16:36:07 +04:00
using System.ComponentModel.DataAnnotations.Schema;
2023-04-01 15:33:39 +04:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankYouBankruptDatabaseImplement.Models
{
public class Card : ICardModel
{
2023-04-01 16:30:10 +04:00
public int Id { get; set; }
2023-04-01 16:30:10 +04:00
[Required]
public int ClientID { get; set; }
public virtual Client Client { get; set; }
2023-04-01 16:30:10 +04:00
[Required]
public int AccountId { get; set; }
2023-04-01 16:30:10 +04:00
[Required]
public string Number { get; set; } = String.Empty;
2023-04-01 16:30:10 +04:00
[Required]
public string CVC { get; set; }
2023-04-01 16:30:10 +04:00
[Required]
public DateTime Period { get; set; } = DateTime.Now;
2023-04-01 15:33:39 +04:00
2023-04-01 16:36:07 +04:00
[ForeignKey("CardId")]
public virtual List<Crediting> Creditings { get; set; } = new();
[ForeignKey("CardId")]
public virtual List<Debiting> Debitings { get; set; } = new();
2023-04-01 16:30:10 +04:00
public CardViewModel GetViewModel => new()
{
Id = Id,
2023-05-14 14:00:44 +04:00
AccountId = AccountId,
ClientID = ClientID,
2023-04-01 16:30:10 +04:00
ClientSurname = Client.Surname,
Number = Number,
Period = Period,
CVC = CVC
};
2023-04-01 15:33:39 +04:00
2023-04-01 16:30:10 +04:00
public static Card Create(BankYouBancruptDatabase context, CardBindingModel model)
{
return new Card()
{
Id = model.Id,
2023-05-14 14:00:44 +04:00
AccountId = model.AccountId,
2023-04-01 16:30:10 +04:00
ClientID = model.ClientID,
Number = model.Number,
Period = model.Period,
CVC = model.CVC
};
}
2023-04-01 15:33:39 +04:00
2023-04-01 16:30:10 +04:00
public void Update(CardBindingModel model)
{
Period = model.Period;
}
2023-04-01 15:33:39 +04:00
}
}
2023-04-01 16:30:10 +04:00