CourseWork_BankYouBankrupt/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Crediting.cs

57 lines
1.4 KiB
C#
Raw Normal View History

2023-04-01 16:30:10 +04:00
using BankYouBankruptContracts.BindingModels;
using BankYouBankruptContracts.ViewModels;
using BankYouBankruptDataModels.Models;
2023-04-01 15:33:39 +04:00
using System;
using System.Collections.Generic;
2023-04-01 16:30:10 +04:00
using System.ComponentModel.DataAnnotations;
2023-04-01 15:33:39 +04:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankYouBankruptDatabaseImplement.Models
{
public class Crediting : ICreditingModel
{
2023-04-01 16:30:10 +04:00
public int Id { get; set; }
2023-04-01 15:33:39 +04:00
2023-04-01 16:30:10 +04:00
[Required]
public int CardId { get; set; }
2023-04-01 15:33:39 +04:00
2023-05-14 18:27:41 +04:00
public virtual Card Card { get; set; }
2023-04-01 16:49:22 +04:00
2023-04-01 16:30:10 +04:00
[Required]
public int Sum { get; set; }
[Required]
public DateTime Date { get; set; } = DateTime.Now;
public CreditingViewModel GetViewModel => new()
{
Id = Id,
CardId = CardId,
2023-04-01 16:49:22 +04:00
CardNumber = Card.Number,
2023-04-01 16:30:10 +04:00
Sum = Sum,
Date = Date
};
2023-04-01 16:49:22 +04:00
public static Crediting Create(BankYouBancruptDatabase context, CreditingBindingModel model)
2023-04-01 16:30:10 +04:00
{
return new Crediting()
{
Id = model.Id,
CardId = model.CardId,
2023-04-01 16:49:22 +04:00
Card = context.Cards.First(x => x.Id == model.CardId),
2023-04-01 16:30:10 +04:00
Sum = model.Sum,
Date = model.Date
};
}
2023-04-01 19:28:58 +04:00
public void Update(CreditingBindingModel model)
{
Date = model.Date;
}
2023-04-01 15:33:39 +04:00
}
}