2024-03-26 18:50:50 +04:00
|
|
|
|
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
|
|
|
|
|
2024-03-26 18:50:50 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public int PlaneId { get; set; }
|
2024-03-26 21:23:10 +04:00
|
|
|
|
|
2024-04-22 23:18:25 +04:00
|
|
|
|
public virtual Plane Plane { get; set; } = new();
|
|
|
|
|
|
|
|
|
|
[Required]
|
|
|
|
|
public int ClientId { get; set; }
|
|
|
|
|
|
|
|
|
|
public Client Client { get; set; } = new();
|
|
|
|
|
|
2024-03-26 18:50:50 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public int Count { get; set; }
|
2024-03-26 21:23:10 +04:00
|
|
|
|
|
2024-03-26 18:50:50 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public double Sum { get; set; }
|
2024-03-26 21:23:10 +04:00
|
|
|
|
|
2024-03-26 18:50:50 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public OrderStatus Status { get; set; }
|
2024-03-26 21:23:10 +04:00
|
|
|
|
|
2024-03-26 18:50:50 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public DateTime DateCreate { get; set; }
|
2024-03-26 21:23:10 +04:00
|
|
|
|
|
2024-03-26 18:50:50 +04:00
|
|
|
|
public DateTime? DateImplement { get; set; }
|
2024-03-26 21:23:10 +04:00
|
|
|
|
|
2024-04-22 23:18:25 +04:00
|
|
|
|
public static Order? Create(AircraftPlantDatabase context, OrderBindingModel? model)
|
2024-03-26 18:50:50 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2024-03-26 21:23:10 +04:00
|
|
|
|
return new Order()
|
2024-03-26 18:50:50 +04:00
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
PlaneId = model.PlaneId,
|
2024-04-22 23:18:25 +04:00
|
|
|
|
Plane = context.Planes.First(x => x.Id == model.PlaneId),
|
|
|
|
|
ClientId = model.ClientId,
|
|
|
|
|
Client = context.Clients.First(x => x.Id == model.ClientId),
|
2024-03-26 18:50:50 +04:00
|
|
|
|
Count = model.Count,
|
|
|
|
|
Sum = model.Sum,
|
|
|
|
|
Status = model.Status,
|
|
|
|
|
DateCreate = model.DateCreate,
|
|
|
|
|
DateImplement = model.DateImplement
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-03-26 21:23:10 +04:00
|
|
|
|
|
2024-03-26 18:50:50 +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
|
|
|
|
|
2024-03-26 18:50:50 +04:00
|
|
|
|
public OrderViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
PlaneId = PlaneId,
|
2024-04-22 23:18:25 +04:00
|
|
|
|
PlaneName = Plane.PlaneName,
|
|
|
|
|
ClientId = ClientId,
|
|
|
|
|
ClientFIO = Client.ClientFIO,
|
2024-03-26 18:50:50 +04:00
|
|
|
|
Count = Count,
|
|
|
|
|
Sum = Sum,
|
|
|
|
|
Status = Status,
|
|
|
|
|
DateCreate = DateCreate,
|
2024-03-26 21:23:10 +04:00
|
|
|
|
DateImplement = DateImplement,
|
2024-03-26 18:50:50 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
2024-03-26 21:23:10 +04:00
|
|
|
|
}
|