PIbd-21_Ihonkina_E.S._Preca.../PrecastConcretePlantDataBaseImplemet/Models/Order.cs

90 lines
3.0 KiB
C#
Raw Normal View History

2023-03-18 19:33:11 +04:00
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantDataModels.Enums;
using PrecastConcretePlantDataModels.Models;
using System;
2023-03-18 18:19:08 +04:00
using System.Collections.Generic;
2023-03-18 19:33:11 +04:00
using System.ComponentModel.DataAnnotations;
2023-03-18 18:19:08 +04:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2023-03-18 19:33:11 +04:00
namespace PrecastConcretePlantDatabaseImplement.Models
2023-03-18 18:19:08 +04:00
{
2023-03-18 19:33:11 +04:00
public class Order : IOrderModel
2023-03-18 18:19:08 +04:00
{
2023-03-18 19:33:11 +04:00
public int Id { get; private set; }
[Required]
2023-04-05 00:55:08 +04:00
public int ClientId { get; set; }
[Required]
2023-03-18 19:33:11 +04:00
public int ReinforcedId { get; private set; }
[Required]
public int Count { get; private set; }
2023-04-19 23:48:32 +04:00
public int? ImplementerId { get; set; }
2023-03-18 19:33:11 +04:00
[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? DateImplement { get; private set; }
public virtual Reinforced Reinforced { get; set; }
2023-04-05 00:55:08 +04:00
public virtual Client Client { get; set; }
2023-04-19 23:48:32 +04:00
public virtual Implementer? Implementer { get; set; }
public static Order? Create(OrderBindingModel? model)
2023-03-18 19:33:11 +04:00
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
2023-04-05 00:55:08 +04:00
ClientId=model.ClientId,
2023-03-18 19:33:11 +04:00
ReinforcedId = model.ReinforcedId,
2023-04-19 23:48:32 +04:00
ImplementerId = model.ImplementerId,
2023-03-18 19:33:11 +04:00
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
};
}
public void Update(OrderBindingModel model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
2023-04-28 22:24:51 +04:00
ImplementerId = model.ImplementerId;
2023-03-18 19:33:11 +04:00
}
2023-04-19 23:48:32 +04:00
public OrderViewModel GetViewModel
{
get
{
using var context = new PrecastConcretePlantDatabase();
return new OrderViewModel
{
Id = Id,
ReinforcedId = ReinforcedId,
ClientId = ClientId,
ImplementerId = ImplementerId,
ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty,
ReinforcedName = context.Reinforceds.FirstOrDefault(x => x.Id == ReinforcedId)?.ReinforcedName ?? string.Empty,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty
};
}
}
2023-03-18 18:19:08 +04:00
}
}