CourseWork_BankYouBankrupt/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/MoneyTransfer.cs

60 lines
1.6 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; }
//для передачи номера счёта отправителя
public virtual Account AccountSenderNumber { get; set; }
[Required]
public int AccountPayeeId { get; set; }
//для передачи номера счёта получателя
public virtual Account AccountPayeeNumber { get; set; }
[Required]
public DateTime DateOperation { get; set; }
public static MoneyTransfer Create(BankYouBancruptDatabase context, MoneyTransferBindingModel model)
{
return new MoneyTransfer()
{
Id = model.Id,
Sum = model.Sum,
AccountSenderId = model.AccountSenderId,
AccountPayeeId = model.AccountPayeeId,
DateOperation = model.DateOperation,
AccountSenderNumber = context.Accounts.First(x => x.Id == model.AccountSenderId),
AccountPayeeNumber = context.Accounts.First(x => x.Id == model.AccountPayeeId)
};
}
public MoneyTransferViewModel GetViewModel => new()
{
Id = Id,
AccountPayeeId = AccountPayeeId,
AccountSenderId = AccountSenderId,
DateOperation = DateOperation,
Sum = Sum
};
}
}