2024-04-28 12:53:39 +04:00
|
|
|
|
using BankContracts.BindingModels.Client;
|
|
|
|
|
using BankContracts.ViewModels.Client.ViewModels;
|
2024-04-28 20:13:23 +04:00
|
|
|
|
using BankDatabaseImplement.Models.CashierModels;
|
2024-04-28 12:53:39 +04:00
|
|
|
|
using BankDataModels.Models.Client;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
|
2024-04-28 20:13:23 +04:00
|
|
|
|
namespace BankDatabaseImplement.Models.ClientModels
|
2024-04-28 12:53:39 +04:00
|
|
|
|
{
|
2024-05-29 17:24:55 +04:00
|
|
|
|
public class Card : ICardModel
|
2024-04-28 12:53:39 +04:00
|
|
|
|
{
|
|
|
|
|
public int Id { get; set; }
|
|
|
|
|
|
|
|
|
|
[Required]
|
2024-05-29 17:24:55 +04:00
|
|
|
|
public int ClientID { get; set; }
|
2024-04-28 12:53:39 +04:00
|
|
|
|
|
|
|
|
|
public virtual Client Client { get; set; }
|
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public int AccountId { get; set; }
|
|
|
|
|
|
|
|
|
|
public virtual Account Account { get; set; }
|
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public string Number { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
[Required]
|
2024-05-29 17:24:55 +04:00
|
|
|
|
public string CVC { get; set; } = string.Empty;
|
2024-04-28 12:53:39 +04:00
|
|
|
|
|
2024-05-29 17:24:55 +04:00
|
|
|
|
[Required]
|
2024-04-28 12:53:39 +04:00
|
|
|
|
public DateTime Period { get; set; } = DateTime.Now;
|
|
|
|
|
|
2024-05-29 17:24:55 +04:00
|
|
|
|
[ForeignKey("CardId")]
|
|
|
|
|
public virtual List<Crediting> Creditings { get; set; } = new();
|
2024-04-28 12:53:39 +04:00
|
|
|
|
|
2024-05-29 17:24:55 +04:00
|
|
|
|
[ForeignKey("CardId")]
|
|
|
|
|
public virtual List<Debiting> Debitings { get; set; } = new();
|
2024-04-28 12:53:39 +04:00
|
|
|
|
|
|
|
|
|
public CardViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
2024-05-29 17:24:55 +04:00
|
|
|
|
AccountId = AccountId,
|
|
|
|
|
ClientID = ClientID,
|
|
|
|
|
ClientSurname = Client.Surname,
|
2024-04-28 12:53:39 +04:00
|
|
|
|
Number = Number,
|
2024-05-29 17:24:55 +04:00
|
|
|
|
Sum = Account.Balance,
|
2024-04-28 12:53:39 +04:00
|
|
|
|
Period = Period,
|
2024-05-29 17:24:55 +04:00
|
|
|
|
CVC = CVC
|
2024-04-28 12:53:39 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static Card Create(BankDatabase context, CardBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
return new Card()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
AccountId = model.AccountId,
|
|
|
|
|
Account = context.Accounts.First(x => x.Id == model.AccountId),
|
2024-05-29 17:24:55 +04:00
|
|
|
|
ClientID = model.ClientID,
|
|
|
|
|
Client = context.Clients.First(x => x.Id == model.ClientID),
|
2024-04-28 12:53:39 +04:00
|
|
|
|
Number = model.Number,
|
|
|
|
|
Period = model.Period,
|
2024-05-29 17:24:55 +04:00
|
|
|
|
CVC = model.CVC
|
2024-04-28 12:53:39 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(CardBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
Period = model.Period;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-29 17:24:55 +04:00
|
|
|
|
|