65 lines
2.1 KiB
C#
65 lines
2.1 KiB
C#
using System.ComponentModel.DataAnnotations.Schema;
|
||
using System.ComponentModel.DataAnnotations;
|
||
using FishFactoryDataModel.Enums;
|
||
using FishFactoryContracts.BindingModels;
|
||
using FishFactoryContracts.ViewModels;
|
||
using FishFactoryDataModel.Models;
|
||
|
||
namespace FishFactoryDatabaseImplement.Models
|
||
{
|
||
public class Order : IOrderModel
|
||
{
|
||
public int Id { get; private set; }
|
||
[Required]
|
||
public int CannedId { get; private set; }
|
||
public virtual Canned Canned { 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; }
|
||
public static Order Create (FishFactoryDatabase context, OrderBindingModel model)
|
||
{
|
||
return new Order()
|
||
{
|
||
Id = model.Id,
|
||
CannedId = model.CannedId,
|
||
Canned = context.Canneds.First(x => x.Id == model.CannedId),
|
||
Count = model.Count,
|
||
Sum = model.Sum,
|
||
Status = model.Status,
|
||
DateCreate = model.DateCreate,
|
||
DateImplement = model.DateImplement,
|
||
};
|
||
}
|
||
public void Update(OrderBindingModel model)
|
||
{
|
||
if (model == null)
|
||
{
|
||
return;
|
||
}
|
||
Id = model.Id;
|
||
CannedId = model.CannedId;
|
||
Sum = model.Sum;
|
||
Status = model.Status;
|
||
DateCreate = model.DateCreate;
|
||
DateImplement = model.DateImplement;
|
||
}
|
||
public OrderViewModel GetViewModel => new()
|
||
{
|
||
Id = Id,
|
||
CannedId = CannedId,
|
||
CannedName = Canned.CannedName,
|
||
Count = Count,
|
||
Sum = Sum,
|
||
Status = Status,
|
||
DateCreate = DateCreate,
|
||
DateImplement = DateImplement,
|
||
};
|
||
}
|
||
}
|