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

71 lines
2.1 KiB
C#
Raw Normal View History

2024-03-25 20:21:59 +04:00
using AbstractLawFirmContracts.BindingModels;
using AbstractLawFirmContracts.ViewModels;
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]
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; }
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,
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,
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 // Безопасное использование DocumentName
2024-03-25 20:21:59 +04:00
};
}
2024-04-09 23:28:01 +04:00
}