ISEbd_21_Kuklew_M.I._Softwa.../SoftwareInstallationDatabaseImplement/Models/Order.cs
Максим Куклев ed3e400b30 загрузил
2024-06-17 19:27:42 +04:00

88 lines
2.7 KiB
C#

using System.ComponentModel.DataAnnotations;
using SoftwareInstallationContracts.BindingModels;
using SoftwareInstallationContracts.ViewModels;
using SoftwareInstallationDataModels.Enums;
using SoftwareInstallationDataModels.Models;
using System.Diagnostics;
using System.Runtime.Serialization;
namespace SoftwareInstallationDatabaseImplement.Models
{
[DataContract]
public class Order : IOrderModel
{
[DataMember]
public int Id { get; private set; }
[DataMember]
[Required]
public int Count { get; private set; }
[DataMember]
[Required]
public double Sum { get; private set; }
[DataMember]
[Required]
public OrderStatus Status { get; private set; }
[DataMember]
[Required]
public DateTime DateCreate { get; private set; }
[DataMember]
public DateTime? DateImplement { get; private set; }
[DataMember]
[Required]
public int RepairId { get; private set; }
public virtual Repair? Repair { get; private set; }
[DataMember]
[Required]
public int ClientId { get; private set; }
public virtual Client? Client { get; private set; }
[DataMember]
public int? ImplementerId { get; private set; } = null;
public virtual Implementer? Implementer { get; private set; }
public static Order? Create(OrderBindingModel model)
{
return new Order()
{
Id = model.Id,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
RepairId = model.RepairId,
ClientId = model.ClientId,
ImplementerId = model.ImplementerId,
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
ImplementerId = model.ImplementerId;
}
public OrderViewModel GetViewModel => new()
{
RepairId = RepairId,
ClientId = ClientId,
ImplementerId = ImplementerId,
RepairName = Repair?.RepairName ?? string.Empty,
ClientFIO = Client?.ClientFIO ?? string.Empty,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
Id = Id,
ImplementerFIO = (Implementer != null ? Implementer.ImplementerFIO : string.Empty)
};
}
}