70 lines
2.1 KiB
C#
70 lines
2.1 KiB
C#
using BankDataModels.Models;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using BankContracts.BindingModels;
|
|
using BankContracts.ViewModels;
|
|
|
|
namespace BankDatabaseImplement.Models
|
|
{
|
|
public class Deposit : IDepositModel
|
|
{
|
|
public int Id { get; set; }
|
|
[Required]
|
|
public int WorkerId { get; set; }
|
|
public virtual Worker? Worker { get; set; }
|
|
[Required]
|
|
public double Sum { get; set; }
|
|
[Required]
|
|
public DateOnly OpeningDate { get; set; }
|
|
[ForeignKey("DepositId")]
|
|
public virtual List<DepositCurrency> Currencies { get; set; } = new();
|
|
[ForeignKey("DepositId")]
|
|
public virtual List<ClientDeposit> Clients { get; set; } = new();
|
|
[ForeignKey("DepositId")]
|
|
public virtual List<Refill> Refills { get; set; } = new();
|
|
private Dictionary<int, ICurrencyModel>?
|
|
_depositCurrencies
|
|
{ get; set; } = null;
|
|
[NotMapped]
|
|
public Dictionary<int, ICurrencyModel> DepositCurrencies
|
|
{
|
|
get
|
|
{
|
|
if (_depositCurrencies == null)
|
|
{
|
|
_depositCurrencies = Currencies.ToDictionary(
|
|
x => x.CurrencyId,
|
|
x => (x.Currency as ICurrencyModel)
|
|
);
|
|
}
|
|
return _depositCurrencies;
|
|
}
|
|
}
|
|
public static Deposit? Create(DepositBindingModel model)
|
|
{
|
|
if (model == null)
|
|
return null;
|
|
return new Deposit
|
|
{
|
|
Id = model.Id,
|
|
WorkerId = model.WorkerId,
|
|
Sum = model.Sum,
|
|
};
|
|
}
|
|
public void Update(DepositBindingModel model)
|
|
{
|
|
if (model == null)
|
|
return;
|
|
Id = model.Id;
|
|
WorkerId = model.WorkerId;
|
|
Sum = model.Sum;
|
|
}
|
|
public DepositViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
WorkerId = WorkerId,
|
|
Sum = Sum,
|
|
};
|
|
}
|
|
}
|