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

82 lines
2.2 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
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();
[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
2024-04-22 23:18:25 +04:00
public static Order? Create(AircraftPlantDatabase context, OrderBindingModel? model)
{
if (model == null)
{
return null;
}
2024-03-26 21:23:10 +04:00
return new Order()
{
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),
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,
2024-04-22 23:18:25 +04:00
PlaneName = Plane.PlaneName,
ClientId = ClientId,
ClientFIO = Client.ClientFIO,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
2024-03-26 21:23:10 +04:00
DateImplement = DateImplement,
};
}
2024-03-26 21:23:10 +04:00
}