слой хранения данных 1
This commit is contained in:
parent
7e6d2bd728
commit
35f2d60907
@ -95,11 +95,7 @@ namespace TransportCompanyBusinessLogic.BusinessLogics
|
||||
{
|
||||
throw new ArgumentNullException(nameof(element));
|
||||
}
|
||||
model.DepartureDate = element.DepartureDate;
|
||||
model.CargoId = element.CargoId;
|
||||
model.ArrivalDate = element.ArrivalDate;
|
||||
model.Status = element.Status;
|
||||
model.Count = element.Count;
|
||||
if (requiredStatus - model.Status == 1)
|
||||
{
|
||||
model.Status = requiredStatus;
|
||||
|
@ -0,0 +1,32 @@
|
||||
using TransportCompanyListImplement.Models;
|
||||
|
||||
namespace TransportCompanyListImplement
|
||||
{
|
||||
public class DataListSingleton
|
||||
{
|
||||
private static DataListSingleton? _instance;
|
||||
public List<Cargo> Cargos { get; set; }
|
||||
public List<Driver> Drivers { get; set; }
|
||||
public List<Point> Points { get; set; }
|
||||
public List<Transportation> Transportations { get; set; }
|
||||
public List<Transport> Transports { get; set; }
|
||||
|
||||
private DataListSingleton()
|
||||
{
|
||||
Cargos = new List<Cargo>();
|
||||
Drivers = new List<Driver>();
|
||||
Points = new List<Point>();
|
||||
Transportations = new List<Transportation>();
|
||||
Transports = new List<Transport>();
|
||||
}
|
||||
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new DataListSingleton();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.SearchModels;
|
||||
using TransportCompanyContracts.StoragesContracts;
|
||||
using TransportCompanyContracts.ViewModels;
|
||||
using TransportCompanyListImplement.Models;
|
||||
|
||||
namespace TransportCompanyListImplement.Implements
|
||||
{
|
||||
public class CargoStorage : ICargoStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public CargoStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<CargoViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<CargoViewModel>();
|
||||
foreach (var component in _source.Cargos)
|
||||
{
|
||||
result.Add(component.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<CargoViewModel> GetFilteredList(CargoSearchModel model)
|
||||
{
|
||||
var result = new List<CargoViewModel>();
|
||||
if (string.IsNullOrEmpty(model.CargoName))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var component in _source.Cargos)
|
||||
{
|
||||
if (component.CargoName.Contains(model.CargoName))
|
||||
{
|
||||
result.Add(component.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public CargoViewModel? GetElement(CargoSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.CargoName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var component in _source.Cargos)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(model.CargoName) && component.CargoName == model.CargoName) ||
|
||||
(model.Id.HasValue && component.Id == model.Id))
|
||||
{
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public CargoViewModel? Insert(CargoBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var component in _source.Cargos)
|
||||
{
|
||||
if (model.Id <= component.Id)
|
||||
{
|
||||
model.Id = component.Id + 1;
|
||||
}
|
||||
}
|
||||
var newComponent = Cargo.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Cargos.Add(newComponent);
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public CargoViewModel? Update(CargoBindingModel model)
|
||||
{
|
||||
foreach (var component in _source.Cargos)
|
||||
{
|
||||
if (component.Id == model.Id)
|
||||
{
|
||||
component.Update(model);
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public CargoViewModel? Delete(CargoBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Cargos.Count; ++i)
|
||||
{
|
||||
if (_source.Cargos[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Cargos[i];
|
||||
_source.Cargos.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.SearchModels;
|
||||
using TransportCompanyContracts.StoragesContracts;
|
||||
using TransportCompanyContracts.ViewModels;
|
||||
using TransportCompanyListImplement.Models;
|
||||
|
||||
namespace TransportCompanyListImplement.Implements
|
||||
{
|
||||
public class DriverStorage : IDriverStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public DriverStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<DriverViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<DriverViewModel>();
|
||||
foreach (var pizzas in _source.Drivers)
|
||||
{
|
||||
result.Add(pizzas.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<DriverViewModel> GetFilteredList(DriverSearchModel model)
|
||||
{
|
||||
var result = new List<DriverViewModel>();
|
||||
if (string.IsNullOrEmpty(model.DriverFio))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var pizzas in _source.Drivers)
|
||||
{
|
||||
if (pizzas.DriverFio.Contains(model.DriverFio))
|
||||
{
|
||||
result.Add(pizzas.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public DriverViewModel? GetElement(DriverSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.DriverFio) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var pizzas in _source.Drivers)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(model.DriverFio) && pizzas.DriverFio == model.DriverFio) ||
|
||||
(model.Id.HasValue && pizzas.Id == model.Id))
|
||||
{
|
||||
return pizzas.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public DriverViewModel? Insert(DriverBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var pizzas in _source.Drivers)
|
||||
{
|
||||
if (model.Id <= pizzas.Id)
|
||||
{
|
||||
model.Id = pizzas.Id + 1;
|
||||
}
|
||||
}
|
||||
var newPizzas = Driver.Create(model);
|
||||
if (newPizzas == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Drivers.Add(newPizzas);
|
||||
return newPizzas.GetViewModel;
|
||||
}
|
||||
|
||||
public DriverViewModel? Update(DriverBindingModel model)
|
||||
{
|
||||
foreach (var pizzas in _source.Drivers)
|
||||
{
|
||||
if (pizzas.Id == model.Id)
|
||||
{
|
||||
pizzas.Update(model);
|
||||
return pizzas.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public DriverViewModel? Delete(DriverBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Drivers.Count; ++i)
|
||||
{
|
||||
if (_source.Drivers[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Drivers[i];
|
||||
_source.Drivers.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.SearchModels;
|
||||
using TransportCompanyContracts.StoragesContracts;
|
||||
using TransportCompanyContracts.ViewModels;
|
||||
using TransportCompanyListImplement.Models;
|
||||
|
||||
namespace TransportCompanyListImplement.Implements
|
||||
{
|
||||
public class PointStorage : IPointStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public PointStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<PointViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<PointViewModel>();
|
||||
foreach (var pizzas in _source.Points)
|
||||
{
|
||||
result.Add(pizzas.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<PointViewModel> GetFilteredList(PointSearchModel model)
|
||||
{
|
||||
var result = new List<PointViewModel>();
|
||||
if (string.IsNullOrEmpty(model.PointName))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var pizzas in _source.Points)
|
||||
{
|
||||
if (pizzas.PointName.Contains(model.PointName))
|
||||
{
|
||||
result.Add(pizzas.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public PointViewModel? GetElement(PointSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.PointName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var pizzas in _source.Points)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(model.PointName) && pizzas.PointName == model.PointName) ||
|
||||
(model.Id.HasValue && pizzas.Id == model.Id))
|
||||
{
|
||||
return pizzas.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PointViewModel? Insert(PointBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var pizzas in _source.Points)
|
||||
{
|
||||
if (model.Id <= pizzas.Id)
|
||||
{
|
||||
model.Id = pizzas.Id + 1;
|
||||
}
|
||||
}
|
||||
var newPizzas = Point.Create(model);
|
||||
if (newPizzas == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Points.Add(newPizzas);
|
||||
return newPizzas.GetViewModel;
|
||||
}
|
||||
|
||||
public PointViewModel? Update(PointBindingModel model)
|
||||
{
|
||||
foreach (var pizzas in _source.Points)
|
||||
{
|
||||
if (pizzas.Id == model.Id)
|
||||
{
|
||||
pizzas.Update(model);
|
||||
return pizzas.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PointViewModel? Delete(PointBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Points.Count; ++i)
|
||||
{
|
||||
if (_source.Points[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Points[i];
|
||||
_source.Points.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.SearchModels;
|
||||
using TransportCompanyContracts.StoragesContracts;
|
||||
using TransportCompanyContracts.ViewModels;
|
||||
using TransportCompanyListImplement.Models;
|
||||
|
||||
namespace TransportCompanyListImplement.Implements
|
||||
{
|
||||
public class TransportStorage : ITransportStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public TransportStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<TransportViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<TransportViewModel>();
|
||||
foreach (var pizzas in _source.Transports)
|
||||
{
|
||||
result.Add(pizzas.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<TransportViewModel> GetFilteredList(TransportSearchModel model)
|
||||
{
|
||||
var result = new List<TransportViewModel>();
|
||||
if (string.IsNullOrEmpty(model.Model))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var pizzas in _source.Transports)
|
||||
{
|
||||
if (pizzas.Model.Contains(model.Model))
|
||||
{
|
||||
result.Add(pizzas.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public TransportViewModel? GetElement(TransportSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Model) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var pizzas in _source.Transports)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(model.Model) && pizzas.Model == model.Model) ||
|
||||
(model.Id.HasValue && pizzas.Id == model.Id))
|
||||
{
|
||||
return pizzas.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public TransportViewModel? Insert(TransportBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var pizzas in _source.Transports)
|
||||
{
|
||||
if (model.Id <= pizzas.Id)
|
||||
{
|
||||
model.Id = pizzas.Id + 1;
|
||||
}
|
||||
}
|
||||
var newPizzas = Transport.Create(model);
|
||||
if (newPizzas == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Transports.Add(newPizzas);
|
||||
return newPizzas.GetViewModel;
|
||||
}
|
||||
|
||||
public TransportViewModel? Update(TransportBindingModel model)
|
||||
{
|
||||
foreach (var pizzas in _source.Transports)
|
||||
{
|
||||
if (pizzas.Id == model.Id)
|
||||
{
|
||||
pizzas.Update(model);
|
||||
return pizzas.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public TransportViewModel? Delete(TransportBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Transports.Count; ++i)
|
||||
{
|
||||
if (_source.Transports[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Transports[i];
|
||||
_source.Transports.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,142 @@
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.SearchModels;
|
||||
using TransportCompanyContracts.StoragesContracts;
|
||||
using TransportCompanyContracts.ViewModels;
|
||||
using TransportCompanyListImplement.Models;
|
||||
|
||||
namespace TransportCompanyListImplement.Implements
|
||||
{
|
||||
public class TransportationStorage : ITransportationStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public TransportationStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<TransportationViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<TransportationViewModel>();
|
||||
foreach (var order in _source.Transportations)
|
||||
{
|
||||
result.Add(AttachDetails(order.GetViewModel));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<TransportationViewModel> GetFilteredList(TransportationSearchModel model)
|
||||
{
|
||||
var result = new List<TransportationViewModel>();
|
||||
if (model == null || !model.Id.HasValue)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var order in _source.Transportations)
|
||||
{
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
result.Add(AttachDetails(order.GetViewModel));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public TransportationViewModel? GetElement(TransportationSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var order in _source.Transportations)
|
||||
{
|
||||
if (model.Id.HasValue && order.Id == model.Id)
|
||||
{
|
||||
return AttachDetails(order.GetViewModel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public TransportationViewModel? Insert(TransportationBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var order in _source.Transportations)
|
||||
{
|
||||
if (model.Id <= order.Id)
|
||||
{
|
||||
model.Id = order.Id + 1;
|
||||
}
|
||||
}
|
||||
var newOrder = Transportation.Create(model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Transportations.Add(newOrder);
|
||||
return AttachDetails(newOrder.GetViewModel);
|
||||
}
|
||||
|
||||
public TransportationViewModel? Update(TransportationBindingModel model)
|
||||
{
|
||||
foreach (var order in _source.Transportations)
|
||||
{
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
order.Update(model);
|
||||
return AttachDetails(order.GetViewModel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public TransportationViewModel? Delete(TransportationBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Transportations.Count; ++i)
|
||||
{
|
||||
if (_source.Transportations[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Transportations[i];
|
||||
_source.Transportations.RemoveAt(i);
|
||||
return AttachDetails(element.GetViewModel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private string GetDriverFio(int driverId)
|
||||
{
|
||||
var driver = _source.Drivers.FirstOrDefault(d => d.Id == driverId);
|
||||
return driver?.DriverFio ?? string.Empty;
|
||||
}
|
||||
|
||||
private string GetCargoName(int cargoId)
|
||||
{
|
||||
var cargo = _source.Cargos.FirstOrDefault(c => c.Id == cargoId);
|
||||
return cargo?.CargoName ?? string.Empty;
|
||||
}
|
||||
|
||||
private string GetTransportModel(int transportId)
|
||||
{
|
||||
var transport = _source.Transports.FirstOrDefault(t => t.Id == transportId);
|
||||
return transport?.Model ?? string.Empty;
|
||||
}
|
||||
|
||||
private string GetPointName(int pointId)
|
||||
{
|
||||
var point = _source.Points.FirstOrDefault(p => p.Id == pointId);
|
||||
return point?.PointName ?? string.Empty;
|
||||
}
|
||||
|
||||
private TransportationViewModel AttachDetails(TransportationViewModel model)
|
||||
{
|
||||
model.DriverFio = GetDriverFio(model.DriverId);
|
||||
model.CargoName = GetCargoName(model.CargoId);
|
||||
model.Model = GetTransportModel(model.TransportId);
|
||||
model.PointNameTo = GetPointName(model.PointToId);
|
||||
model.PointNameFrom = GetPointName(model.PointFromId);
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.ViewModels;
|
||||
using TransportCompanyDataModels.Models;
|
||||
|
||||
namespace TransportCompanyListImplement.Models
|
||||
{
|
||||
public class Cargo : ICargoModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string CargoName { get; private set; } = string.Empty;
|
||||
public int Weight { get; private set; }
|
||||
|
||||
public static Cargo? Create(CargoBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.ViewModels;
|
||||
using TransportCompanyDataModels.Models;
|
||||
|
||||
namespace TransportCompanyListImplement.Models
|
||||
{
|
||||
public class Driver : IDriverModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string DriverFio { get; private set; } = string.Empty;
|
||||
public string PhoneNumber { get; private set; } = string.Empty;
|
||||
|
||||
public static Driver? Create(DriverBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Driver()
|
||||
{
|
||||
Id = model.Id,
|
||||
DriverFio = model.DriverFio,
|
||||
PhoneNumber = model.PhoneNumber
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(DriverBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DriverFio = model.DriverFio;
|
||||
PhoneNumber = model.PhoneNumber;
|
||||
}
|
||||
|
||||
public DriverViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
DriverFio = DriverFio,
|
||||
PhoneNumber = PhoneNumber
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.ViewModels;
|
||||
using TransportCompanyDataModels.Models;
|
||||
|
||||
namespace TransportCompanyListImplement.Models
|
||||
{
|
||||
public class Point : IPointModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string PointName { get; private set; } = string.Empty;
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
|
||||
public static Point? Create(PointBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Point()
|
||||
{
|
||||
Id = model.Id,
|
||||
PointName = model.PointName,
|
||||
Address = model.Address
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(PointBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PointName = model.PointName;
|
||||
Address = model.Address;
|
||||
}
|
||||
|
||||
public PointViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
PointName = PointName,
|
||||
Address = Address
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
using System.Net;
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.ViewModels;
|
||||
using TransportCompanyDataModels.Models;
|
||||
|
||||
namespace TransportCompanyListImplement.Models
|
||||
{
|
||||
public class Transport :ITransportModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string Model { get; private set; } = string.Empty;
|
||||
public int LoadCapacity { get; private set; }
|
||||
public string StateNumber { get; private set; } = string.Empty;
|
||||
|
||||
public static Transport? Create(TransportBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Transport()
|
||||
{
|
||||
Id = model.Id,
|
||||
Model = model.Model,
|
||||
LoadCapacity = model.LoadCapacity,
|
||||
StateNumber = model.StateNumber,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(TransportBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Model = model.Model;
|
||||
LoadCapacity = model.LoadCapacity;
|
||||
StateNumber = model.StateNumber;
|
||||
}
|
||||
|
||||
public TransportViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Model = Model,
|
||||
LoadCapacity = LoadCapacity,
|
||||
StateNumber = StateNumber,
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.ViewModels;
|
||||
using TransportCompanyDataModels.Enums;
|
||||
using TransportCompanyDataModels.Models;
|
||||
|
||||
namespace TransportCompanyListImplement.Models
|
||||
{
|
||||
public class Transportation : ITransportationModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int DriverId { get; private set; }
|
||||
public int TransportId { get; private set; }
|
||||
public int CargoId { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public int PointToId { get; private set; }
|
||||
public int PointFromId { get; private set; }
|
||||
public TransportationStatus Status { get; private set; } = TransportationStatus.Неизвестен;
|
||||
public DateTime DepartureDate { get; private set; } = DateTime.Now;
|
||||
public DateTime? ArrivalDate { get; private set; }
|
||||
|
||||
public static Transportation? Create(TransportationBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Transportation()
|
||||
{
|
||||
Id = model.Id,
|
||||
DriverId = model.DriverId,
|
||||
TransportId = model.TransportId,
|
||||
CargoId = model.CargoId,
|
||||
Count = model.Count,
|
||||
PointToId = model.PointToId,
|
||||
PointFromId = model.PointFromId,
|
||||
Status = model.Status,
|
||||
DepartureDate = model.DepartureDate,
|
||||
ArrivalDate = model.ArrivalDate,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(TransportationBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DriverId = model.DriverId;
|
||||
TransportId = model.TransportId;
|
||||
CargoId = model.CargoId;
|
||||
Count = model.Count;
|
||||
PointToId = model.PointToId;
|
||||
PointFromId = model.PointFromId;
|
||||
Status = model.Status;
|
||||
DepartureDate = model.DepartureDate;
|
||||
ArrivalDate = model.ArrivalDate;
|
||||
}
|
||||
|
||||
public TransportationViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
DriverId = DriverId,
|
||||
TransportId = TransportId,
|
||||
CargoId = CargoId,
|
||||
Count = Count,
|
||||
PointToId = PointToId,
|
||||
PointFromId = PointFromId,
|
||||
Status = Status,
|
||||
DepartureDate = DepartureDate,
|
||||
ArrivalDate = ArrivalDate,
|
||||
};
|
||||
}
|
||||
}
|
@ -6,4 +6,9 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TransportCompanyContracts\TransportCompanyContracts.csproj" />
|
||||
<ProjectReference Include="..\TransportCompanyDataModels\TransportCompanyDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Loading…
Reference in New Issue
Block a user