PIbd-23_Leonteva_V._A._LawFirm/LawFirm/LawFirmDatabaseImplement/Models/Order.cs

90 lines
2.6 KiB
C#
Raw Normal View History

2024-04-23 12:07:00 +04:00
using LawFirmContracts.BindingModels;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Enums;
using LawFirmDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
2024-06-19 23:52:53 +04:00
using System.Runtime.Serialization;
2024-04-23 12:07:00 +04:00
namespace LawFirmDatabaseImplement.Models
{
2024-06-19 23:52:53 +04:00
[DataContract]
public class Order : IOrderModel
2024-04-23 12:07:00 +04:00
{
[Required]
2024-06-19 23:52:53 +04:00
[DataMember]
public int DocumentId { get; set; }
[Required]
2024-06-19 23:52:53 +04:00
[DataMember]
public int ClientId { get; private set; }
[Required]
2024-06-19 23:52:53 +04:00
[DataMember]
public int Count { get; set; }
2024-04-23 12:07:00 +04:00
[Required]
2024-06-19 23:52:53 +04:00
[DataMember]
public double Sum { get; set; }
2024-04-23 12:07:00 +04:00
[Required]
2024-06-19 23:52:53 +04:00
[DataMember]
public OrderStatus Status { get; set; }
2024-04-23 12:07:00 +04:00
[Required]
2024-06-19 23:52:53 +04:00
[DataMember]
public DateTime DateCreate { get; set; }
[DataMember]
public int? ImplementerId { get; private set; }
[DataMember]
public DateTime? DateImplement { get; set; }
2024-04-23 12:07:00 +04:00
public virtual Document Document { get; set; }
public virtual Client Client { get; set; }
2024-05-24 18:50:45 +04:00
public virtual Implementer? Implementer { get; private set; }
public int Id { get; set; }
public static Order? Create(OrderBindingModel? model)
2024-04-23 12:07:00 +04:00
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
DocumentId = model.DocumentId,
ClientId = model.ClientId,
Count = model.Count,
2024-04-23 12:07:00 +04:00
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
2024-05-24 18:50:45 +04:00
DateImplement = model.DateImplement,
ImplementerId = model.ImplementerId,
2024-04-23 12:07:00 +04:00
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
2024-05-24 18:50:45 +04:00
DocumentId = model.DocumentId;
Count = model.Count;
Sum = model.Sum;
2024-04-23 12:07:00 +04:00
Status = model.Status;
2024-05-24 18:50:45 +04:00
DateCreate = model.DateCreate;
2024-04-23 12:07:00 +04:00
DateImplement = model.DateImplement;
2024-05-24 18:50:45 +04:00
ImplementerId = model.ImplementerId;
Id = model.Id;
2024-04-23 12:07:00 +04:00
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
DocumentId = DocumentId,
ClientId = ClientId,
ClientFIO = Client.ClientFIO,
2024-05-24 18:50:45 +04:00
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty,
Count = Count,
2024-04-23 12:07:00 +04:00
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
2024-05-24 18:50:45 +04:00
DocumentName = Document.DocumentName,
ImplementerId = ImplementerId,
2024-04-23 12:07:00 +04:00
};
}
}