SUBD/Sushi/SushiDatabaseImplement/Models/Order.cs
2024-04-18 11:16:56 +04:00

73 lines
2.1 KiB
C#

using SushiContracts.BindingModels;
using SushiContracts.ViewModels;
using SushiDataModels.Enums;
using System.ComponentModel.DataAnnotations;
namespace SushiShopDatabaseImplement.Models
{
public class Order
{
public int Id { get; private set; }
[Required]
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; }
[Required]
public int SushiId { get; private set; }
[Required]
public int ClientId { get; private set; }
[Required]
public int EmployeeId { get; private set; }
public static Order? Create(OrderBindingModel model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
Count = model.Count,
Sum = model.Sum,
ClientId = model.ClientId,
EmployeeId = model.EmployeeId,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
SushiId = model.SushiId,
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
ClientId = model.ClientId;
EmployeeId = model.EmployeeId;
Status = model.Status;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
SushiId = SushiId,
ClientId = ClientId,
EmployeeId = EmployeeId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
Id = Id,
};
}
}