ISEbd-21_Agliullov.D.A._Con.../ConfectionaryFileImplement/Order.cs

77 lines
2.2 KiB
C#
Raw Normal View History

using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.ViewModels;
using ConfectioneryDataModels.Enums;
using ConfectioneryDataModels.Models;
using System.Xml.Linq;
namespace ConfectioneryFileImplement
{
public class Order : IOrderModel
{
public int Id { get; private set; }
public int PastryId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; }
public DateTime DateCreate { get; private set; }
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
PastryId = model.PastryId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
Id = model.Id,
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
PastryId = model.PastryId;
Count = model.Count;
Sum = model.Sum;
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
Id = model.Id;
}
public OrderViewModel GetViewModel => new()
{
PastryId = PastryId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
Id = Id,
};
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("PastryId", PastryId),
new XElement("Count", Count),
new XElement("Sum", Sum.ToString()),
new XElement("Status", Status),
new XElement("DateCreate", DateCreate),
new XElement("DateImplement", DateImplement)
);
}
}