89 lines
2.6 KiB
C#
89 lines
2.6 KiB
C#
using ElectronicsShopContracts.BindingModels;
|
||
using ElectronicsShopContracts.ViewModels;
|
||
using ElectronicsShopDataModels.Enums;
|
||
using ElectronicsShopDataModels.Models;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel.DataAnnotations;
|
||
using System.Diagnostics;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace ElectronicsShopDataBaseImplement.Models
|
||
{
|
||
public class Order : IOrderModel
|
||
{
|
||
public int ID { get; set; }
|
||
[Required]
|
||
public double Sum { get; set; }
|
||
[Required]
|
||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||
[Required]
|
||
public PaymeantOption PaymeantOption { get; set; } = PaymeantOption.Неизвестно;
|
||
[Required]
|
||
public DateTime DateCreate { get; set; }= DateTime.Now;
|
||
[Required]
|
||
public DateTime? DateImplemet { get; set; } = null;
|
||
[Required]
|
||
public Dictionary<int, (IProductModel, int)> ProductList { get; set; } = new();
|
||
|
||
public static Order? Create(OrderBindingModel? model)
|
||
{
|
||
if (model == null)
|
||
{
|
||
return null;
|
||
}
|
||
return new Order()
|
||
{
|
||
ID = model.ID,
|
||
Sum = model.Sum,
|
||
Status = model.Status,
|
||
PaymeantOption = model.PaymeantOption,
|
||
DateCreate = model.DateCreate,
|
||
//todo ProductList
|
||
};
|
||
}
|
||
public static Order? Create(OrderViewModel model)
|
||
{
|
||
return new Order
|
||
{
|
||
ID = model.ID,
|
||
Sum = model.Sum,
|
||
Status = model.Status,
|
||
PaymeantOption = model.PaymeantOption,
|
||
DateCreate = model.DateCreate,
|
||
//todo ProductList
|
||
};
|
||
}
|
||
public void Update(OrderBindingModel model)
|
||
{
|
||
if (model == null)
|
||
{
|
||
return;
|
||
}
|
||
ID = model.ID;
|
||
Sum = model.Sum;
|
||
PaymeantOption = model.PaymeantOption;
|
||
Status = model.Status;
|
||
DateCreate = model.DateCreate;
|
||
if (model.DateImplemet != null)
|
||
{
|
||
DateImplemet = model.DateImplemet;
|
||
}
|
||
//todo ProductList
|
||
}
|
||
|
||
public OrderViewModel GetViewModel => new()
|
||
{
|
||
ID = ID,
|
||
Sum = Sum,
|
||
PaymeantOption = PaymeantOption,
|
||
Status = Status,
|
||
DateCreate = DateCreate,
|
||
DateImplemet=DateImplemet,
|
||
ProductList = ProductList
|
||
};
|
||
}
|
||
}
|