62 lines
1.6 KiB
C#
62 lines
1.6 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using TransportCompanyContracts.BindingModels;
|
|
using TransportCompanyContracts.ViewModels;
|
|
using TransportCompanyDataModels.Models;
|
|
|
|
namespace TransportCompanyDatabaseImplement.Models
|
|
{
|
|
public class Cargo : ICargoModel
|
|
{
|
|
public int Id { get; private set; }
|
|
[Required]
|
|
public string CargoName { get; private set; } = string.Empty;
|
|
[Required]
|
|
public int Weight { get; private set; }
|
|
|
|
[ForeignKey("CargoId")]
|
|
public virtual List<Transportation> Transportations { get; set; } = new();
|
|
|
|
public static Cargo? Create(CargoBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new Cargo()
|
|
{
|
|
Id = model.Id,
|
|
CargoName = model.CargoName,
|
|
Weight = model.Weight
|
|
};
|
|
}
|
|
|
|
public static Cargo Create(CargoViewModel model)
|
|
{
|
|
return new Cargo
|
|
{
|
|
Id = model.Id,
|
|
CargoName = model.CargoName,
|
|
Weight = model.Weight
|
|
};
|
|
}
|
|
|
|
public void Update(CargoBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
CargoName = model.CargoName;
|
|
Weight = model.Weight;
|
|
}
|
|
|
|
public CargoViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
CargoName = CargoName,
|
|
Weight = Weight
|
|
};
|
|
}
|
|
}
|