2024-06-02 17:45:23 +04:00
|
|
|
|
using DocumentFormat.OpenXml.InkML;
|
|
|
|
|
using ShipyardContracts.BindingModels;
|
2024-04-27 19:15:39 +04:00
|
|
|
|
using ShipyardContracts.ViewModels;
|
|
|
|
|
using ShipyardDataModels.Enums;
|
|
|
|
|
using ShipyardDataModels.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace ShipyardDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Order : IOrderModel
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; private set; }
|
2024-06-02 17:45:23 +04:00
|
|
|
|
public virtual Ship Ship { get; set; } = new();
|
2024-04-27 19:15:39 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public int Count { get; private set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public double Sum { get; private set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public OrderStatus Status { get; private set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public DateTime DateCreate { get; private set; }
|
|
|
|
|
public DateTime? DateImplement { get; private set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public int ShipId { get; private set; }
|
2024-06-02 17:45:23 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public int ClientId { get; private set; }
|
|
|
|
|
public virtual Client? Client { get; private set; }
|
2024-06-02 18:07:29 +04:00
|
|
|
|
public int? ImplementerId { get; private set; } = null;
|
|
|
|
|
public virtual Implementer? Implementer { get; private set; }
|
2024-04-27 19:15:39 +04:00
|
|
|
|
|
2024-06-02 17:45:23 +04:00
|
|
|
|
public static Order? Create(OrderBindingModel model, ShipyardDataBase context)
|
2024-04-27 19:15:39 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Order()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
2024-06-02 17:45:23 +04:00
|
|
|
|
ShipId = model.ShipId,
|
|
|
|
|
Ship = context.Ships.First(x => x.Id == model.ShipId),
|
|
|
|
|
ClientId = model.ClientId,
|
|
|
|
|
Client = context.Clients.First(x => x.Id == model.ClientId),
|
|
|
|
|
Count = model.Count,
|
2024-04-27 19:15:39 +04:00
|
|
|
|
Sum = model.Sum,
|
|
|
|
|
Status = model.Status,
|
|
|
|
|
DateCreate = model.DateCreate,
|
|
|
|
|
DateImplement = model.DateImplement,
|
2024-06-02 18:07:29 +04:00
|
|
|
|
ImplementerId = model.ImplementerId,
|
|
|
|
|
};
|
2024-04-27 19:15:39 +04:00
|
|
|
|
}
|
|
|
|
|
public void Update(OrderBindingModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Status = model.Status;
|
|
|
|
|
DateImplement = model.DateImplement;
|
2024-06-02 18:07:29 +04:00
|
|
|
|
ImplementerId = model.ImplementerId;
|
|
|
|
|
}
|
2024-04-27 19:15:39 +04:00
|
|
|
|
public OrderViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
ShipId = ShipId,
|
2024-06-02 17:45:23 +04:00
|
|
|
|
ShipName = Ship.ShipName,
|
2024-04-27 19:15:39 +04:00
|
|
|
|
Count = Count,
|
|
|
|
|
Sum = Sum,
|
|
|
|
|
Status = Status,
|
|
|
|
|
DateCreate = DateCreate,
|
|
|
|
|
DateImplement = DateImplement,
|
|
|
|
|
Id = Id,
|
2024-06-02 17:45:23 +04:00
|
|
|
|
ClientId = ClientId,
|
|
|
|
|
ClientFIO = Client?.ClientFIO ?? String.Empty,
|
2024-06-02 18:07:29 +04:00
|
|
|
|
ImplementerId = ImplementerId,
|
|
|
|
|
ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : string.Empty
|
2024-06-02 17:45:23 +04:00
|
|
|
|
};
|
2024-04-27 19:15:39 +04:00
|
|
|
|
}
|
|
|
|
|
}
|