2024-03-09 21:37:08 +04:00
|
|
|
|
using SushiBarContracts.BindingModel;
|
|
|
|
|
using SushiBarContracts.ViewModels;
|
|
|
|
|
using SushiBarDataModels;
|
|
|
|
|
using SushiBarDataModels.Enums;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
|
|
|
|
|
namespace SushiBarDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Order : IOrderModel
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; set; }
|
2024-04-06 21:47:06 +04:00
|
|
|
|
|
2024-03-09 21:37:08 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public int SushiId { get; set; }
|
2024-04-06 21:47:06 +04:00
|
|
|
|
|
2024-03-09 21:37:08 +04:00
|
|
|
|
[Required]
|
2024-04-06 15:55:02 +04:00
|
|
|
|
public int ClientId { get; set; }
|
2024-04-06 21:47:06 +04:00
|
|
|
|
|
2024-04-06 15:55:02 +04:00
|
|
|
|
[Required]
|
2024-03-09 21:37:08 +04:00
|
|
|
|
public int Count { get; set; }
|
2024-04-06 21:47:06 +04:00
|
|
|
|
|
2024-03-09 21:37:08 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public double Sum { get; set; }
|
2024-04-06 21:47:06 +04:00
|
|
|
|
|
2024-03-09 21:37:08 +04:00
|
|
|
|
[Required]
|
2024-04-06 21:47:06 +04:00
|
|
|
|
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
|
|
|
|
|
2024-03-09 21:37:08 +04:00
|
|
|
|
[Required]
|
2024-04-06 21:47:06 +04:00
|
|
|
|
public DateTime DateCreate { get; set; } = DateTime.Now;
|
2024-03-09 21:37:08 +04:00
|
|
|
|
public DateTime? DateImplement { get; set; }
|
|
|
|
|
|
2024-04-06 21:47:06 +04:00
|
|
|
|
public virtual Client Client { get; set; }
|
|
|
|
|
|
|
|
|
|
public virtual Sushi Sushi { get; set; }
|
|
|
|
|
|
2024-03-09 21:37:08 +04:00
|
|
|
|
public static Order? Create(OrderBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Order()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
SushiId = model.SushiId,
|
|
|
|
|
Count = model.Count,
|
|
|
|
|
Sum = model.Sum,
|
|
|
|
|
Status = model.Status,
|
|
|
|
|
DateCreate = model.DateCreate,
|
2024-04-06 15:55:02 +04:00
|
|
|
|
DateImplement = model.DateImplement,
|
|
|
|
|
ClientId = model.ClientId
|
2024-03-09 21:37:08 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Status = model.Status;
|
|
|
|
|
DateImplement = model.DateImplement;
|
|
|
|
|
}
|
|
|
|
|
public OrderViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
SushiId = SushiId,
|
|
|
|
|
Count = Count,
|
|
|
|
|
Sum = Sum,
|
|
|
|
|
Status = Status,
|
|
|
|
|
DateCreate = DateCreate,
|
|
|
|
|
DateImplement = DateImplement,
|
2024-04-06 17:22:40 +04:00
|
|
|
|
ClientId = ClientId,
|
2024-04-06 21:47:06 +04:00
|
|
|
|
ClientFIO = Client.ClientFIO
|
2024-03-09 21:37:08 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|