2023-04-06 23:41:09 +04:00
|
|
|
|
using ComputerShopContracts.BindingModels;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
using ComputerShopDataModels.Enums;
|
|
|
|
|
using ComputerShopContracts.ViewModels;
|
|
|
|
|
using ComputerShopDataModels.Models;
|
|
|
|
|
|
|
|
|
|
namespace ComputerShopDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
internal class Order : IOrderModel
|
|
|
|
|
{
|
|
|
|
|
public int Id { 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.Now;
|
|
|
|
|
|
|
|
|
|
public DateTime? DateImplement { get; private set; }
|
|
|
|
|
[ForeignKey("OrderId")]
|
2023-05-20 00:08:47 +04:00
|
|
|
|
public virtual List<SupplyOrder> Supplies { get; set; } = new();
|
|
|
|
|
private Dictionary<int, IOrderModel>? _supplyOrders = null;
|
|
|
|
|
|
2023-04-07 16:53:49 +04:00
|
|
|
|
[ForeignKey("OrderId")]
|
|
|
|
|
public virtual List<AssemblyOrder> Assemblies { get; set; } = new();
|
2023-05-20 00:08:47 +04:00
|
|
|
|
private Dictionary<int, (IOrderModel, int)>? _assemblyOrders = null;
|
|
|
|
|
|
|
|
|
|
[NotMapped]
|
|
|
|
|
public Dictionary<int, (IOrderModel, int)> AssemblyOrders
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_assemblyOrders == null)
|
|
|
|
|
{
|
|
|
|
|
_assemblyOrders = Assemblies
|
|
|
|
|
.ToDictionary(recPC => recPC.AssemblyId, recPC =>
|
|
|
|
|
(recPC.Order as IOrderModel, recPC.Count));
|
|
|
|
|
}
|
|
|
|
|
return _assemblyOrders;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[NotMapped]
|
|
|
|
|
public Dictionary<int, IOrderModel> SupplyOrders
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_supplyOrders == null)
|
|
|
|
|
{
|
|
|
|
|
_supplyOrders = Supplies
|
|
|
|
|
.ToDictionary(recPC => recPC.SupplyId, recPC =>
|
|
|
|
|
(recPC.Order as IOrderModel));
|
|
|
|
|
}
|
|
|
|
|
return _supplyOrders;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 18:26:38 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public int ClientId { get; set; }
|
2023-04-06 23:41:09 +04:00
|
|
|
|
public static Order? Create(OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Order()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
Sum = model.Sum,
|
|
|
|
|
Status = model.Status,
|
|
|
|
|
DateCreate = model.DateCreate,
|
|
|
|
|
DateImplement = model.DateImplement,
|
2023-05-20 00:08:47 +04:00
|
|
|
|
ClientId = model.ClientId
|
2023-04-06 23:41:09 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public static Order Create(OrderViewModel model)
|
|
|
|
|
{
|
|
|
|
|
return new Order
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
Sum = model.Sum,
|
|
|
|
|
Status = model.Status,
|
|
|
|
|
DateCreate = model.DateCreate,
|
|
|
|
|
DateImplement = model.DateImplement,
|
2023-05-20 00:08:47 +04:00
|
|
|
|
ClientId = model.ClientId
|
2023-04-06 23:41:09 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public void Update(OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Status = model.Status;
|
|
|
|
|
DateImplement = model.DateImplement;
|
|
|
|
|
}
|
|
|
|
|
public OrderViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
Sum = Sum,
|
|
|
|
|
Status = Status,
|
|
|
|
|
DateCreate = DateCreate,
|
|
|
|
|
DateImplement = DateImplement,
|
2023-05-20 00:08:47 +04:00
|
|
|
|
ClientId = ClientId
|
2023-04-06 23:41:09 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|