PIbd-23-Yunusov-N.N.-CarRep.../CarRepairShop/CarRepairShopDatabaseImplement/Models/Order.cs

68 lines
2.1 KiB
C#
Raw Normal View History

2024-03-14 18:53:30 +04:00
using CarRepairShopContracts.BindingModels;
using CarRepairShopContracts.ViewModels;
using CarRepairShopDataModels.Enums;
using System.ComponentModel.DataAnnotations;
namespace CarRepairShopDatabaseImplement.Models
{
public class Order
{
public int Id { 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; }
[Required]
public int RepairId { get; private set; }
2024-04-06 19:58:28 +04:00
public virtual Repair? Repairs { get; private set; }
[Required]
public int ClientId { get; private set; }
public virtual Client? Client { get; private set; }
2024-03-25 21:45:56 +04:00
public virtual Repair? Repair { get; set; }
2024-03-14 18:53:30 +04:00
2024-03-24 21:23:30 +04:00
public static Order? Create(OrderBindingModel model)
2024-03-14 18:53:30 +04:00
{
return new Order()
{
Id = model.Id,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
RepairId = model.RepairId,
2024-04-06 19:58:28 +04:00
ClientId = model.ClientId,
2024-03-14 18:53:30 +04:00
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
RepairId = RepairId,
2024-04-06 19:58:28 +04:00
ClientId = ClientId,
2024-03-25 21:45:56 +04:00
RepairName = Repair?.RepairName ?? string.Empty,
2024-04-06 19:58:28 +04:00
ClientFIO = Client?.ClientFIO ?? string.Empty,
2024-03-14 18:53:30 +04:00
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
2024-03-24 20:29:38 +04:00
Id = Id
2024-03-14 18:53:30 +04:00
};
}
}