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.Enums;
|
|
|
|
|
using BankDataModels.Models.Client;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2024-04-28 20:13:23 +04:00
|
|
|
|
namespace BankDatabaseImplement.Models.ClientModels
|
2024-04-28 12:53:39 +04:00
|
|
|
|
{
|
2024-05-01 01:54:31 +04:00
|
|
|
|
// Класс, реализующий интерфейс модели банковской карты
|
|
|
|
|
public class Card : ICardModel
|
2024-04-28 12:53:39 +04:00
|
|
|
|
{
|
|
|
|
|
public int Id { get; set; }
|
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public int ClientId { get; set; }
|
|
|
|
|
|
|
|
|
|
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]
|
|
|
|
|
public double Balance { get; set; }
|
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public DateTime Period { get; set; } = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
[Required]
|
2024-04-28 20:52:53 +04:00
|
|
|
|
public StatusCard StatusCard { get; set; } = StatusCard.Открыта;
|
2024-04-28 12:53:39 +04:00
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public string? ClientSurname { get; set; }
|
|
|
|
|
|
2024-05-01 01:54:31 +04:00
|
|
|
|
// Для реализации связи один-ко-многим с пополнением карты
|
|
|
|
|
[ForeignKey("CardId")]
|
2024-04-28 20:13:23 +04:00
|
|
|
|
public virtual List<Crediting> creditings { get; set; } = new();
|
2024-04-28 12:53:39 +04:00
|
|
|
|
|
2024-05-01 01:54:31 +04:00
|
|
|
|
// Для реализации связи один-ко-многим со снятием наличных с карты
|
|
|
|
|
[ForeignKey("CardId")]
|
2024-04-28 20:13:23 +04:00
|
|
|
|
public virtual List<Debiting> debitings { get; set; } = new();
|
2024-04-28 12:53:39 +04:00
|
|
|
|
|
|
|
|
|
public CardViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
AccountId = AccountId,
|
|
|
|
|
ClientId = ClientId,
|
|
|
|
|
Number = Number,
|
|
|
|
|
Balance = Balance,
|
|
|
|
|
Period = Period,
|
|
|
|
|
StatusCard = StatusCard,
|
|
|
|
|
ClientSurname = ClientSurname
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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),
|
|
|
|
|
ClientId = model.ClientId,
|
|
|
|
|
Client = context.Clients.First(x => x.Id == model.ClientId),
|
|
|
|
|
Number = model.Number,
|
|
|
|
|
Balance = model.Balance,
|
|
|
|
|
Period = model.Period,
|
|
|
|
|
StatusCard = model.StatusCard,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(CardBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
Period = model.Period;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|