From 35f2d60907fc85ed5fda25a9d38f477f03bbb32b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Sun, 25 Feb 2024 20:03:53 +0400 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=BB=D0=BE=D0=B9=20=D1=85=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/TransportationLogic.cs | 4 - .../DataListSingleton.cs | 32 ++++ .../Implements/CargoStorage.cs | 108 +++++++++++++ .../Implements/DriverStorage.cs | 108 +++++++++++++ .../Implements/PointStorage.cs | 108 +++++++++++++ .../Implements/TransportStorage.cs | 108 +++++++++++++ .../Implements/TransportationStorage.cs | 142 ++++++++++++++++++ .../Models/Cargo.cs | 44 ++++++ .../Models/Driver.cs | 44 ++++++ .../Models/Point.cs | 44 ++++++ .../Models/Transport.cs | 49 ++++++ .../Models/Transportation.cs | 73 +++++++++ .../TransportCompanyListImplement.csproj | 5 + 13 files changed, 865 insertions(+), 4 deletions(-) create mode 100644 TransportCompany/TransportCompanyListImplement/DataListSingleton.cs create mode 100644 TransportCompany/TransportCompanyListImplement/Implements/CargoStorage.cs create mode 100644 TransportCompany/TransportCompanyListImplement/Implements/DriverStorage.cs create mode 100644 TransportCompany/TransportCompanyListImplement/Implements/PointStorage.cs create mode 100644 TransportCompany/TransportCompanyListImplement/Implements/TransportStorage.cs create mode 100644 TransportCompany/TransportCompanyListImplement/Implements/TransportationStorage.cs create mode 100644 TransportCompany/TransportCompanyListImplement/Models/Cargo.cs create mode 100644 TransportCompany/TransportCompanyListImplement/Models/Driver.cs create mode 100644 TransportCompany/TransportCompanyListImplement/Models/Point.cs create mode 100644 TransportCompany/TransportCompanyListImplement/Models/Transport.cs create mode 100644 TransportCompany/TransportCompanyListImplement/Models/Transportation.cs diff --git a/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/TransportationLogic.cs b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/TransportationLogic.cs index 71955a3..eda237b 100644 --- a/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/TransportationLogic.cs +++ b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogics/TransportationLogic.cs @@ -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; diff --git a/TransportCompany/TransportCompanyListImplement/DataListSingleton.cs b/TransportCompany/TransportCompanyListImplement/DataListSingleton.cs new file mode 100644 index 0000000..61e7744 --- /dev/null +++ b/TransportCompany/TransportCompanyListImplement/DataListSingleton.cs @@ -0,0 +1,32 @@ +using TransportCompanyListImplement.Models; + +namespace TransportCompanyListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Cargos { get; set; } + public List Drivers { get; set; } + public List Points { get; set; } + public List Transportations { get; set; } + public List Transports { get; set; } + + private DataListSingleton() + { + Cargos = new List(); + Drivers = new List(); + Points = new List(); + Transportations = new List(); + Transports = new List(); + } + + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/TransportCompany/TransportCompanyListImplement/Implements/CargoStorage.cs b/TransportCompany/TransportCompanyListImplement/Implements/CargoStorage.cs new file mode 100644 index 0000000..f882d0b --- /dev/null +++ b/TransportCompany/TransportCompanyListImplement/Implements/CargoStorage.cs @@ -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 GetFullList() + { + var result = new List(); + foreach (var component in _source.Cargos) + { + result.Add(component.GetViewModel); + } + return result; + } + + public List GetFilteredList(CargoSearchModel model) + { + var result = new List(); + 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; + } + } +} diff --git a/TransportCompany/TransportCompanyListImplement/Implements/DriverStorage.cs b/TransportCompany/TransportCompanyListImplement/Implements/DriverStorage.cs new file mode 100644 index 0000000..3a4fe68 --- /dev/null +++ b/TransportCompany/TransportCompanyListImplement/Implements/DriverStorage.cs @@ -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 GetFullList() + { + var result = new List(); + foreach (var pizzas in _source.Drivers) + { + result.Add(pizzas.GetViewModel); + } + return result; + } + + public List GetFilteredList(DriverSearchModel model) + { + var result = new List(); + 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; + } + } +} diff --git a/TransportCompany/TransportCompanyListImplement/Implements/PointStorage.cs b/TransportCompany/TransportCompanyListImplement/Implements/PointStorage.cs new file mode 100644 index 0000000..cc63fee --- /dev/null +++ b/TransportCompany/TransportCompanyListImplement/Implements/PointStorage.cs @@ -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 GetFullList() + { + var result = new List(); + foreach (var pizzas in _source.Points) + { + result.Add(pizzas.GetViewModel); + } + return result; + } + + public List GetFilteredList(PointSearchModel model) + { + var result = new List(); + 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; + } + } +} diff --git a/TransportCompany/TransportCompanyListImplement/Implements/TransportStorage.cs b/TransportCompany/TransportCompanyListImplement/Implements/TransportStorage.cs new file mode 100644 index 0000000..af65699 --- /dev/null +++ b/TransportCompany/TransportCompanyListImplement/Implements/TransportStorage.cs @@ -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 GetFullList() + { + var result = new List(); + foreach (var pizzas in _source.Transports) + { + result.Add(pizzas.GetViewModel); + } + return result; + } + + public List GetFilteredList(TransportSearchModel model) + { + var result = new List(); + 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; + } + } +} diff --git a/TransportCompany/TransportCompanyListImplement/Implements/TransportationStorage.cs b/TransportCompany/TransportCompanyListImplement/Implements/TransportationStorage.cs new file mode 100644 index 0000000..154a015 --- /dev/null +++ b/TransportCompany/TransportCompanyListImplement/Implements/TransportationStorage.cs @@ -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 GetFullList() + { + var result = new List(); + foreach (var order in _source.Transportations) + { + result.Add(AttachDetails(order.GetViewModel)); + } + return result; + } + + public List GetFilteredList(TransportationSearchModel model) + { + var result = new List(); + 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; + } + } +} diff --git a/TransportCompany/TransportCompanyListImplement/Models/Cargo.cs b/TransportCompany/TransportCompanyListImplement/Models/Cargo.cs new file mode 100644 index 0000000..571de33 --- /dev/null +++ b/TransportCompany/TransportCompanyListImplement/Models/Cargo.cs @@ -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 + }; + } +} diff --git a/TransportCompany/TransportCompanyListImplement/Models/Driver.cs b/TransportCompany/TransportCompanyListImplement/Models/Driver.cs new file mode 100644 index 0000000..168c761 --- /dev/null +++ b/TransportCompany/TransportCompanyListImplement/Models/Driver.cs @@ -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 + }; + } +} diff --git a/TransportCompany/TransportCompanyListImplement/Models/Point.cs b/TransportCompany/TransportCompanyListImplement/Models/Point.cs new file mode 100644 index 0000000..d2c22d9 --- /dev/null +++ b/TransportCompany/TransportCompanyListImplement/Models/Point.cs @@ -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 + }; + } +} diff --git a/TransportCompany/TransportCompanyListImplement/Models/Transport.cs b/TransportCompany/TransportCompanyListImplement/Models/Transport.cs new file mode 100644 index 0000000..1d3be71 --- /dev/null +++ b/TransportCompany/TransportCompanyListImplement/Models/Transport.cs @@ -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, + }; + } +} diff --git a/TransportCompany/TransportCompanyListImplement/Models/Transportation.cs b/TransportCompany/TransportCompanyListImplement/Models/Transportation.cs new file mode 100644 index 0000000..31928ac --- /dev/null +++ b/TransportCompany/TransportCompanyListImplement/Models/Transportation.cs @@ -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, + }; + } +} diff --git a/TransportCompany/TransportCompanyListImplement/TransportCompanyListImplement.csproj b/TransportCompany/TransportCompanyListImplement/TransportCompanyListImplement.csproj index 132c02c..ca2eec3 100644 --- a/TransportCompany/TransportCompanyListImplement/TransportCompanyListImplement.csproj +++ b/TransportCompany/TransportCompanyListImplement/TransportCompanyListImplement.csproj @@ -6,4 +6,9 @@ enable + + + + +