PIbd-21_MasenkinMS_Aircraft.../AircraftPlant/AircraftPlantDatabaseImplement/Models/Order.cs
2024-03-10 01:33:27 +04:00

113 lines
2.9 KiB
C#

using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.ViewModels;
using AircraftPlantDataModels.Enums;
using AircraftPlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AircraftPlantDatabaseImplement.Models
{
/// <summary>
/// Сущность "Заказ"
/// </summary>
public class Order : IOrderModel
{
/// <summary>
/// Идентификатор
/// </summary>
public int Id { get; set; }
/// <summary>
/// Идентификатор изделия
/// </summary>
[Required]
public int PlaneId { get; set; }
/// <summary>
/// Количество изделий
/// </summary>
[Required]
public int Count { get; set; }
/// <summary>
/// Сумма заказа
/// </summary>
[Required]
public double Sum { get; set; }
/// <summary>
/// Статус заказа
/// </summary>
[Required]
public OrderStatus Status { get; set; }
/// <summary>
/// Дата создания заказа
/// </summary>
[Required]
public DateTime DateCreate { get; set; }
/// <summary>
/// Дата выполнения заказа
/// </summary>
public DateTime? DateImplement { get; set; }
/// <summary>
/// Создание модели заказа
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order
{
Id = model.Id,
PlaneId = model.PlaneId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
};
}
/// <summary>
/// Изменение модели заказа
/// </summary>
/// <param name="model"></param>
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
/// <summary>
/// Получение модели заказа
/// </summary>
public OrderViewModel GetViewModel => new()
{
Id = Id,
PlaneId = PlaneId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};
}
}