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 Currencies { get; set; } = new(); [ForeignKey("DepositId")] public virtual List Clients { get; set; } = new(); [ForeignKey("DepositId")] public virtual List Refills { get; set; } = new(); private Dictionary? _depositCurrencies { get; set; } = null; [NotMapped] public Dictionary 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, }; } }