PIbd-23-Volkov-N.A.-Compute.../ComputersShop/ComputersShopDataBaseImplement/Models/Order.cs

85 lines
2.1 KiB
C#
Raw Normal View History

2024-03-04 22:33:22 +04:00
using ComputersShopContracts.BindingModels;
using ComputersShopContracts.ViewModels;
using ComputersShopDataModels.Enums;
using ComputersShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
2024-04-01 20:00:17 +04:00
using System.Reflection.Metadata;
2024-03-04 22:33:22 +04:00
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopDataBaseImplement.Models
{
2024-04-14 16:11:19 +04:00
public class Order : IOrderModel
{
[Required]
public int ComputerId { get; set; }
[Required]
public int ClientId { get; private set; }
public int? ImplementerId { get; set; }
2024-03-04 22:33:22 +04:00
[Required]
2024-04-14 16:11:19 +04:00
public int Count { get; set; }
[Required]
public double Sum { get; set; }
[Required]
public OrderStatus Status { get; set; }
[Required]
public DateTime DateCreate { get; set; }
2024-03-04 22:33:22 +04:00
2024-04-14 16:11:19 +04:00
public DateTime? DateImplement { get; set; }
public virtual Computer Computer { get; set; }
public virtual Client Client { get; set; }
public virtual Implementer? Implementer { get; set; }
2024-03-04 22:33:22 +04:00
public int Id { get; set; }
2024-04-14 16:11:19 +04:00
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
ComputerId = model.ComputerId,
ClientId = model.ClientId,
ImplementerId = model.ImplementerId,
2024-03-04 22:33:22 +04:00
Count = model.Count,
2024-04-14 16:11:19 +04:00
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
};
}
2024-03-04 22:33:22 +04:00
2024-04-14 16:11:19 +04:00
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
ImplementerId = model.ImplementerId;
2024-03-04 22:33:22 +04:00
}
public OrderViewModel GetViewModel => new()
2024-04-14 16:11:19 +04:00
{
Id = Id,
ComputerId = ComputerId,
ClientId = ClientId,
ClientFIO = Client.ClientFIO,
2024-04-18 14:56:31 +04:00
ClientEmail = Client.Email,
2024-04-14 16:11:19 +04:00
ImplementerId = ImplementerId,
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty,
2024-03-04 22:33:22 +04:00
Count = Count,
2024-04-14 16:11:19 +04:00
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
ComputerName = Computer.ComputerName
};
}
2024-03-04 22:33:22 +04:00
}