2024-05-01 01:54:31 +04:00

89 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BankContracts.BindingModels.Client;
using BankContracts.ViewModels.Client.ViewModels;
using BankDatabaseImplement.Models.CashierModels;
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;
namespace BankDatabaseImplement.Models.ClientModels
{
// Класс, реализующий интерфейс модели банковской карты
public class Card : ICardModel
{
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]
public StatusCard StatusCard { get; set; } = StatusCard.Открыта;
[Required]
public string? ClientSurname { get; set; }
// Для реализации связи один-ко-многим с пополнением карты
[ForeignKey("CardId")]
public virtual List<Crediting> creditings { get; set; } = new();
// Для реализации связи один-ко-многим со снятием наличных с карты
[ForeignKey("CardId")]
public virtual List<Debiting> debitings { get; set; } = new();
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;
}
}
}