74 lines
2.1 KiB
C#
74 lines
2.1 KiB
C#
using SoftwareInstallationContracts.BindingModels;
|
||
using SoftwareInstallationContracts.ViewModels;
|
||
using SoftwareInstallationDataModels.Enums;
|
||
using SoftwareInstallationDataModels.Models;
|
||
using System.ComponentModel.DataAnnotations;
|
||
using System.Diagnostics;
|
||
|
||
namespace SoftwareInstallationDatabaseImplement.Models
|
||
{
|
||
public class Order : IOrderModel
|
||
{
|
||
public int Id { get; private set; }
|
||
|
||
[Required]
|
||
public int PackageId { get; private set; }
|
||
|
||
public virtual Package Package { get; set; } = new();
|
||
|
||
[Required]
|
||
public int Count { get; private set; }
|
||
|
||
[Required]
|
||
public double Sum { get; private set; }
|
||
|
||
[Required]
|
||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||
|
||
[Required]
|
||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||
|
||
public DateTime? DateImplement { get; private set; }
|
||
[Required]
|
||
public int TravelId { get; private set; }
|
||
public virtual Travel Travel { get; private set; }
|
||
|
||
public static Order Create(SoftwareInstallationDatabase context, OrderBindingModel model)
|
||
{
|
||
return new Order()
|
||
{
|
||
Id = model.Id,
|
||
PackageId = model.PackageId,
|
||
Package = context.Packages.First(x => x.Id == model.PackageId),
|
||
Count = model.Count,
|
||
Sum = model.Sum,
|
||
Status = model.Status,
|
||
DateCreate = model.DateCreate,
|
||
DateImplement = model.DateImplement,
|
||
};
|
||
}
|
||
|
||
public void Update(OrderBindingModel? model)
|
||
{
|
||
if (model == null)
|
||
{
|
||
return;
|
||
}
|
||
Status = model.Status;
|
||
DateImplement = model.DateImplement;
|
||
}
|
||
|
||
public OrderViewModel GetViewModel => new()
|
||
{
|
||
Id = Id,
|
||
PackageId = PackageId,
|
||
PackageName = Package.PackageName,
|
||
Count = Count,
|
||
Sum = Sum,
|
||
Status = Status,
|
||
DateCreate = DateCreate,
|
||
DateImplement = DateImplement,
|
||
};
|
||
}
|
||
}
|