PIbd-22_Safiulova_K.N._Airc.../AircraftPlant/AircraftPlantDatabaseImplement/Models/Order.cs

72 lines
1.8 KiB
C#
Raw Normal View History

using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.ViewModels;
using AircraftPlantDataModels.Enums;
using AircraftPlantDataModels.Models;
using System.ComponentModel.DataAnnotations;
namespace AircraftPlantDatabaseImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; set; }
2024-03-26 21:23:10 +04:00
[Required]
public int PlaneId { get; set; }
2024-03-26 21:23:10 +04:00
[Required]
public int Count { get; set; }
2024-03-26 21:23:10 +04:00
[Required]
public double Sum { get; set; }
2024-03-26 21:23:10 +04:00
[Required]
public OrderStatus Status { get; set; }
2024-03-26 21:23:10 +04:00
[Required]
public DateTime DateCreate { get; set; }
2024-03-26 21:23:10 +04:00
public DateTime? DateImplement { get; set; }
2024-03-26 21:23:10 +04:00
public virtual Plane Plane { get; set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
2024-03-26 21:23:10 +04:00
return new Order()
{
Id = model.Id,
PlaneId = model.PlaneId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
};
}
2024-03-26 21:23:10 +04:00
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
2024-03-26 21:23:10 +04:00
public OrderViewModel GetViewModel => new()
{
Id = Id,
PlaneId = PlaneId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
2024-03-26 21:23:10 +04:00
DateImplement = DateImplement,
PlaneName = Plane.PlaneName
};
}
2024-03-26 21:23:10 +04:00
}