Eliseev_E.E._PIbd-21_DBMS/TransportCompany/TransportCompanyDatabaseImplements/Models/Trucking.cs

90 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using TransportCompanyContracts.BindingModels;
using TransportCompanyContracts.ViewModels;
using TransportCompanyDataModels.Models;
namespace TransportCompanyDatabaseImplements.Models;
public partial class Trucking : ITruckingModel
{
public int Id { get; set; }
public int ClientId { get; set; }
public int CargoId { get; set; }
public double Price { get; set; }
public DateTime DateStart { get; set; }
public DateTime DateEnd { get; set; }
public int TransportationId { get; set; }
public int TransportId { get; set; }
public virtual Cargo Cargo { get; set; } = null!;
public virtual Client Client { get; set; } = null!;
public virtual Transport Transport { get; set; } = null!;
public virtual TypeTransportation TypeTransportation { get; set; } = null!;
public static Trucking? Create(TruckingBindingModel model)
{
if (model == null)
{
return null;
}
return new Trucking()
{
Id = model.Id,
ClientId = model.ClientId,
CargoId = model.CargoId,
Price = model.Price,
DateStart = model.DateStart,
DateEnd = model.DateEnd,
TransportationId = model.TransportationId,
TransportId = model.TransportId
};
}
public void Update(TruckingBindingModel model)
{
if (model == null)
{
return;
}
Id = model.Id;
ClientId = model.ClientId;
CargoId = model.CargoId;
Price = model.Price;
DateStart = model.DateStart;
DateEnd = model.DateEnd;
TransportationId = model.TransportationId;
TransportId = model.TransportId;
}
public TruckingViewModel GetViewModel => new()
{
Id = Id,
ClientId = ClientId,
CargoId = CargoId,
Price = Price,
DateStart = DateStart,
DateEnd = DateEnd,
TransportationId = TransportationId,
TransportId = TransportId,
ClientName = Client.Name,
ClientSurname = Client.Surname,
ClientPatronymic = Client.Patronymic,
TypeTransportation = TypeTransportation.TransportationType,
TransportName = Transport.TransportType,
Cargo = Cargo.TypeCargo
};
}