CourseWork_BankYouBankrupt/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/MoneyTransfer.cs

77 lines
1.9 KiB
C#

using BankYouBankruptContracts.BindingModels;
using BankYouBankruptContracts.ViewModels;
using BankYouBankruptDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankYouBankruptDatabaseImplement.Models
{
public class MoneyTransfer : IMoneyTransferModel
{
public int Id { get; set; }
[Required]
public int Sum { get; set; }
[Required]
public int? AccountSenderId { get; set; }
[Required]
public int AccountPayeeId { get; set; }
[Required]
public DateTime DateOperation { get; set; }
[Required]
public int? CreditingId { get; set; }
public int CashierId { get; set; }
public virtual Cashier Cashier { get; set; }
public virtual Account AccountSender { get; set; }
public virtual Account AccountPayeer { get; set; }
public static MoneyTransfer Create(BankYouBancruptDatabase context, MoneyTransferBindingModel model)
{
return new MoneyTransfer()
{
Id = model.Id,
Sum = model.Sum,
Cashier = context.Cashiers.First(x => x.Id == model.CashierId),
AccountSender = context.Accounts.First(x => x.Id == model.AccountSenderId),
AccountPayeer = context.Accounts.First(x => x.Id == model.AccountPayeeId),
AccountSenderId = model.AccountSenderId,
AccountPayeeId = model.AccountPayeeId,
DateOperation = model.DateOperation
};
}
public void Update(MoneyTransferBindingModel model)
{
Id = model.Id;
DateOperation = model.DateOperation;
}
public MoneyTransferViewModel GetViewModel => new()
{
Id = Id,
AccountPayeeId = AccountPayeeId,
AccountSenderId = AccountSenderId,
AccountPayeeNumber = AccountPayeer.AccountNumber,
AccountSenderNumber = AccountSender.AccountNumber,
DateOperation = DateOperation,
Sum = Sum,
CreditingId = CreditingId,
CashierId = CashierId,
CashierSurname = Cashier.Surname
};
}
}