PIbd-22_Katysheva_N.E._Pizz.../Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs

69 lines
2.0 KiB
C#
Raw Normal View History

2024-04-07 15:05:57 +04:00
using PizzeriaContracts.BindingModels;
using PizzeriaContracts.ViewModels;
using PizzeriaDataModels.Enums;
using PizzeriaDataModels.Models;
using System.ComponentModel.DataAnnotations;
namespace PizzeriaDatabaseImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
[Required]
public int PizzaId { get; private set; }
[Required]
2024-05-07 23:20:02 +04:00
public int ClientId { get; set; }
[Required]
2024-04-07 15:05:57 +04:00
public int Count { get; private set; }
[Required]
public double Sum { get; private set; }
[Required]
public OrderStatus Status { get; private set; }
[Required]
public DateTime DateCreate { get; private set; }
public DateTime? DateImplement { get; private set; }
public virtual Pizza Pizza { get; set; }
2024-05-07 23:20:02 +04:00
public virtual Client Client { get; set; }
2024-04-07 15:05:57 +04:00
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
PizzaId = model.PizzaId,
2024-05-07 23:20:02 +04:00
ClientId = model.ClientId,
2024-04-07 15:05:57 +04:00
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
PizzaId = PizzaId,
2024-05-07 23:20:02 +04:00
ClientId = ClientId,
2024-04-07 15:05:57 +04:00
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
PizzaName = Pizza.PizzaName
};
}
}