72 lines
1.9 KiB
C#
72 lines
1.9 KiB
C#
|
using RouteGuideContracts.BindingModels;
|
|||
|
using RouteGuideContracts.ViewModels;
|
|||
|
using RouteGuideDataModels.Models;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel.DataAnnotations.Schema;
|
|||
|
using System.ComponentModel.DataAnnotations;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace RouteGuideDatabaseImplements.Models
|
|||
|
{
|
|||
|
public class Transport : ITransportModel
|
|||
|
{
|
|||
|
public int Id { get; private set; }
|
|||
|
|
|||
|
[Required]
|
|||
|
public string DriverName { get; private set; } = string.Empty;
|
|||
|
|
|||
|
[Required]
|
|||
|
public int RouteId { get; set; }
|
|||
|
|
|||
|
[Required]
|
|||
|
public int TransportTypeId { get; set; }
|
|||
|
|
|||
|
public static Transport? Create(TransportBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return new Transport()
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
DriverName = model.DriverName,
|
|||
|
RouteId = model.RouteId,
|
|||
|
TransportTypeId = model.TransportTypeId
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
public static Transport Create(TransportViewModel model)
|
|||
|
{
|
|||
|
return new Transport
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
DriverName = model.DriverName,
|
|||
|
RouteId = model.RouteId,
|
|||
|
TransportTypeId = model.TransportTypeId
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
public void Update(TransportBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
DriverName = model.DriverName;
|
|||
|
RouteId = model.RouteId;
|
|||
|
}
|
|||
|
|
|||
|
public TransportViewModel GetViewModel => new()
|
|||
|
{
|
|||
|
Id = Id,
|
|||
|
DriverName = DriverName,
|
|||
|
RouteId = RouteId,
|
|||
|
TransportTypeId = TransportTypeId
|
|||
|
};
|
|||
|
}
|
|||
|
}
|