PIbd-22_Chernyshev_G.J._30_.../GarmentFactoryDatabaseImplement/Models/Order.cs

81 lines
2.1 KiB
C#
Raw Normal View History

2024-03-20 10:21:07 +04:00
using GarmentFactoryContracts.BindingModels;
using GarmentFactoryContracts.ViewModels;
using GarmentFactoryDataModels.Enums;
using GarmentFactoryDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GarmentFactoryDatabaseImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; set; }
[Required]
public int TextileId { get; private set; }
[Required]
public int Count { get; 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? DateComplete { get; private set; }
// Для передачи названия изделия
public virtual Textile Textile { get; set; }
public static Order? Create(OrderBindingModel model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
TextileId = model.TextileId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateComplete = model.DateComplete,
};
}
public void Update(OrderBindingModel model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateComplete = model.DateComplete;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
TextileId = TextileId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateComplete = DateComplete,
TextileName = Textile.TextileName
};
}
}