PIbd-23_Vrazhkin_S_A_Furnit.../FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs

83 lines
2.3 KiB
C#
Raw Normal View History

2024-03-05 13:13:35 +04:00
using FurnitureAssemblyContracts.BindingModels;
using FurnitureAssemblyContracts.ViewModels;
using FurnitureAssemblyDataModels.Enums;
using FurnitureAssemblyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
2024-04-29 18:16:15 +04:00
using System.Reflection;
2024-03-05 13:13:35 +04:00
using System.Text;
using System.Threading.Tasks;
2024-04-29 18:16:15 +04:00
using System.Xml.Linq;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
2024-03-05 13:13:35 +04:00
namespace FurnitureAssemblyDatabaseImplement.Models
{
public class Order : IOrderModel
{
2024-04-29 18:16:15 +04:00
[ForeignKey("ProductId")]
public int FurnitureId { get; set; }
2024-03-05 13:13:35 +04:00
[Required]
2024-04-29 18:16:15 +04:00
public int Count { get; set; }
2024-03-05 13:13:35 +04:00
[Required]
2024-04-29 18:16:15 +04:00
public double Sum { get; set; }
2024-03-05 13:13:35 +04:00
[Required]
2024-04-29 18:16:15 +04:00
public OrderStatus Status { get; set; }
2024-03-05 13:13:35 +04:00
[Required]
2024-04-29 18:16:15 +04:00
public DateTime DateCreate { get; set; }
2024-03-05 13:13:35 +04:00
2024-04-29 18:16:15 +04:00
public DateTime? DateImplement { get; set; }
2024-03-05 13:13:35 +04:00
2024-04-29 18:16:15 +04:00
public int Id { get; set; }
[Required]
public int ClientId { get; private set; }
public virtual Client Client { get; set; }
2024-03-05 13:13:35 +04:00
public virtual Furniture Furniture { get; set; }
public static Order? Create(OrderBindingModel? model)
{
return new Order()
{
Id = model.Id,
FurnitureId = model.FurnitureId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
2024-04-29 18:16:15 +04:00
DateImplement = model.DateImplement,
ClientId = model.ClientId
2024-03-05 13:13:35 +04:00
};
}
2024-04-29 18:16:15 +04:00
public void Update(OrderBindingModel? model)
2024-03-05 13:13:35 +04:00
{
if (model == null)
{
return;
}
2024-04-29 18:16:15 +04:00
Count = model.Count;
Sum = model.Sum;
2024-03-05 13:13:35 +04:00
Status = model.Status;
DateImplement = model.DateImplement;
}
2024-04-29 18:16:15 +04:00
2024-03-05 13:13:35 +04:00
public OrderViewModel GetViewModel => new()
{
Id = Id,
FurnitureId = FurnitureId,
FurnitureName = Furniture.FurnitureName,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
2024-04-29 18:16:15 +04:00
DateImplement = DateImplement,
ClientId = ClientId,
ClientFIO = Client.ClientFIO
2024-03-05 13:13:35 +04:00
};
}
}