ISEbd-21_Putilin_P.A._Preca.../PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Order.cs
2023-03-06 23:49:02 +04:00

88 lines
2.4 KiB
C#

using Microsoft.EntityFrameworkCore;
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantDataModels.Enums;
using PrecastConcretePlantDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
namespace PrecastConcretePlantDatabaseImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
[Required]
public int ReinforcedId { get; private set; }
[Required]
public int Count { get; private set; }
[Required]
public double Sum { get; private set; }
[Required]
public OrderStatus Status { get; private set; }
[Required]
public DateTime DateCreate { get; private set; }
public DateTime? DateImplement { get; private set; }
public Reinforced Reinforced { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
ReinforcedId = model.ReinforcedId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
Id = model.Id,
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
ReinforcedId = model.ReinforcedId;
Count = model.Count;
Sum = model.Sum;
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
Id = model.Id;
}
public OrderViewModel GetViewModel
{
get
{
var context = new PrecastConcretePlantDatabase();
return new()
{
ReinforcedName = Reinforced?.ReinforcedName ?? string.Empty,
ReinforcedId = ReinforcedId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
Id = Id,
};
}
}
}
}