Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
1c13ef3cf5 | ||
|
2e8db89434 | ||
|
18ffa6ef58 |
@ -5,15 +5,17 @@ VisualStudioVersion = 17.9.34714.143
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransportCompanyView", "TransportCompany\TransportCompanyView.csproj", "{B63702D9-CAE6-425A-A367-A47515776076}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransportCompanyBusinessLogic", "TransportCompanyBusinessLogic\TransportCompanyBusinessLogic.csproj", "{3E707E19-DDD4-45C2-9DD0-40623BF03826}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransportCompanyBusinessLogic", "TransportCompanyBusinessLogic\TransportCompanyBusinessLogic.csproj", "{3E707E19-DDD4-45C2-9DD0-40623BF03826}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransportCompanyContracts", "TransportCompanyContracts\TransportCompanyContracts.csproj", "{4203915B-B01C-4CB6-A703-024E0925DB42}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransportCompanyContracts", "TransportCompanyContracts\TransportCompanyContracts.csproj", "{4203915B-B01C-4CB6-A703-024E0925DB42}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransportCompanyDatabaseImplement", "TransportCompanyDatabaseImplement\TransportCompanyDatabaseImplement.csproj", "{26367C31-2C70-4617-84BB-C21E0F12FE06}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransportCompanyDatabaseImplement", "TransportCompanyDatabaseImplement\TransportCompanyDatabaseImplement.csproj", "{26367C31-2C70-4617-84BB-C21E0F12FE06}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransportCompanyDataModels", "TransportCompanyDataModels\TransportCompanyDataModels.csproj", "{B0D88CF2-87FE-4010-BED9-F84C3CE8D727}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransportCompanyDataModels", "TransportCompanyDataModels\TransportCompanyDataModels.csproj", "{B0D88CF2-87FE-4010-BED9-F84C3CE8D727}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransportCompanyListImplement", "TransportCompanyListImplement\TransportCompanyListImplement.csproj", "{7C803695-F275-4822-8344-8A58E28E10C0}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransportCompanyListImplement", "TransportCompanyListImplement\TransportCompanyListImplement.csproj", "{7C803695-F275-4822-8344-8A58E28E10C0}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransportCompanyMongoDBImplement", "TransportCompanyMongoDBImplement\TransportCompanyMongoDBImplement.csproj", "{6D12EC66-4505-4258-981F-AE6D256D4653}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -45,6 +47,10 @@ Global
|
||||
{7C803695-F275-4822-8344-8A58E28E10C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7C803695-F275-4822-8344-8A58E28E10C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7C803695-F275-4822-8344-8A58E28E10C0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6D12EC66-4505-4258-981F-AE6D256D4653}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6D12EC66-4505-4258-981F-AE6D256D4653}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6D12EC66-4505-4258-981F-AE6D256D4653}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6D12EC66-4505-4258-981F-AE6D256D4653}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -0,0 +1,79 @@
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.SearchModels;
|
||||
using TransportCompanyContracts.StoragesContracts;
|
||||
using TransportCompanyContracts.ViewModels;
|
||||
using TransportCompanyDatabaseImplement.Models;
|
||||
|
||||
namespace TransportCompanyMongoDBImplement.Implements
|
||||
{
|
||||
public class CargoStorage : ICargoStorage
|
||||
{
|
||||
public List<CargoViewModel> GetFullList()
|
||||
{
|
||||
using var context = new TransportCompanyDatabase();
|
||||
return context.Cargos.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<CargoViewModel> GetFilteredList(CargoSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.CargoName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new TransportCompanyDatabase();
|
||||
return context.Cargos.Where(x => x.CargoName.Contains(model.CargoName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public CargoViewModel? GetElement(CargoSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.CargoName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new TransportCompanyDatabase();
|
||||
return context.Cargos.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.CargoName) && x.CargoName == model.CargoName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public CargoViewModel? Insert(CargoBindingModel model)
|
||||
{
|
||||
var newComponent = Cargo.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new TransportCompanyDatabase();
|
||||
context.Cargos.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public CargoViewModel? Update(CargoBindingModel model)
|
||||
{
|
||||
using var context = new TransportCompanyDatabase();
|
||||
var component = context.Cargos.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
|
||||
public CargoViewModel? Delete(CargoBindingModel model)
|
||||
{
|
||||
using var context = new TransportCompanyDatabase();
|
||||
var element = context.Cargos.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Cargos.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.SearchModels;
|
||||
using TransportCompanyContracts.StoragesContracts;
|
||||
using TransportCompanyContracts.ViewModels;
|
||||
using TransportCompanyDatabaseImplement.Models;
|
||||
|
||||
namespace TransportCompanyMongoDBImplement.Implements
|
||||
{
|
||||
public class DriverStorage : IDriverStorage
|
||||
{
|
||||
public List<DriverViewModel> GetFullList()
|
||||
{
|
||||
using var context = new TransportCompanyDatabase();
|
||||
return context.Drivers.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<DriverViewModel> GetFilteredList(DriverSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.DriverFio))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new TransportCompanyDatabase();
|
||||
return context.Drivers.Where(x => x.DriverFio.Contains(model.DriverFio)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public DriverViewModel? GetElement(DriverSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.DriverFio) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new TransportCompanyDatabase();
|
||||
return context.Drivers.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.DriverFio) && x.DriverFio == model.DriverFio) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public DriverViewModel? Insert(DriverBindingModel model)
|
||||
{
|
||||
var newComponent = Driver.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new TransportCompanyDatabase();
|
||||
context.Drivers.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public DriverViewModel? Update(DriverBindingModel model)
|
||||
{
|
||||
using var context = new TransportCompanyDatabase();
|
||||
var component = context.Drivers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
|
||||
public DriverViewModel? Delete(DriverBindingModel model)
|
||||
{
|
||||
using var context = new TransportCompanyDatabase();
|
||||
var element = context.Drivers.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Drivers.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.SearchModels;
|
||||
using TransportCompanyContracts.StoragesContracts;
|
||||
using TransportCompanyContracts.ViewModels;
|
||||
using TransportCompanyDatabaseImplement.Models;
|
||||
|
||||
namespace TransportCompanyMongoDBImplement.Implements
|
||||
{
|
||||
public class PointStorage : IPointStorage
|
||||
{
|
||||
public List<PointViewModel> GetFullList()
|
||||
{
|
||||
using var context = new TransportCompanyDatabase();
|
||||
return context.Points.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<PointViewModel> GetFilteredList(PointSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.PointName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new TransportCompanyDatabase();
|
||||
return context.Points.Where(x => x.PointName.Contains(model.PointName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public PointViewModel? GetElement(PointSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.PointName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new TransportCompanyDatabase();
|
||||
return context.Points.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.PointName) && x.PointName == model.PointName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public PointViewModel? Insert(PointBindingModel model)
|
||||
{
|
||||
var newComponent = Point.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new TransportCompanyDatabase();
|
||||
context.Points.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public PointViewModel? Update(PointBindingModel model)
|
||||
{
|
||||
using var context = new TransportCompanyDatabase();
|
||||
var component = context.Points.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
|
||||
public PointViewModel? Delete(PointBindingModel model)
|
||||
{
|
||||
using var context = new TransportCompanyDatabase();
|
||||
var element = context.Points.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Points.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.SearchModels;
|
||||
using TransportCompanyContracts.StoragesContracts;
|
||||
using TransportCompanyContracts.ViewModels;
|
||||
using TransportCompanyDatabaseImplement.Models;
|
||||
|
||||
namespace TransportCompanyMongoDBImplement.Implements
|
||||
{
|
||||
public class TransportStorage : ITransportStorage
|
||||
{
|
||||
public List<TransportViewModel> GetFullList()
|
||||
{
|
||||
using var context = new TransportCompanyDatabase();
|
||||
return context.Transports.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<TransportViewModel> GetFilteredList(TransportSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Model))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new TransportCompanyDatabase();
|
||||
return context.Transports.Where(x => x.Model.Contains(model.Model)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public TransportViewModel? GetElement(TransportSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Model) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new TransportCompanyDatabase();
|
||||
return context.Transports.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.Model) && x.Model == model.Model) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public TransportViewModel? Insert(TransportBindingModel model)
|
||||
{
|
||||
var newComponent = Transport.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new TransportCompanyDatabase();
|
||||
context.Transports.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public TransportViewModel? Update(TransportBindingModel model)
|
||||
{
|
||||
using var context = new TransportCompanyDatabase();
|
||||
var component = context.Transports.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
|
||||
public TransportViewModel? Delete(TransportBindingModel model)
|
||||
{
|
||||
using var context = new TransportCompanyDatabase();
|
||||
var element = context.Transports.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Transports.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.SearchModels;
|
||||
using TransportCompanyContracts.StoragesContracts;
|
||||
using TransportCompanyContracts.ViewModels;
|
||||
|
||||
using TransportCompanyDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace TransportCompanyMongoDBImplement.Implements
|
||||
{
|
||||
public class TransportationStorage
|
||||
{
|
||||
public List<TransportationViewModel> GetFullList()
|
||||
{
|
||||
using var context = new TransportCompanyDatabase();
|
||||
return context.Transportations
|
||||
.Include(x => x.Cargo)
|
||||
.Include(x => x.Driver)
|
||||
.Include(x => x.PointFrom)
|
||||
.Include(x => x.PointTo)
|
||||
.Include(x => x.Transport)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<TransportationViewModel> GetFilteredList(TransportationSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new TransportCompanyDatabase();
|
||||
return context.Transportations
|
||||
.Include(x => x.Cargo)
|
||||
.Include(x => x.Driver)
|
||||
.Include(x => x.PointFrom)
|
||||
.Include(x => x.PointTo)
|
||||
.Include(x => x.Transport)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public TransportationViewModel? GetElement(TransportationSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new TransportCompanyDatabase();
|
||||
return context.Transportations
|
||||
.Include(x => x.Cargo)
|
||||
.Include(x => x.Driver)
|
||||
.Include(x => x.PointFrom)
|
||||
.Include(x => x.PointTo)
|
||||
.Include(x => x.Transport)
|
||||
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
|
||||
public TransportationViewModel? Update(TransportationBindingModel model)
|
||||
{
|
||||
using var context = new TransportCompanyDatabase();
|
||||
var order = context.Transportations.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
return order.GetViewModel;
|
||||
}
|
||||
|
||||
public TransportationViewModel? Delete(TransportationBindingModel model)
|
||||
{
|
||||
using var context = new TransportCompanyDatabase();
|
||||
var order = context.Transportations.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (order != null)
|
||||
{
|
||||
context.Transportations.Remove(order);
|
||||
context.SaveChanges();
|
||||
return order.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
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
|
||||
{
|
||||
[BsonId]
|
||||
[BsonElement("_id")]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public int Id { get; private set; }
|
||||
[BsonRequired]
|
||||
public string CargoName { get; private set; } = string.Empty;
|
||||
[BsonRequired]
|
||||
public int Weight { get; private set; }
|
||||
|
||||
[BsonRequired]
|
||||
[BsonElement("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
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
using TransportCompanyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.ViewModels;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace TransportCompanyDatabaseImplement.Models
|
||||
{
|
||||
public class Driver : IDriverModel
|
||||
{
|
||||
[BsonId]
|
||||
[BsonElement("_id")]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public int Id { get; private set; }
|
||||
[BsonRequired]
|
||||
public string DriverFio { get; private set; } = string.Empty;
|
||||
[BsonRequired]
|
||||
public string PhoneNumber { get; private set; } = string.Empty;
|
||||
|
||||
[BsonRequired]
|
||||
[BsonElement("DriverId")]
|
||||
public virtual List<Transportation> Transportations { get; set; } = new();
|
||||
|
||||
public static Driver? Create(DriverBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Driver()
|
||||
{
|
||||
Id = model.Id,
|
||||
DriverFio = model.DriverFio,
|
||||
PhoneNumber = model.PhoneNumber
|
||||
};
|
||||
}
|
||||
|
||||
public static Driver Create(DriverViewModel model)
|
||||
{
|
||||
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,72 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.ViewModels;
|
||||
using TransportCompanyDataModels.Models;
|
||||
|
||||
namespace TransportCompanyDatabaseImplement.Models
|
||||
{
|
||||
public class Point : IPointModel
|
||||
{
|
||||
[BsonId]
|
||||
[BsonElement("_id")]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public int Id { get; private set; }
|
||||
[BsonRequired]
|
||||
public string PointName { get; private set; } = string.Empty;
|
||||
[BsonRequired]
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
|
||||
[BsonRequired]
|
||||
[BsonElement("PointToId")]
|
||||
public virtual List<Transportation> TransportationsTo { get; set; } = new();
|
||||
|
||||
[BsonRequired]
|
||||
[BsonElement("PointFromId")]
|
||||
public virtual List<Transportation> TransportationsFrom { get; set; } = new();
|
||||
|
||||
|
||||
public static Point? Create(PointBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Point()
|
||||
{
|
||||
Id = model.Id,
|
||||
PointName = model.PointName,
|
||||
Address = model.Address
|
||||
};
|
||||
}
|
||||
|
||||
public static Point Create(PointViewModel model)
|
||||
{
|
||||
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,73 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.ViewModels;
|
||||
using TransportCompanyDataModels.Models;
|
||||
|
||||
namespace TransportCompanyDatabaseImplement.Models
|
||||
{
|
||||
public class Transport : ITransportModel
|
||||
{
|
||||
[BsonId]
|
||||
[BsonElement("_id")]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public int Id { get; private set; }
|
||||
[BsonRequired]
|
||||
public string Model { get; private set; } = string.Empty;
|
||||
[BsonRequired]
|
||||
public int LoadCapacity { get; private set; }
|
||||
[BsonRequired]
|
||||
public string StateNumber { get; private set; } = string.Empty;
|
||||
|
||||
[BsonRequired]
|
||||
[BsonElement("TransportId")]
|
||||
public virtual List<Transportation> Transportations { get; set; } = new();
|
||||
|
||||
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 static Transport Create(TransportViewModel model)
|
||||
{
|
||||
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,87 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.ViewModels;
|
||||
using TransportCompanyDataModels.Enums;
|
||||
using TransportCompanyDataModels.Models;
|
||||
|
||||
namespace TransportCompanyDatabaseImplement.Models
|
||||
{
|
||||
public class Transportation : ITransportationModel
|
||||
{
|
||||
[BsonId]
|
||||
[BsonElement("_id")]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public int Id { get; private set; }
|
||||
|
||||
[BsonRequired]
|
||||
|
||||
public int DriverId { get; private set; }
|
||||
public virtual Driver Driver { get; set; } = new();
|
||||
|
||||
[BsonRequired]
|
||||
|
||||
public int TransportId { get; private set; }
|
||||
public virtual Transport Transport { get; set; } = new();
|
||||
|
||||
[BsonRequired]
|
||||
|
||||
public int CargoId { get; private set; }
|
||||
public virtual Cargo Cargo { get; set; } = new();
|
||||
|
||||
[BsonRequired]
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
[BsonRequired]
|
||||
|
||||
public int PointToId { get; private set; }
|
||||
public virtual Point PointTo { get; set; } = new();
|
||||
|
||||
[BsonRequired]
|
||||
|
||||
public int PointFromId { get; private set; }
|
||||
public virtual Point PointFrom { get; set; } = new();
|
||||
|
||||
[BsonRequired]
|
||||
|
||||
public TransportationStatus Status { get; private set; } = TransportationStatus.Неизвестен;
|
||||
|
||||
[Required]
|
||||
public DateTime DepartureDate { get; private set; } = DateTime.Now;
|
||||
|
||||
public DateTime? ArrivalDate { get; private set; }
|
||||
|
||||
|
||||
|
||||
public void Update(TransportationBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
ArrivalDate = model.ArrivalDate;
|
||||
}
|
||||
|
||||
public TransportationViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
DriverId = DriverId,
|
||||
DriverFio = Driver.DriverFio,
|
||||
TransportId = TransportId,
|
||||
Model = Transport.Model,
|
||||
CargoId = CargoId,
|
||||
CargoName = Cargo.CargoName,
|
||||
Count = Count,
|
||||
PointToId = PointToId,
|
||||
PointNameTo = PointTo.PointName,
|
||||
PointFromId = PointFromId,
|
||||
PointNameFrom = PointFrom.PointName,
|
||||
Status = Status,
|
||||
DepartureDate = DepartureDate,
|
||||
ArrivalDate = ArrivalDate,
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using TransportCompanyDatabaseImplement.Models;
|
||||
|
||||
namespace TransportCompanyMongoDBImplement
|
||||
{
|
||||
public class TransportCompanyDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=ALYONA\;Initial Catalog=TransportCompanyDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
public virtual DbSet<Cargo> Cargos { set; get; }
|
||||
public virtual DbSet<Driver> Drivers { set; get; }
|
||||
public virtual DbSet<Point> Points { set; get; }
|
||||
public virtual DbSet<Transport> Transports { set; get; }
|
||||
public virtual DbSet<Transportation> Transportations { set; get; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Transportation>()
|
||||
.HasOne(t => t.PointTo)
|
||||
.WithMany(p => p.TransportationsTo)
|
||||
.HasForeignKey(t => t.PointToId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
modelBuilder.Entity<Transportation>()
|
||||
.HasOne(t => t.PointFrom)
|
||||
.WithMany(p => p.TransportationsFrom)
|
||||
.HasForeignKey(t => t.PointFromId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MongoDB.Bson" Version="2.25.0" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.25.0" />
|
||||
<PackageReference Include="Npgsql" Version="8.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TransportCompanyContracts\TransportCompanyContracts.csproj" />
|
||||
<ProjectReference Include="..\TransportCompanyDatabaseImplement\TransportCompanyDatabaseImplement.csproj" />
|
||||
<ProjectReference Include="..\TransportCompanyDataModels\TransportCompanyDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,21 @@
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace BarberShopMongoDBImplement
|
||||
{
|
||||
public class TransportCompanyMongoDatabase
|
||||
{
|
||||
public static TransportCompanyMongoDatabase? instance;
|
||||
public MongoClient client;
|
||||
private TransportCompanyMongoDatabase()
|
||||
{ client = new MongoClient("mongodb://localhost:27017"); }
|
||||
|
||||
public static TransportCompanyMongoDatabase getInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new TransportCompanyMongoDatabase();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user