62 lines
1.5 KiB
C#
62 lines
1.5 KiB
C#
using BankContracts.BindingModels.Client;
|
|
using BankContracts.ViewModels.Client.ViewModels;
|
|
using BankDatabaseImplement.Models.ClientModels;
|
|
using BankDataModels.Enums;
|
|
using BankDataModels.Models.Client;
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace BankDatabaseImplement.Models
|
|
{
|
|
public class Debiting : IDebitingModel
|
|
{
|
|
public int Id { get; set; }
|
|
|
|
[Required]
|
|
public int CardId { get; set; }
|
|
|
|
public virtual Card Card { get; set; }
|
|
|
|
[Required]
|
|
public int Sum { get; set; }
|
|
|
|
[Required]
|
|
public DateTime DateOpen { get; set; } = DateTime.Now;
|
|
|
|
public DateTime? DateClose { get; set; }
|
|
|
|
[Required]
|
|
public StatusEnum Status { get; set; }
|
|
|
|
public DebitingViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
CardId = CardId,
|
|
CardNumber = Card.Number,
|
|
Sum = Sum,
|
|
DateOpen = DateOpen,
|
|
DateClose = DateClose,
|
|
Status = Status
|
|
};
|
|
|
|
public static Debiting Create(BankDatabase context, DebitingBindingModel model)
|
|
{
|
|
return new Debiting()
|
|
{
|
|
Id = model.Id,
|
|
CardId = model.CardId,
|
|
Card = context.Cards.First(x => x.Id == model.CardId),
|
|
Sum = model.Sum,
|
|
DateOpen = model.DateOpen,
|
|
Status = model.Status
|
|
};
|
|
}
|
|
|
|
public void Update(DebitingBindingModel model)
|
|
{
|
|
DateClose = model.DateClose;
|
|
|
|
Status = model.Status;
|
|
}
|
|
}
|
|
}
|