2024-03-17 21:00:26 +04:00
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using FishFactoryDataModel.Enums;
|
|
|
|
|
using FishFactoryContracts.BindingModels;
|
|
|
|
|
using FishFactoryContracts.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace FishFactoryDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Order
|
|
|
|
|
{
|
2024-03-19 20:55:45 +04:00
|
|
|
|
public int Id { get; private set; }
|
2024-03-17 21:00:26 +04:00
|
|
|
|
[Required]
|
2024-03-19 20:55:45 +04:00
|
|
|
|
public int CannedId { get; private set; }
|
2024-03-17 21:00:26 +04:00
|
|
|
|
public virtual Canned Canned { get; set; } = new();
|
|
|
|
|
[Required]
|
2024-03-19 20:55:45 +04:00
|
|
|
|
public int Count { get; private set; }
|
2024-03-17 21:00:26 +04:00
|
|
|
|
[Required]
|
2024-03-19 20:55:45 +04:00
|
|
|
|
public double Sum { get; private set; }
|
2024-03-17 21:00:26 +04:00
|
|
|
|
[Required]
|
2024-03-19 20:55:45 +04:00
|
|
|
|
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
2024-03-17 21:00:26 +04:00
|
|
|
|
[Required]
|
2024-03-19 20:55:45 +04:00
|
|
|
|
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
|
|
|
|
public DateTime? DateImplement { get; private set; }
|
2024-03-17 21:00:26 +04:00
|
|
|
|
public static Order Create (FishFactoryDatabase context, OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
return new Order()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
CannedId = model.CannedId,
|
|
|
|
|
Count = model.Count,
|
|
|
|
|
Sum = model.Sum,
|
|
|
|
|
Status = model.Status,
|
|
|
|
|
DateCreate = model.DateCreate,
|
|
|
|
|
DateImplement = model.DateImplement,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public void Update(OrderBindingModel model)
|
|
|
|
|
{
|
2024-03-19 20:55:45 +04:00
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Id = model.Id;
|
|
|
|
|
CannedId = model.CannedId;
|
|
|
|
|
Sum = model.Sum;
|
2024-03-17 21:00:26 +04:00
|
|
|
|
Status = model.Status;
|
2024-03-19 20:55:45 +04:00
|
|
|
|
DateCreate = model.DateCreate;
|
2024-03-17 21:00:26 +04:00
|
|
|
|
DateImplement = model.DateImplement;
|
|
|
|
|
}
|
|
|
|
|
public OrderViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
CannedId = CannedId,
|
|
|
|
|
CannedName = Canned.CannedName,
|
|
|
|
|
Count = Count,
|
|
|
|
|
Sum = Sum,
|
|
|
|
|
Status = Status,
|
|
|
|
|
DateCreate = DateCreate,
|
|
|
|
|
DateImplement = DateImplement,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|