86 lines
2.3 KiB
C#
86 lines
2.3 KiB
C#
using FoodOrderDatabaseImplement.Models;
|
||
using FoodOrdersContracts.BindingModels;
|
||
using FoodOrdersContracts.ViewModels;
|
||
using FoodOrdersDataModel.Enums;
|
||
using FoodOrdersDataModel.Models;
|
||
using System.ComponentModel.DataAnnotations;
|
||
|
||
namespace FoodOrdersDatabaseImplement.Models
|
||
{
|
||
public class Order : IOrderModel
|
||
{
|
||
public int Id { get; private set; }
|
||
[Required]
|
||
public int FoodId { get; private set; }
|
||
public string FoodName { get; private set; } = string.Empty;
|
||
[Required]
|
||
public int ClientId { get; private set; }
|
||
public string ClientName { get; private set; } = string.Empty;
|
||
|
||
|
||
[Required]
|
||
public int Count { get; private set; }
|
||
|
||
[Required]
|
||
public double Sum { get; private set; }
|
||
|
||
[Required]
|
||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||
|
||
[Required]
|
||
public DateTime DateCreate { get; private set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||
|
||
public DateTime? DateImplement { get; private set; }
|
||
|
||
public virtual Food Food { get; private set; }
|
||
public virtual Client Client { get; private set; }
|
||
|
||
public static Order? Create(OrderBindingModel? model)
|
||
{
|
||
if (model == null)
|
||
{
|
||
return null;
|
||
}
|
||
|
||
return new Order()
|
||
{
|
||
Id = model.Id,
|
||
FoodId = model.FoodId,
|
||
FoodName = model.FoodName,
|
||
ClientId = model.ClientId,
|
||
ClientName = model.ClientName,
|
||
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,
|
||
FoodId = FoodId,
|
||
FoodName = FoodName,
|
||
ClientId = ClientId,
|
||
ClientName = ClientName,
|
||
Count = Count,
|
||
Sum = Sum,
|
||
Status = Status,
|
||
DateCreate = DateCreate,
|
||
DateImplement = DateImplement
|
||
};
|
||
}
|
||
}
|