70 lines
1.9 KiB
C#
70 lines
1.9 KiB
C#
using BankYouBankruptContracts.BindingModels;
|
||
using BankYouBankruptContracts.ViewModels.Client.Default;
|
||
using BankYouBankruptDataModels.Enums;
|
||
using BankYouBankruptDataModels.Models;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel.DataAnnotations;
|
||
using System.ComponentModel.DataAnnotations.Schema;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace BankYouBankruptDatabaseImplement.Models
|
||
{
|
||
public class Crediting : ICreditingModel
|
||
{
|
||
|
||
public int Id { get; set; }
|
||
|
||
[Required]
|
||
public int CardId { get; set; }
|
||
|
||
public virtual Card Card { get; set; }
|
||
|
||
[Required]
|
||
public int Sum { get; set; }
|
||
|
||
[Required]
|
||
public DateTime DateOpen { get; set; } = DateTime.Now;
|
||
|
||
public DateTime? DateClose { get; set; }
|
||
|
||
[Required]
|
||
public StatusEnum Status { get; set; }
|
||
|
||
//для реализации связи один ко многим с переводом денег
|
||
[ForeignKey("CreditingId")]
|
||
public virtual List<MoneyTransfer> MoneyTransfers { get; set; } = new();
|
||
|
||
public CreditingViewModel GetViewModel => new()
|
||
{
|
||
Id = Id,
|
||
CardId = CardId,
|
||
CardNumber = Card.Number,
|
||
Sum = Sum,
|
||
DateOpen = DateOpen,
|
||
DateClose = DateClose,
|
||
Status = Status
|
||
};
|
||
|
||
public static Crediting Create(BankYouBancruptDatabase context, CreditingBindingModel model)
|
||
{
|
||
return new Crediting()
|
||
{
|
||
Id = model.Id,
|
||
CardId = model.CardId,
|
||
Card = context.Cards.First(x => x.Id == model.CardId),
|
||
Sum = model.Sum,
|
||
DateOpen = model.DateOpen
|
||
};
|
||
}
|
||
|
||
public void Update(CreditingBindingModel model)
|
||
{
|
||
DateClose = model.DateClose;
|
||
Status = model.Status;
|
||
}
|
||
}
|
||
}
|