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