2024-03-09 21:37:08 +04:00
|
|
|
|
using SushiBarContracts.BindingModel;
|
|
|
|
|
using SushiBarContracts.ViewModels;
|
|
|
|
|
using SushiBarDataModels;
|
|
|
|
|
using SushiBarDataModels.Enums;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2024-05-17 21:19:15 +04:00
|
|
|
|
using System.Runtime.Serialization;
|
2024-03-09 21:37:08 +04:00
|
|
|
|
|
|
|
|
|
namespace SushiBarDatabaseImplement.Models
|
|
|
|
|
{
|
2024-05-17 21:19:15 +04:00
|
|
|
|
[DataContract]
|
2024-03-09 21:37:08 +04:00
|
|
|
|
public class Order : IOrderModel
|
|
|
|
|
{
|
2024-05-17 21:19:15 +04:00
|
|
|
|
[DataMember]
|
2024-03-09 21:37:08 +04:00
|
|
|
|
public int Id { get; set; }
|
2024-04-06 21:47:06 +04:00
|
|
|
|
|
2024-05-17 21:19:15 +04:00
|
|
|
|
[DataMember]
|
2024-03-09 21:37:08 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public int SushiId { get; set; }
|
2024-04-06 21:47:06 +04:00
|
|
|
|
|
2024-05-17 21:19:15 +04:00
|
|
|
|
[DataMember]
|
2024-03-09 21:37:08 +04:00
|
|
|
|
[Required]
|
2024-04-06 15:55:02 +04:00
|
|
|
|
public int ClientId { get; set; }
|
2024-05-17 21:19:15 +04:00
|
|
|
|
|
|
|
|
|
[DataMember]
|
2024-04-20 20:00:18 +04:00
|
|
|
|
public int? ImplementerId { get; set; }
|
2024-04-06 21:47:06 +04:00
|
|
|
|
|
2024-05-17 21:19:15 +04:00
|
|
|
|
[DataMember]
|
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-05-17 21:19:15 +04:00
|
|
|
|
[DataMember]
|
2024-03-09 21:37:08 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public double Sum { get; set; }
|
2024-04-06 21:47:06 +04:00
|
|
|
|
|
2024-05-17 21:19:15 +04:00
|
|
|
|
[DataMember]
|
2024-03-09 21:37:08 +04:00
|
|
|
|
[Required]
|
2024-04-06 21:47:06 +04:00
|
|
|
|
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
|
|
|
|
|
2024-05-17 21:19:15 +04:00
|
|
|
|
[DataMember]
|
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-05-17 21:19:15 +04:00
|
|
|
|
|
|
|
|
|
[DataMember]
|
2024-03-09 21:37:08 +04:00
|
|
|
|
public DateTime? DateImplement { get; set; }
|
2024-05-17 21:19:15 +04:00
|
|
|
|
|
2024-04-20 23:14:21 +04:00
|
|
|
|
public virtual Client? Client { get; set; }
|
2024-04-20 20:00:18 +04:00
|
|
|
|
public virtual Implementer? Implementer { get; set; }
|
2024-04-20 23:14:21 +04:00
|
|
|
|
public virtual Sushi? Sushi { get; set; }
|
2024-04-06 21:47:06 +04:00
|
|
|
|
|
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,
|
2024-04-20 20:00:18 +04:00
|
|
|
|
ClientId = model.ClientId,
|
|
|
|
|
ImplementerId = model.ImplementerId,
|
2024-03-09 21:37:08 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
2024-05-17 21:19:15 +04:00
|
|
|
|
|
2024-03-09 21:37:08 +04:00
|
|
|
|
public void Update(OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Status = model.Status;
|
|
|
|
|
DateImplement = model.DateImplement;
|
2024-04-20 20:00:18 +04:00
|
|
|
|
ImplementerId = model.ImplementerId;
|
2024-03-09 21:37:08 +04:00
|
|
|
|
}
|
|
|
|
|
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-05-17 21:19:15 +04:00
|
|
|
|
ImplementerId = ImplementerId,
|
2024-04-21 12:28:36 +04:00
|
|
|
|
SushiName = Sushi?.SushiName ?? string.Empty,
|
2024-04-20 20:00:18 +04:00
|
|
|
|
ClientFIO = Client?.ClientFIO ?? string.Empty,
|
|
|
|
|
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty
|
2024-03-09 21:37:08 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|