ComputerHardwareStore_YouAr.../ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Models/Order.cs

66 lines
1.6 KiB
C#
Raw Normal View History

2024-04-29 21:02:20 +04:00
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.ViewModels;
using ComputerHardwareStoreDataModels.Enums;
using ComputerHardwareStoreDataModels.Models;
using System.ComponentModel.DataAnnotations;
2024-04-30 17:05:42 +04:00
using System.ComponentModel.DataAnnotations.Schema;
2024-04-29 21:02:20 +04:00
namespace ComputerHardwareStoreDatabaseImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
2024-05-30 07:44:40 +04:00
[Required]
public int ProductId { get; set; }
public virtual Product Product { get; set; } = null!;
[Required]
2024-04-29 21:02:20 +04:00
public int Count { get; set; }
[Required]
public double Sum { get; set; }
[Required]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
[Required]
public DateTime DateCreate { get; set; } = DateTime.Now;
public DateTime? DateImplement { get; set; }
2024-04-30 17:05:42 +04:00
2024-05-30 07:44:40 +04:00
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
ProductId = model.ProductId,
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,
ProductId = ProductId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
ProductName = Product.Name
};
}
2024-04-30 17:05:42 +04:00
}