CourseWork_BankYouBankrupt/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/MoneyTransfer.cs

77 lines
2.1 KiB
C#
Raw Normal View History

using BankYouBankruptContracts.BindingModels;
using BankYouBankruptContracts.ViewModels;
using BankYouBankruptDataModels.Models;
2023-04-01 15:33:39 +04:00
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
2023-04-01 15:33:39 +04:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankYouBankruptDatabaseImplement.Models
{
public class MoneyTransfer : IMoneyTransferModel
{
public int Id { get; set; }
2023-04-01 15:33:39 +04:00
[Required]
public int Sum { get; set; }
2023-04-01 15:33:39 +04:00
public int? AccountSenderId { get; set; }
2023-04-01 15:33:39 +04:00
[Required]
public int AccountPayeeId { get; set; }
2023-04-01 15:33:39 +04:00
[Required]
public DateTime DateOperation { get; set; }
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),
2023-05-16 21:55:36 +04:00
AccountSender = model.AccountSenderId == null ? null : context.Accounts.First(x => x.Id == model.AccountSenderId),
AccountPayeer = context.Accounts.First(x => x.Id == model.AccountPayeeId),
AccountSenderId = model.AccountSenderId,
AccountPayeeId = model.AccountPayeeId,
2023-05-16 21:55:36 +04:00
DateOperation = model.DateOperation,
CreditingId = model.CreditingId,
CashierId = model.CashierId
};
}
public void Update(MoneyTransferBindingModel model)
{
Id = model.Id;
DateOperation = model.DateOperation;
}
public MoneyTransferViewModel GetViewModel => new()
{
Id = Id,
AccountPayeeId = AccountPayeeId,
AccountSenderId = AccountSenderId,
AccountPayeeNumber = AccountPayeer.AccountNumber,
2023-05-16 21:55:36 +04:00
AccountSenderNumber = AccountSenderId == null ? null : AccountSender.AccountNumber,
DateOperation = DateOperation,
Sum = Sum,
CreditingId = CreditingId,
CashierId = CashierId,
CashierSurname = Cashier.Surname
};
}
2023-04-01 15:33:39 +04:00
}