85 lines
1.9 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;
using BankContracts.ViewModels;
using BankDataModels.Enums;
using BankDataModels.Models;
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
{
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;
}
}
}