2024-02-20 12:09:56 +04:00
|
|
|
|
using FurnitureAssemblyContracts.BindingModels;
|
|
|
|
|
using FurnitureAssemblyContracts.ViewModels;
|
|
|
|
|
using FurnitureAssemblyDataModels.Enums;
|
|
|
|
|
using FurnitureAssemblyDataModels.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
2024-05-14 11:56:24 +04:00
|
|
|
|
using System.Runtime.Serialization;
|
2024-02-20 12:09:56 +04:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
2024-04-29 18:59:10 +04:00
|
|
|
|
namespace FurnitureAssemblyFileImplement.Models
|
2024-02-20 12:09:56 +04:00
|
|
|
|
{
|
2024-05-14 11:56:24 +04:00
|
|
|
|
[DataContract]
|
2024-02-20 12:09:56 +04:00
|
|
|
|
public class Order : IOrderModel
|
|
|
|
|
{
|
2024-05-14 11:56:24 +04:00
|
|
|
|
[DataMember]
|
2024-02-20 12:09:56 +04:00
|
|
|
|
public int FurnitureId { get; private set; }
|
2024-05-14 11:56:24 +04:00
|
|
|
|
[DataMember]
|
2024-04-29 18:16:15 +04:00
|
|
|
|
public string FurnitureName { get; private set; } = string.Empty;
|
2024-05-14 11:56:24 +04:00
|
|
|
|
[DataMember]
|
2024-02-20 12:09:56 +04:00
|
|
|
|
public int Count { get; private set; }
|
2024-05-14 11:56:24 +04:00
|
|
|
|
[DataMember]
|
2024-02-20 12:09:56 +04:00
|
|
|
|
public double Sum { get; private set; }
|
2024-05-14 11:56:24 +04:00
|
|
|
|
[DataMember]
|
2024-02-20 12:09:56 +04:00
|
|
|
|
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
2024-05-14 11:56:24 +04:00
|
|
|
|
[DataMember]
|
2024-02-20 12:09:56 +04:00
|
|
|
|
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
2024-05-14 11:56:24 +04:00
|
|
|
|
[DataMember]
|
2024-02-20 12:09:56 +04:00
|
|
|
|
public DateTime? DateImplement { get; private set; }
|
2024-05-14 11:56:24 +04:00
|
|
|
|
[DataMember]
|
2024-04-29 18:16:15 +04:00
|
|
|
|
public int ClientId { get; private set; }
|
2024-05-14 11:56:24 +04:00
|
|
|
|
[DataMember]
|
2024-02-20 12:09:56 +04:00
|
|
|
|
public int Id { get; private set; }
|
2024-05-14 11:56:24 +04:00
|
|
|
|
[DataMember]
|
2024-04-29 18:59:10 +04:00
|
|
|
|
public int? ImplementerId { get; private set; } = null;
|
2024-02-20 12:09:56 +04:00
|
|
|
|
|
|
|
|
|
public static Order? Create(OrderBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Order()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
FurnitureId = model.FurnitureId,
|
|
|
|
|
Count = model.Count,
|
|
|
|
|
Sum = model.Sum,
|
|
|
|
|
Status = model.Status,
|
|
|
|
|
DateCreate = model.DateCreate,
|
2024-04-29 18:16:15 +04:00
|
|
|
|
DateImplement = model.DateImplement,
|
2024-04-29 18:59:10 +04:00
|
|
|
|
ClientId = model.ClientId,
|
|
|
|
|
ImplementerId = model.ImplementerId
|
2024-02-20 12:09:56 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Order? Create(XElement element)
|
|
|
|
|
{
|
|
|
|
|
if (element == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
var order = new Order()
|
|
|
|
|
{
|
|
|
|
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
|
|
|
|
FurnitureId = Convert.ToInt32(element.Element("FurnitureId")!.Value),
|
2024-04-29 18:16:15 +04:00
|
|
|
|
FurnitureName = element.Element("FurnitureName")!.Value,
|
2024-02-20 12:09:56 +04:00
|
|
|
|
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
|
|
|
|
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
2024-04-29 18:16:15 +04:00
|
|
|
|
DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null),
|
2024-04-29 18:59:10 +04:00
|
|
|
|
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
|
|
|
|
|
ImplementerId = Convert.ToInt32(element.Element("ImplementerId")?.Value)
|
2024-02-20 12:09:56 +04:00
|
|
|
|
};
|
|
|
|
|
DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl);
|
|
|
|
|
|
|
|
|
|
order.DateImplement = dateImpl;
|
|
|
|
|
|
|
|
|
|
if (!Enum.TryParse(element.Element("Status")!.Value, out OrderStatus status))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
order.Status = status;
|
|
|
|
|
return order;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(OrderBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Status = model.Status;
|
|
|
|
|
DateImplement = model.DateImplement;
|
2024-04-29 18:59:10 +04:00
|
|
|
|
ImplementerId = model.ImplementerId;
|
2024-02-20 12:09:56 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public OrderViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
FurnitureId = FurnitureId,
|
2024-04-29 18:16:15 +04:00
|
|
|
|
FurnitureName = FurnitureName,
|
2024-02-20 12:09:56 +04:00
|
|
|
|
Count = Count,
|
|
|
|
|
Sum = Sum,
|
|
|
|
|
Status = Status,
|
|
|
|
|
DateCreate = DateCreate,
|
2024-04-29 18:16:15 +04:00
|
|
|
|
DateImplement = DateImplement,
|
2024-04-29 18:59:10 +04:00
|
|
|
|
ClientId = ClientId,
|
|
|
|
|
ImplementerId = ImplementerId
|
2024-02-20 12:09:56 +04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public XElement GetXElement => new("Order",
|
|
|
|
|
new XAttribute("Id", Id),
|
2024-04-29 18:16:15 +04:00
|
|
|
|
new XElement("ClientId", ClientId),
|
2024-02-20 12:09:56 +04:00
|
|
|
|
new XElement("FurnitureId", FurnitureId),
|
2024-04-29 18:16:15 +04:00
|
|
|
|
new XElement("FurnitureName", FurnitureName),
|
2024-02-20 12:09:56 +04:00
|
|
|
|
new XElement("Count", Count.ToString()),
|
|
|
|
|
new XElement("Sum", Sum.ToString()),
|
|
|
|
|
new XElement("Status", Status.ToString()),
|
|
|
|
|
new XElement("DateCreate", DateCreate.ToString()),
|
2024-04-29 18:59:10 +04:00
|
|
|
|
new XElement("DateImplement", DateImplement.ToString()),
|
|
|
|
|
new XElement("ImplemwenterId", ImplementerId.ToString()));
|
2024-02-20 12:09:56 +04:00
|
|
|
|
}
|
|
|
|
|
}
|