Pibd-21_Ievlewa_MD._Precast.../PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Order.cs

88 lines
2.7 KiB
C#
Raw Normal View History

2024-04-04 21:21:21 +04:00
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantDataModels.Enums;
using PrecastConcretePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantDatabaseImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
[Required]
2024-04-18 20:50:43 +04:00
public int ClientId { get; set; }
2024-04-04 21:21:21 +04:00
public int Count { get; private set; }
[Required]
public double Sum { get; private set; }
2024-05-02 20:47:10 +04:00
public int? ImplementerId { get; set; }
[Required]
2024-04-04 21:21:21 +04:00
public OrderStatus Status { get; private set; }
[Required]
public DateTime DateCreate { get; private set; }
public DateTime? DateImplement { get; private set; }
[Required]
public int ReinforcedId { get; private set; }
public virtual Reinforced Reinforced { get; set; }
2024-04-18 20:50:43 +04:00
public virtual Client Client { get; set; }
2024-05-02 20:47:10 +04:00
public virtual Implementer? Implementer { get; set; }
2024-04-04 21:21:21 +04:00
2024-05-02 20:47:10 +04:00
public static Order? Create(OrderBindingModel model)
2024-04-04 21:21:21 +04:00
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
2024-04-18 20:50:43 +04:00
ClientId = model.ClientId,
2024-04-04 21:21:21 +04:00
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
ReinforcedId = model.ReinforcedId,
2024-05-02 20:47:10 +04:00
ImplementerId = model.ImplementerId,
};
2024-04-04 21:21:21 +04:00
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
2024-05-02 20:47:10 +04:00
DateImplement = model.DateImplement;
ImplementerId = model.ImplementerId;
}
2024-04-04 21:21:21 +04:00
2024-05-02 20:47:10 +04:00
public OrderViewModel GetViewModel
{
get
{
using var context = new PrecastConcretePlantDatabase();
return new OrderViewModel
{
ReinforcedId = ReinforcedId,
ImplementerId = ImplementerId,
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty,
ReinforcedName = context.Reinforceds.FirstOrDefault(x => x.Id == ReinforcedId)?.ReinforcedName ?? string.Empty,
ClientId = ClientId,
ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
Id = Id,
};
}
}
}
}