CourseWork_Bank/Bank/BankDatabaseImplement/Models/Payment.cs

52 lines
1.4 KiB
C#
Raw Normal View History

using BankContracts.BindingModels;
using BankContracts.ViewModels;
using BankDataModels;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
namespace BankDatabaseImplement.Models
{
public class Payment : IPaymentModel
{
[Required]
public int OperationByPurchaseId { get; private set; }
[Required]
public DateOnly Date { get; private set; }
[Required]
public double PaidPrice { get; private set; }
public int Id { get; private set; }
[Required]
public OperationByPurchase? OperationByPurchase { get; private set; }
public static Payment Create(PaymentBindingModel model)
{
if (model == null)
{
return null;
}
return new Payment()
{
Date = model.Date,
PaidPrice = model.PaidPrice,
Id = model.Id,
OperationByPurchaseId = model.OperationByPurchaseId,
};
}
public PaymentViewModel GetViewModel => new()
{
Operation = OperationByPurchase?.Operation?.GetViewModel,
OperationByPurchase = OperationByPurchase,
FullPrice = OperationByPurchase?.Operation?.Price ?? -1,
Date = Date,
PaidPrice = PaidPrice,
Id = Id,
OperationByPurchaseId = OperationByPurchaseId,
};
}
}