60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
using ComputerHardwareStoreContracts.BindingModels;
|
||
using ComputerHardwareStoreContracts.ViewModels;
|
||
using ComputerHardwareStoreDataModels.Enums;
|
||
using ComputerHardwareStoreDataModels.Models;
|
||
using System.ComponentModel.DataAnnotations;
|
||
|
||
namespace ComputerHardwareStoreDatabaseImplement.Models
|
||
{
|
||
public class Order : IOrderModel
|
||
{
|
||
public int Id { get; private set; }
|
||
[Required]
|
||
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; }
|
||
[Required]
|
||
public int ProductId { get; private set; }
|
||
public virtual Product? Product { get; set; }
|
||
public static Order? Create(ComputerHardwareStoreDBContext context, OrderBindingModel model)
|
||
{
|
||
if (model == null)
|
||
{
|
||
return null;
|
||
}
|
||
return new Order()
|
||
{
|
||
Id = model.Id,
|
||
Sum = model.Sum,
|
||
Status = model.Status,
|
||
DateCreate = model.DateCreate,
|
||
DateImplement = model.DateImplement,
|
||
Product = context.Products.First(x => x.Id == model.ProductId)
|
||
};
|
||
}
|
||
public void Update(OrderBindingModel model)
|
||
{
|
||
if (model == null)
|
||
{
|
||
return;
|
||
}
|
||
Status = model.Status;
|
||
DateImplement = model.DateImplement;
|
||
}
|
||
public OrderViewModel GetViewModel => new()
|
||
{
|
||
Id = Id,
|
||
Sum = Sum,
|
||
Status = Status,
|
||
DateCreate = DateCreate,
|
||
DateImplement = DateImplement,
|
||
};
|
||
|
||
public Dictionary<int, (IProductModel, int)> OrderProduct => throw new NotImplementedException();
|
||
}
|