PIbd-22_Petrushin_E.A._LawFirm/LawFirm/AbstractLawFirmDatabaseImplement/Models/Order.cs

83 lines
2.7 KiB
C#
Raw Normal View History

2024-03-25 20:21:59 +04:00
using AbstractLawFirmContracts.BindingModels;
using AbstractLawFirmContracts.ViewModels;
using AbstractLawFirmDataBaseImplement.Models;
2024-03-25 20:21:59 +04:00
using AbstractLawFirmDataModels.Enums;
using AbstractLawFirmDataModels.Models;
using System;
using System.Collections.Generic;
2024-04-09 23:28:01 +04:00
using System.ComponentModel.DataAnnotations;
2024-03-25 20:21:59 +04:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2024-04-09 23:28:01 +04:00
namespace AbstractLawFirmDatabaseImplement.Models
2024-03-25 20:21:59 +04:00
{
public class Order : IOrderModel
{
public int Id { get; private set; }
2024-04-09 23:28:01 +04:00
[Required]
2024-03-25 20:21:59 +04:00
public int DocumentId { get; private set; }
2024-04-09 23:28:01 +04:00
[Required]
public int ClientId { get; private set; }
2024-05-05 10:58:53 +04:00
public int? ImplementerId { get; private set; }
[Required]
2024-03-25 20:21:59 +04:00
public int Count { get; private set; }
2024-04-09 23:28:01 +04:00
[Required]
2024-03-25 20:21:59 +04:00
public double Sum { get; private set; }
2024-04-09 23:28:01 +04:00
[Required]
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
[Required]
public DateTime DateCreate { get; private set; } = DateTime.Now;
2024-03-25 20:21:59 +04:00
public DateTime? DateImplement { get; private set; }
2024-04-09 23:28:01 +04:00
public virtual Document Document { get; set; }
public virtual Client Client { get; set; }
2024-05-05 10:58:53 +04:00
public Implementer? Implementer { get; private set; }
2024-04-09 23:28:01 +04:00
2024-03-25 20:21:59 +04:00
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
2024-04-09 23:28:01 +04:00
return new Order
2024-03-25 20:21:59 +04:00
{
DocumentId = model.DocumentId,
ClientId = model.ClientId,
2024-05-05 10:58:53 +04:00
ImplementerId = model.ImplementerId,
2024-03-25 20:21:59 +04:00
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
2024-04-09 23:28:01 +04:00
Id = model.Id,
2024-03-25 20:21:59 +04:00
};
}
2024-04-09 23:28:01 +04:00
2024-03-25 20:21:59 +04:00
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
2024-04-09 23:28:01 +04:00
public OrderViewModel GetViewModel => new OrderViewModel
2024-03-25 20:21:59 +04:00
{
DocumentId = DocumentId,
ClientId = ClientId,
2024-05-05 10:58:53 +04:00
ImplementerId = ImplementerId,
2024-03-25 20:21:59 +04:00
Count = Count,
Sum = Sum,
DateCreate = DateCreate,
DateImplement = DateImplement,
2024-04-09 23:28:01 +04:00
Id = Id,
Status = Status,
DocumentName = Document?.DocumentName ?? string.Empty,
2024-05-05 10:58:53 +04:00
ClientFIO = Client?.ClientFIO ?? string.Empty,
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty,
2024-03-25 20:21:59 +04:00
};
}
2024-04-09 23:28:01 +04:00
}