2023-04-06 21:07:40 +04:00
|
|
|
|
using BankContracts.BindingModels;
|
|
|
|
|
using BankContracts.ViewModels;
|
|
|
|
|
using BankDataModels.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace BankDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Transfer : ITransferModel
|
|
|
|
|
{
|
|
|
|
|
public int Id {get; set;}
|
|
|
|
|
[Required]
|
|
|
|
|
public float Amount { get; set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public DateTime TransferDateTime { get; set; } = DateTime.Now;
|
|
|
|
|
[Required]
|
|
|
|
|
public int PaymentId { get; set; }
|
|
|
|
|
public virtual Payment Payment { get; set; } = new();
|
2023-04-07 13:42:01 +04:00
|
|
|
|
public int OperatorId { get; set; }
|
|
|
|
|
public virtual Operator Operator { get; set; } = new();
|
2023-04-06 21:07:40 +04:00
|
|
|
|
public static Transfer? Create(BankDatabase context, TransferBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Transfer()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
Amount = model.Amount,
|
|
|
|
|
TransferDateTime = model.TransferDateTime,
|
|
|
|
|
PaymentId = model.PaymentId,
|
2023-04-07 17:08:15 +04:00
|
|
|
|
Payment = context.Payments.First(x => x.Id == model.PaymentId),
|
|
|
|
|
OperatorId = model.OperatorId,
|
|
|
|
|
Operator = context.Operators.First(x => x.Id == model.OperatorId)
|
2023-04-06 21:07:40 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public static Transfer? Create(BankDatabase context, TransferViewModel model)
|
|
|
|
|
{
|
|
|
|
|
return new Transfer()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
Amount = model.Amount,
|
|
|
|
|
TransferDateTime = model.TransferDateTime,
|
|
|
|
|
PaymentId = model.PaymentId,
|
|
|
|
|
Payment = context.Payments.First(x => x.Id == model.PaymentId)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public void Update(TransferBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Amount = model.Amount;
|
|
|
|
|
}
|
|
|
|
|
public TransferViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
TransferDateTime = TransferDateTime,
|
|
|
|
|
Amount = Amount,
|
2023-04-07 13:42:01 +04:00
|
|
|
|
PaymentId = PaymentId,
|
|
|
|
|
OperatorId = OperatorId,
|
|
|
|
|
OperatorName = Operator.LastName + " " + Operator.FirstName + " " + Operator.MiddleName,
|
2023-04-06 21:07:40 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|