CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Payment.cs

70 lines
1.8 KiB
C#
Raw Normal View History

using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels.Enums;
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Models
{
public class Payment : IPaymentModel
{
public int ID { get; set; }
2024-05-25 22:32:22 +04:00
[ForeignKey("ProductID")]
public int ProductID { get; set; }
2024-05-25 22:32:22 +04:00
[ForeignKey("OrderID")]
public int OrderID { get; set; }
2024-05-25 22:32:22 +04:00
[Required]
public double SumPayment { get; set; }
2024-05-25 22:32:22 +04:00
[Required]
public PaymeantOption PayOption { get; set; } = PaymeantOption.Неоплачено;
2024-05-25 22:32:22 +04:00
public static Payment? Create(PaymentBindingModel? model)
{
if (model == null)
{
return null;
}
return new Payment()
{
ID = model.ID,
ProductID = model.ProductID,
OrderID = model.OrderID,
SumPayment = model.SumPayment,
PayOption = model.PayOption,
};
}
2024-05-25 22:32:22 +04:00
public void Update(PaymentBindingModel? model)
{
if (model == null)
{
return;
}
ProductID = model.ProductID;
OrderID = model.OrderID;
SumPayment = model.SumPayment;
PayOption = model.PayOption;
}
public PaymentViewModel GetViewModel => new()
{
ID = ID,
ProductID = ProductID,
OrderID = OrderID,
SumPayment = SumPayment,
PayOption = PayOption,
};
}
}