ISEbd-21_Zinovev_V.V._Furni.../FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs

86 lines
2.6 KiB
C#
Raw Normal View History

2024-05-04 20:14:41 +04:00
using FurnitureAssemblyContracts.BindingModels;
using FurnitureAssemblyContracts.ViewModels;
using FurnitureAssemblyDataModels.Enums;
using FurnitureAssemblyDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
2024-05-05 20:11:20 +04:00
using System.ComponentModel.DataAnnotations.Schema;
2024-05-04 20:14:41 +04:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureAssemblyDatabaseImplement.Models
{
public class Order : IOrderModel
{
2024-05-05 20:11:20 +04:00
[ForeignKey("ProductId")]
public int FurnitureId { get; set; }
2024-05-04 20:14:41 +04:00
[Required]
2024-05-05 20:11:20 +04:00
public int Count { get; set; }
2024-05-04 20:14:41 +04:00
[Required]
2024-05-05 20:11:20 +04:00
public double Sum { get; set; }
2024-05-04 20:14:41 +04:00
[Required]
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
[Required]
public DateTime DateCreate { get; private set; } = DateTime.Now.ToUniversalTime();
2024-05-05 20:11:20 +04:00
public DateTime? DateImplement { get; set; }
public int Id { get; set; }
[Required]
public int ClientId { get; private set; }
2024-05-05 23:58:51 +04:00
public int? ImplementerId { get; private set; }
2024-05-04 20:14:41 +04:00
2024-05-05 20:11:20 +04:00
public virtual Client Client { get; set; }
2024-05-04 20:14:41 +04:00
public virtual Furniture Furniture { get; set; }
2024-05-05 23:58:51 +04:00
public virtual Implementer? Implementer { get; set; }
2024-05-05 20:11:20 +04:00
public static Order? Create(OrderBindingModel? model)
2024-05-04 20:14:41 +04:00
{
return new Order()
{
Id = model.Id,
FurnitureId = model.FurnitureId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
2024-05-05 23:58:51 +04:00
ClientId = model.ClientId,
ImplementerId = model.ImplementerId
2024-05-04 20:14:41 +04:00
};
}
2024-05-05 20:11:20 +04:00
public void Update(OrderBindingModel? model)
2024-05-04 20:14:41 +04:00
{
if (model == null)
{
return;
}
2024-05-05 20:11:20 +04:00
Count = model.Count;
Sum = model.Sum;
2024-05-04 20:14:41 +04:00
Status = model.Status;
DateImplement = model.DateImplement;
2024-05-05 23:58:51 +04:00
ImplementerId = model.ImplementerId;
2024-05-04 20:14:41 +04:00
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
FurnitureId = FurnitureId,
2024-05-05 20:11:20 +04:00
FurnitureName = Furniture.FurnitureName,
2024-05-04 20:14:41 +04:00
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
2024-05-05 20:11:20 +04:00
ClientId = ClientId,
2024-05-05 23:58:51 +04:00
ClientFIO = Client.ClientFIO,
ImplementerId = ImplementerId,
ImplementerFIO = Implementer?.ImplementerFIO
2024-05-04 20:14:41 +04:00
};
2024-05-05 20:11:20 +04:00
2024-05-04 20:14:41 +04:00
}
}