66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
using BankYouBankruptContracts.BindingModels;
|
||
using BankYouBankruptContracts.ViewModels;
|
||
using BankYouBankruptDataModels.Enums;
|
||
using BankYouBankruptDataModels.Models;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel.DataAnnotations;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace BankYouBankruptDatabaseImplement.Models
|
||
{
|
||
public class Debiting : IDebitingModel
|
||
{
|
||
public int Id { get; set; }
|
||
|
||
[Required]
|
||
public int CardId { get; set; }
|
||
|
||
public virtual Card Card { get; set; } = new();
|
||
|
||
[Required]
|
||
public int Sum { get; set; }
|
||
|
||
[Required]
|
||
public DateTime DateOpen { get; set; } = DateTime.Now;
|
||
|
||
[Required]
|
||
public DateTime DateClose { get; set; }
|
||
|
||
[Required]
|
||
public StatusEnum Status { get; set; } = StatusEnum.Открыта;
|
||
|
||
public DebitingViewModel GetViewModel => new()
|
||
{
|
||
Id = Id,
|
||
CardId = CardId,
|
||
CardNumber = Card.Number,
|
||
Sum = Sum,
|
||
DateOpen = DateOpen,
|
||
DateClose = DateClose,
|
||
Status = Status
|
||
};
|
||
|
||
public static Debiting Create(BankYouBancruptDatabase context, DebitingBindingModel model)
|
||
{
|
||
return new Debiting()
|
||
{
|
||
Id = model.Id,
|
||
CardId = model.CardId,
|
||
Card = context.Cards.First(x => x.Id == model.CardId),
|
||
Sum = model.Sum,
|
||
DateOpen = model.DateOpen,
|
||
DateClose = model.DateClose,
|
||
Status = model.Status
|
||
};
|
||
}
|
||
|
||
public void Update(DebitingBindingModel model)
|
||
{
|
||
DateClose = model.DateClose;
|
||
}
|
||
}
|
||
}
|