PIbd-22_Shabunov_O.A._SushiBar/SushiBarDatabaseImplement/Models/Promotion.cs
2024-05-16 17:13:55 +04:00

50 lines
1.3 KiB
C#

using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace SushiBarDatabaseImplement.Models
{
public class Promotion
{
[Key]
public int Id { get; set; }
[Required]
public string PromotionName { get; set; } = string.Empty;
[Required]
public float Discount { get; set; }
[Required]
public double TriggeringSum { get; set; }
[ForeignKey("PromotionId")]
public virtual List<Cheque> Cheques { get; set; } = new();
public static Promotion? Create(PromotionBindingModel Model)
{
return new Promotion()
{
PromotionName = Model.PromotionName,
Discount = Model.Discount,
TriggeringSum = Model.TriggeringSum,
};
}
public void Update(PromotionBindingModel Model)
{
PromotionName = Model.PromotionName;
Discount = Model.Discount;
TriggeringSum = Model.TriggeringSum;
}
public PromotionViewModel ViewModel => new()
{
PromotionName = PromotionName,
Discount = Discount,
TriggeringSum = TriggeringSum,
};
}
}