PIbd-21_Zaharchenko_M.I._Pi.../Pizzeria/PizzeriaListImplement/Models/Order.cs

55 lines
1.7 KiB
C#
Raw Normal View History

2023-02-16 08:52:03 +04:00
using PizzeriaDataModels.Enums;
using PizzeriaDataModels.Models;
using PizzeriaContracts.BindingModels;
using PizzeriaContracts.ViewModels;
2023-02-12 20:11:02 +04:00
2023-02-16 08:52:03 +04:00
namespace PizzeriaListImplement.Models
2023-02-12 20:11:02 +04:00
{
public class Order : IOrderModel
{
public int Id { get; private set; }
2023-02-16 08:52:03 +04:00
public int PizzaId { get; private set; }
2023-02-12 20:11:02 +04:00
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
2023-02-16 08:52:03 +04:00
PizzaId = model.PizzaId,
2023-02-12 20:11:02 +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;
}
2023-02-16 08:52:03 +04:00
Status = model.Status;
2023-03-05 11:51:11 +04:00
if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement;
2023-02-12 20:11:02 +04:00
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
2023-02-16 08:52:03 +04:00
PizzaId = PizzaId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
2023-02-12 20:11:02 +04:00
DateImplement = DateImplement,
};
}
}