Compare commits

...

4 Commits

31 changed files with 291 additions and 271 deletions

View File

@ -28,10 +28,16 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container(); SuspendLayout();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; //
this.ClientSize = new System.Drawing.Size(800, 450); // Form1
this.Text = "Form1"; //
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Name = "Form1";
Text = "Form1";
ResumeLayout(false);
} }
#endregion #endregion

View File

@ -1,3 +1,13 @@
using ServiceStationContracts.BindingModels;
using ServiceStationContracts.BusinessLogicsContracts;
using ServiceStationContracts.SearchModels;
using ServiceStationContracts.StoragesContracts;
using ServiceStationContracts.ViewModels;
using ServiceStationDatabaseImplement;
using ServiceStationDatabaseImplement.Models;
using ServiceStationDataModels.Enums;
using ServiceStationDataModels.Models;
namespace ServiceStation namespace ServiceStation
{ {
public partial class Form1 : Form public partial class Form1 : Form

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<root> <root>
<!-- <!--
Microsoft ResX Schema Microsoft ResX Schema
Version 2.0 Version 2.0
The primary goals of this format is to allow a simple XML format The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes various data types are done through the TypeConverter classes
associated with the data types. associated with the data types.
Example: Example:
... ado.net/XML headers & schema ... ... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader> <resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader> <resheader name="version">2.0</resheader>
@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment> <comment>This is a comment</comment>
</data> </data>
There are any number of "resheader" rows that contain simple There are any number of "resheader" rows that contain simple
name/value pairs. name/value pairs.
Each data row contains a name, and value. The row also contains a Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture. text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the Classes that don't support this are serialized and stored with the
mimetype set. mimetype set.
The mimetype is used for serialized objects, and tells the The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly: extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below. read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64 mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64 mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64 mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter : using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
--> -->

View File

@ -1,9 +1,10 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using ServiceStationContracts.BusinessLogicsContracts; using ServiceStationContracts.BusinessLogicsContracts;
using ServiceStationContracts.StoragesContracts;
using ServiceStationDatabaseImplement.Implements; using ServiceStationDatabaseImplement.Implements;
using NLog.Extensions.Logging; using NLog.Extensions.Logging;
using ServiceStationBusinessLogic.BusinessLogics;
using ServiceStationContracts.StoragesContracts;
namespace ServiceStation namespace ServiceStation
@ -24,7 +25,7 @@ namespace ServiceStation
var services = new ServiceCollection(); var services = new ServiceCollection();
ConfigureServices(services); ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider(); _serviceProvider = services.BuildServiceProvider();
Application.Run(new Form1()); Application.Run(_serviceProvider.GetRequiredService<Form1>());
} }
private static void ConfigureServices(ServiceCollection services) private static void ConfigureServices(ServiceCollection services)
{ {
@ -35,9 +36,23 @@ namespace ServiceStation
}); });
services.AddTransient<IExecutorStorage, ExecutorStorage>(); services.AddTransient<IExecutorStorage, ExecutorStorage>();
services.AddTransient<IGuarantorStorage, GuarantorStorage>(); services.AddTransient<IGuarantorStorage, GuarantorStorage>();
//services.AddTransient<IExecutorLogic, ExecutorL>(); services.AddTransient<ICarStorage, CarStorage>();
//services.AddTransient<IGuarantorLogic, GuarantorLogic>(); services.AddTransient<IDefectStorage, DefectStorage>();
services.AddTransient<IRepairStorage, RepairStorage>();
services.AddTransient<ISparePartStorage, SparePartStorage>();
services.AddTransient<ITechnicalWorkStorage, TechnicalWorkStorage>();
services.AddTransient<IWorkStorage, WorkStorage>();
services.AddTransient<IExecutorLogic, ExecutorLogic>();
services.AddTransient<IGuarantorLogic, GuarantorLogic>();
services.AddTransient<ICarLogic, CarLogic>();
services.AddTransient<IDefectLogic, DefectLogic>();
services.AddTransient<IRepairLogic, RepairLogic>();
services.AddTransient<ISparePartLogic, SparePartLogic>();
services.AddTransient<ITechnicalWorkLogic, TechnicalWorkLogic>();
services.AddTransient<IWorkLogic, WorkLogic>();
services.AddTransient<Form1>();
} }
} }
} }

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true" internalLogLevel="Info">
<targets>
<target xsi:type="File" name="tofile" fileName="log-${shortdate}.log" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="tofile" />
</rules>
</nlog>
</configuration>

View File

@ -18,7 +18,7 @@ namespace ServiceStationBusinessLogic.BusinessLogics
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly ICarStorage _carStorage; private readonly ICarStorage _carStorage;
public CarLogic(ILogger logger, ICarStorage carStorage) public CarLogic(ILogger<CarLogic> logger, ICarStorage carStorage)
{ {
_logger = logger; _logger = logger;
_carStorage = carStorage; _carStorage = carStorage;

View File

@ -17,7 +17,7 @@ namespace ServiceStationBusinessLogic.BusinessLogics
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IDefectStorage _defectStorage; private readonly IDefectStorage _defectStorage;
public DefectLogic(ILogger logger, IDefectStorage defectStorage) public DefectLogic(ILogger<DefectLogic> logger, IDefectStorage defectStorage)
{ {
_logger = logger; _logger = logger;
_defectStorage = defectStorage; _defectStorage = defectStorage;

View File

@ -17,7 +17,7 @@ namespace ServiceStationBusinessLogic.BusinessLogics
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IExecutorStorage _executorStorage; private readonly IExecutorStorage _executorStorage;
public ExecutorLogic(ILogger logger, IExecutorStorage executorStorage) public ExecutorLogic(ILogger<IExecutorLogic> logger, IExecutorStorage executorStorage)
{ {
_logger = logger; _logger = logger;
_executorStorage = executorStorage; _executorStorage = executorStorage;

View File

@ -17,7 +17,7 @@ namespace ServiceStationBusinessLogic.BusinessLogics
private ILogger _logger; private ILogger _logger;
private ITechnicalWorkStorage _technicalWorkStorage; private ITechnicalWorkStorage _technicalWorkStorage;
public TechnicalWorkLogic(ILogger logger, ITechnicalWorkStorage technicalWorkStorage) public TechnicalWorkLogic(ILogger<TechnicalWorkLogic> logger, ITechnicalWorkStorage technicalWorkStorage)
{ {
_logger = logger; _logger = logger;
_technicalWorkStorage = technicalWorkStorage; _technicalWorkStorage = technicalWorkStorage;

View File

@ -18,6 +18,8 @@ namespace ServiceStationContracts.BindingModels
public int ExecutorId { get; set; } public int ExecutorId { get; set; }
public int? RepairId { get; set; }
public Dictionary<int, ICarModel> DefectCars { get; set; } = new(); public Dictionary<int, ICarModel> DefectCars { get; set; } = new();
} }
} }

View File

@ -20,7 +20,7 @@ namespace ServiceStationContracts.BindingModels
public int GuarantorId { get; set; } public int GuarantorId { get; set; }
public int DefectId { get; set; } public int? DefectId { get; set; }
public Dictionary<int, ISparePartModel> RepairSpareParts { get; set; } = new(); public Dictionary<int, ISparePartModel> RepairSpareParts { get; set; } = new();
} }

View File

@ -20,7 +20,7 @@ namespace ServiceStationContracts.BindingModels
public int GuarantorId { get; set; } public int GuarantorId { get; set; }
public int TechnicalWorkId { get; set; } public int? TechnicalWorkId { get; set; }
public Dictionary<int, ISparePartModel> WorkSpareParts { get; set; } = new(); public Dictionary<int, ISparePartModel> WorkSpareParts { get; set; } = new();
} }

View File

@ -19,9 +19,5 @@ namespace ServiceStationContracts.ViewModels
public string CarBrand { get; set; } = string.Empty; public string CarBrand { get; set; } = string.Empty;
public int ExecutorId { get; set; } public int ExecutorId { get; set; }
public Dictionary<int, IDefectModel> CarDefects { get; set; } = new();
public Dictionary<int, ITechnicalWorkModel> CarTechnicalWorks { get; set; } = new();
} }
} }

View File

@ -21,6 +21,8 @@ namespace ServiceStationContracts.ViewModels
public int ExecutorId { get; set; } public int ExecutorId { get; set; }
public int? RepairId { get; set; }
public Dictionary<int, ICarModel> DefectCars { get; set; } = new(); public Dictionary<int, ICarModel> DefectCars { get; set; } = new();
} }
} }

View File

@ -24,7 +24,7 @@ namespace ServiceStationContracts.ViewModels
public int GuarantorId { get; set; } public int GuarantorId { get; set; }
public int DefectId { get; set; } public int? DefectId { get; set; }
public Dictionary<int, ISparePartModel> RepairSpareParts { get; set; } = new(); public Dictionary<int, ISparePartModel> RepairSpareParts { get; set; } = new();
} }

View File

@ -1,11 +1,7 @@
using ServiceStationDataModels.Enums; using ServiceStationDataModels.Enums;
using ServiceStationDataModels.Models; using ServiceStationDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ServiceStationContracts.ViewModels namespace ServiceStationContracts.ViewModels
{ {
@ -24,8 +20,8 @@ namespace ServiceStationContracts.ViewModels
public int GuarantorId { get; set; } public int GuarantorId { get; set; }
public int TechnicalWorkId { get; set; } public int? TechnicalWorkId { get; set; }
public Dictionary<int, ISparePartModel> WorkSpareParts { get; } = new(); public Dictionary<int, ISparePartModel> WorkSpareParts { get; set; } = new();
} }
} }

View File

@ -12,6 +12,7 @@ namespace ServiceStationDataModels.Models
string DefectType { get; } string DefectType { get; }
double DefectPrice { get; } double DefectPrice { get; }
int ExecutorId { get; } int ExecutorId { get; }
int? RepairId { get; }
public Dictionary<int, ICarModel> DefectCars { get; } public Dictionary<int, ICarModel> DefectCars { get; }
} }
} }

View File

@ -16,8 +16,6 @@ namespace ServiceStationDataModels.Models
int GuarantorId { get; } int GuarantorId { get; }
int DefectId { get; }
public Dictionary<int, ISparePartModel> RepairSpareParts { get; } public Dictionary<int, ISparePartModel> RepairSpareParts { get; }
} }
} }

View File

@ -16,7 +16,7 @@ namespace ServiceStationDataModels.Models
int GuarantorId { get; } int GuarantorId { get; }
int TechnicalWorkId { get; } int? TechnicalWorkId { get; }
public Dictionary<int, ISparePartModel> WorkSpareParts { get; } public Dictionary<int, ISparePartModel> WorkSpareParts { get; }
} }

View File

@ -23,7 +23,7 @@ namespace ServiceStationDatabaseImplement.Implements
.ThenInclude(x => x.Car) .ThenInclude(x => x.Car)
.ThenInclude(x => x.CarTechnicalWorks) .ThenInclude(x => x.CarTechnicalWorks)
.ThenInclude(x => x.TechnicalWork) .ThenInclude(x => x.TechnicalWork)
.Include(x => x.Repairs) .Include(x => x.Repair)
.Include(x => x.Executor) .Include(x => x.Executor)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
@ -41,7 +41,7 @@ namespace ServiceStationDatabaseImplement.Implements
.ThenInclude(x => x.Car) .ThenInclude(x => x.Car)
.ThenInclude(x => x.CarTechnicalWorks) .ThenInclude(x => x.CarTechnicalWorks)
.ThenInclude(x => x.TechnicalWork) .ThenInclude(x => x.TechnicalWork)
.Include(x => x.Repairs) .Include(x => x.Repair)
.Include(x => x.Executor) .Include(x => x.Executor)
.Where(x => x.ExecutorId == model.ExecutorId) .Where(x => x.ExecutorId == model.ExecutorId)
.ToList() .ToList()
@ -53,7 +53,7 @@ namespace ServiceStationDatabaseImplement.Implements
.ThenInclude(x => x.Car) .ThenInclude(x => x.Car)
.ThenInclude(x => x.CarTechnicalWorks) .ThenInclude(x => x.CarTechnicalWorks)
.ThenInclude(x => x.TechnicalWork) .ThenInclude(x => x.TechnicalWork)
.Include(x => x.Repairs) .Include(x => x.Repair)
.Include(x => x.Executor) .Include(x => x.Executor)
.Where(x => x.DefectType == model.DefectType) .Where(x => x.DefectType == model.DefectType)
.ToList() .ToList()
@ -72,7 +72,7 @@ namespace ServiceStationDatabaseImplement.Implements
.ThenInclude(x => x.Car) .ThenInclude(x => x.Car)
.ThenInclude(x => x.CarTechnicalWorks) .ThenInclude(x => x.CarTechnicalWorks)
.ThenInclude(x => x.TechnicalWork) .ThenInclude(x => x.TechnicalWork)
.Include(x => x.Repairs) .Include(x => x.Repair)
.Include(x => x.Executor) .Include(x => x.Executor)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.DefectType) && x.DefectType == model.DefectType) || (model.Id.HasValue && x.Id == model.Id))? .FirstOrDefault(x => (!string.IsNullOrEmpty(model.DefectType) && x.DefectType == model.DefectType) || (model.Id.HasValue && x.Id == model.Id))?
.GetViewModel; .GetViewModel;
@ -98,7 +98,7 @@ namespace ServiceStationDatabaseImplement.Implements
if (elem == null) return null; if (elem == null) return null;
elem.Update(model); elem.Update(model);
context.SaveChanges(); context.SaveChanges();
if (model.DefectCars != null) elem.UpdateCars(context, model); if (model.DefectCars.Count != 0) elem.UpdateCars(context, model);
transaction.Commit(); transaction.Commit();
return elem.GetViewModel; return elem.GetViewModel;
} }

View File

@ -25,14 +25,14 @@ namespace ServiceStationDatabaseImplement.Implements
public List<ExecutorViewModel> GetFilteredList(ExecutorSearchModel model) public List<ExecutorViewModel> GetFilteredList(ExecutorSearchModel model)
{ {
if (string.IsNullOrEmpty(model.ExecutorFIO)) return new(); if (string.IsNullOrEmpty(model.ExecutorNumber)) return new();
using var context = new ServiceStationDatabase(); using var context = new ServiceStationDatabase();
return context.Executors return context.Executors
.Include(x => x.Cars) .Include(x => x.Cars)
.Include(x => x.Defects) .Include(x => x.Defects)
.Include(x => x.TechnicalWorks) .Include(x => x.TechnicalWorks)
.Where(x => x.ExecutorFIO.Contains(model.ExecutorFIO)) .Where(x => x.ExecutorNumber.Contains(model.ExecutorNumber))
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
@ -40,15 +40,15 @@ namespace ServiceStationDatabaseImplement.Implements
public ExecutorViewModel? GetElement(ExecutorSearchModel model) public ExecutorViewModel? GetElement(ExecutorSearchModel model)
{ {
using var context = new ServiceStationDatabase(); using var context = new ServiceStationDatabase();
if (!model.Id.HasValue && !string.IsNullOrEmpty(model.ExecutorFIO)) return null; if (!model.Id.HasValue && string.IsNullOrEmpty(model.ExecutorNumber)) return null;
if (!string.IsNullOrEmpty(model.ExecutorFIO)) if (!string.IsNullOrEmpty(model.ExecutorNumber))
{ {
return context.Executors return context.Executors
.Include(x => x.Cars) .Include(x => x.Cars)
.Include(x => x.Defects) .Include(x => x.Defects)
.Include(x => x.TechnicalWorks) .Include(x => x.TechnicalWorks)
.FirstOrDefault(x => x.ExecutorFIO.Contains(model.ExecutorFIO))? .FirstOrDefault(x => x.ExecutorNumber.Contains(model.ExecutorNumber))?
.GetViewModel; .GetViewModel;
} }
return context.Executors return context.Executors

View File

@ -22,7 +22,6 @@ namespace ServiceStationDatabaseImplement.Implements
.ThenInclude(x => x.SparePart) .ThenInclude(x => x.SparePart)
.ThenInclude(x => x.SparePartWorks) .ThenInclude(x => x.SparePartWorks)
.ThenInclude(x => x.Work) .ThenInclude(x => x.Work)
//.Include(x => x.Defect)
.Include(x => x.Guarantor) .Include(x => x.Guarantor)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
@ -40,7 +39,6 @@ namespace ServiceStationDatabaseImplement.Implements
.ThenInclude(x => x.SparePart) .ThenInclude(x => x.SparePart)
.ThenInclude(x => x.SparePartWorks) .ThenInclude(x => x.SparePartWorks)
.ThenInclude(x => x.Work) .ThenInclude(x => x.Work)
//.Include(x => x.Defect)
.Include(x => x.Guarantor) .Include(x => x.Guarantor)
.Where(x => x.GuarantorId == model.GuarantorId) .Where(x => x.GuarantorId == model.GuarantorId)
.ToList() .ToList()
@ -52,7 +50,6 @@ namespace ServiceStationDatabaseImplement.Implements
.ThenInclude(x => x.SparePart) .ThenInclude(x => x.SparePart)
.ThenInclude(x => x.SparePartWorks) .ThenInclude(x => x.SparePartWorks)
.ThenInclude(x => x.Work) .ThenInclude(x => x.Work)
//.Include(x => x.Defect)
.Include(x => x.Guarantor) .Include(x => x.Guarantor)
.Where(x => x.RepairName == model.RepairName) .Where(x => x.RepairName == model.RepairName)
.ToList() .ToList()
@ -71,7 +68,6 @@ namespace ServiceStationDatabaseImplement.Implements
.ThenInclude(x => x.SparePart) .ThenInclude(x => x.SparePart)
.ThenInclude(x => x.SparePartWorks) .ThenInclude(x => x.SparePartWorks)
.ThenInclude(x => x.Work) .ThenInclude(x => x.Work)
//.Include(x => x.Defect)
.Include(x => x.Guarantor) .Include(x => x.Guarantor)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.RepairName) && x.RepairName == model.RepairName) || (model.Id.HasValue && x.Id == model.Id))? .FirstOrDefault(x => (!string.IsNullOrEmpty(model.RepairName) && x.RepairName == model.RepairName) || (model.Id.HasValue && x.Id == model.Id))?
.GetViewModel; .GetViewModel;

View File

@ -23,7 +23,6 @@ namespace ServiceStationDatabaseImplement.Implements
.ThenInclude(x => x.Car) .ThenInclude(x => x.Car)
.ThenInclude(x => x.CarDefects) .ThenInclude(x => x.CarDefects)
.ThenInclude(x => x.Defect) .ThenInclude(x => x.Defect)
.Include(x => x.Work)
.Include(x => x.Executor) .Include(x => x.Executor)
.ToList() .ToList()
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
@ -45,7 +44,6 @@ namespace ServiceStationDatabaseImplement.Implements
.ThenInclude(x => x.Car) .ThenInclude(x => x.Car)
.ThenInclude(x => x.CarDefects) .ThenInclude(x => x.CarDefects)
.ThenInclude(x => x.Defect) .ThenInclude(x => x.Defect)
.Include(x => x.Work)
.Include(x => x.Executor) .Include(x => x.Executor)
.Where(x => x.DateStartWork >= model.DateFrom && x.DateStartWork <= model.DateTo && x.ExecutorId == model.ExecutorId) .Where(x => x.DateStartWork >= model.DateFrom && x.DateStartWork <= model.DateTo && x.ExecutorId == model.ExecutorId)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
@ -58,7 +56,6 @@ namespace ServiceStationDatabaseImplement.Implements
.ThenInclude(x => x.Car) .ThenInclude(x => x.Car)
.ThenInclude(x => x.CarDefects) .ThenInclude(x => x.CarDefects)
.ThenInclude(x => x.Defect) .ThenInclude(x => x.Defect)
.Include(x => x.Work)
.Include(x => x.Executor) .Include(x => x.Executor)
.Where(x => x.ExecutorId == model.ExecutorId) .Where(x => x.ExecutorId == model.ExecutorId)
.ToList() .ToList()
@ -70,7 +67,6 @@ namespace ServiceStationDatabaseImplement.Implements
.ThenInclude(x => x.Car) .ThenInclude(x => x.Car)
.ThenInclude(x => x.CarDefects) .ThenInclude(x => x.CarDefects)
.ThenInclude(x => x.Defect) .ThenInclude(x => x.Defect)
.Include(x => x.Work)
.Include(x => x.Executor) .Include(x => x.Executor)
.Where(x => x.WorkType.Contains(model.WorkType)) .Where(x => x.WorkType.Contains(model.WorkType))
.ToList() .ToList()
@ -88,7 +84,6 @@ namespace ServiceStationDatabaseImplement.Implements
.ThenInclude(x => x.Car) .ThenInclude(x => x.Car)
.ThenInclude(x => x.CarDefects) .ThenInclude(x => x.CarDefects)
.ThenInclude(x => x.Defect) .ThenInclude(x => x.Defect)
.Include(x => x.Work)
.Include(x => x.Executor) .Include(x => x.Executor)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.WorkType) && x.WorkType == model.WorkType) || (model.Id.HasValue && x.Id == model.Id))? .FirstOrDefault(x => (!string.IsNullOrEmpty(model.WorkType) && x.WorkType == model.WorkType) || (model.Id.HasValue && x.Id == model.Id))?
.GetViewModel; .GetViewModel;

View File

@ -44,7 +44,6 @@ namespace ServiceStationDatabaseImplement.Implements
.ThenInclude(x => x.SparePart) .ThenInclude(x => x.SparePart)
.ThenInclude(x => x.SparePartRepairs) .ThenInclude(x => x.SparePartRepairs)
.ThenInclude(x => x.Repair) .ThenInclude(x => x.Repair)
//.Include(x => x.TechnicalWork)
.Include(x => x.Guarantor) .Include(x => x.Guarantor)
.Where(x => x.GuarantorId == model.GuarantorId) .Where(x => x.GuarantorId == model.GuarantorId)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
@ -57,7 +56,6 @@ namespace ServiceStationDatabaseImplement.Implements
.ThenInclude(x => x.SparePart) .ThenInclude(x => x.SparePart)
.ThenInclude(x => x.SparePartRepairs) .ThenInclude(x => x.SparePartRepairs)
.ThenInclude(x => x.Repair) .ThenInclude(x => x.Repair)
//.Include(x => x.TechnicalWork)
.Include(x => x.Guarantor) .Include(x => x.Guarantor)
.Where(x => x.GuarantorId == model.GuarantorId) .Where(x => x.GuarantorId == model.GuarantorId)
.ToList() .ToList()
@ -69,7 +67,6 @@ namespace ServiceStationDatabaseImplement.Implements
.ThenInclude(x => x.SparePart) .ThenInclude(x => x.SparePart)
.ThenInclude(x => x.SparePartRepairs) .ThenInclude(x => x.SparePartRepairs)
.ThenInclude(x => x.Repair) .ThenInclude(x => x.Repair)
//.Include(x => x.TechnicalWork)
.Include(x => x.Guarantor) .Include(x => x.Guarantor)
.Where(x => x.WorkName.Contains(model.WorkName)) .Where(x => x.WorkName.Contains(model.WorkName))
.ToList() .ToList()
@ -82,15 +79,15 @@ namespace ServiceStationDatabaseImplement.Implements
if (string.IsNullOrEmpty(model.WorkName) && !model.Id.HasValue) return null; if (string.IsNullOrEmpty(model.WorkName) && !model.Id.HasValue) return null;
using var context = new ServiceStationDatabase(); using var context = new ServiceStationDatabase();
return context.Works var elem = context.Works
.Include(x => x.SpareParts) .Include(x => x.SpareParts)
.ThenInclude(x => x.SparePart) .ThenInclude(x => x.SparePart)
.ThenInclude(x => x.SparePartRepairs) .ThenInclude(x => x.SparePartRepairs)
.ThenInclude(x => x.Repair) .ThenInclude(x => x.Repair)
//.Include(x => x.TechnicalWork)
.Include(x => x.Guarantor) .Include(x => x.Guarantor)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.WorkName) && x.WorkName == model.WorkName) || (model.Id.HasValue && x.Id == model.Id))? .FirstOrDefault(x => (!string.IsNullOrEmpty(model.WorkName) && x.WorkName == model.WorkName) || (model.Id.HasValue && x.Id == model.Id));
.GetViewModel;
return elem?.GetViewModel;
} }
public WorkViewModel? Insert(WorkBindingModel model) public WorkViewModel? Insert(WorkBindingModel model)
@ -116,7 +113,7 @@ namespace ServiceStationDatabaseImplement.Implements
elem.Update(model); elem.Update(model);
context.SaveChanges(); context.SaveChanges();
if (model.WorkSpareParts != null) elem.UpdateSpareParts(context, model); if (model.WorkSpareParts.Count != 0) elem.UpdateSpareParts(context, model);
transaction.Commit(); transaction.Commit();
return elem.GetViewModel; return elem.GetViewModel;
} }

View File

@ -12,7 +12,7 @@ using ServiceStationDatabaseImplement;
namespace ServiceStationDatabaseImplement.Migrations namespace ServiceStationDatabaseImplement.Migrations
{ {
[DbContext(typeof(ServiceStationDatabase))] [DbContext(typeof(ServiceStationDatabase))]
[Migration("20240427193650_InitMigration")] [Migration("20240428190245_InitMigration")]
partial class InitMigration partial class InitMigration
{ {
/// <inheritdoc /> /// <inheritdoc />
@ -115,10 +115,15 @@ namespace ServiceStationDatabaseImplement.Migrations
b.Property<int>("ExecutorId") b.Property<int>("ExecutorId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int?>("RepairId")
.HasColumnType("int");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("ExecutorId"); b.HasIndex("ExecutorId");
b.HasIndex("RepairId");
b.ToTable("Defects"); b.ToTable("Defects");
}); });
@ -186,9 +191,6 @@ namespace ServiceStationDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("DefectId")
.HasColumnType("int");
b.Property<int>("GuarantorId") b.Property<int>("GuarantorId")
.HasColumnType("int"); .HasColumnType("int");
@ -204,8 +206,6 @@ namespace ServiceStationDatabaseImplement.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("DefectId");
b.HasIndex("GuarantorId"); b.HasIndex("GuarantorId");
b.ToTable("Repairs"); b.ToTable("Repairs");
@ -296,9 +296,6 @@ namespace ServiceStationDatabaseImplement.Migrations
b.Property<int>("ExecutorId") b.Property<int>("ExecutorId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("WorkId")
.HasColumnType("int");
b.Property<double>("WorkPrice") b.Property<double>("WorkPrice")
.HasColumnType("float"); .HasColumnType("float");
@ -310,8 +307,6 @@ namespace ServiceStationDatabaseImplement.Migrations
b.HasIndex("ExecutorId"); b.HasIndex("ExecutorId");
b.HasIndex("WorkId");
b.ToTable("TechnicalWorks"); b.ToTable("TechnicalWorks");
}); });
@ -329,7 +324,7 @@ namespace ServiceStationDatabaseImplement.Migrations
b.Property<int>("Status") b.Property<int>("Status")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("TechnicalWorkId") b.Property<int?>("TechnicalWorkId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<string>("WorkName") b.Property<string>("WorkName")
@ -343,6 +338,8 @@ namespace ServiceStationDatabaseImplement.Migrations
b.HasIndex("GuarantorId"); b.HasIndex("GuarantorId");
b.HasIndex("TechnicalWorkId");
b.ToTable("Works"); b.ToTable("Works");
}); });
@ -403,17 +400,17 @@ namespace ServiceStationDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("ServiceStationDatabaseImplement.Models.Repair", "Repair")
.WithMany("Defects")
.HasForeignKey("RepairId");
b.Navigation("Executor"); b.Navigation("Executor");
b.Navigation("Repair");
}); });
modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Repair", b => modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Repair", b =>
{ {
b.HasOne("ServiceStationDatabaseImplement.Models.Defect", null)
.WithMany("Repairs")
.HasForeignKey("DefectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ServiceStationDatabaseImplement.Models.Guarantor", "Guarantor") b.HasOne("ServiceStationDatabaseImplement.Models.Guarantor", "Guarantor")
.WithMany("Repairs") .WithMany("Repairs")
.HasForeignKey("GuarantorId") .HasForeignKey("GuarantorId")
@ -480,15 +477,7 @@ namespace ServiceStationDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("ServiceStationDatabaseImplement.Models.Work", "Work")
.WithMany("TechnicalWorks")
.HasForeignKey("WorkId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Executor"); b.Navigation("Executor");
b.Navigation("Work");
}); });
modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Work", b => modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Work", b =>
@ -499,7 +488,13 @@ namespace ServiceStationDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("ServiceStationDatabaseImplement.Models.TechnicalWork", "TechnicalWork")
.WithMany("Works")
.HasForeignKey("TechnicalWorkId");
b.Navigation("Guarantor"); b.Navigation("Guarantor");
b.Navigation("TechnicalWork");
}); });
modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Car", b => modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Car", b =>
@ -512,8 +507,6 @@ namespace ServiceStationDatabaseImplement.Migrations
modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Defect", b => modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Defect", b =>
{ {
b.Navigation("Cars"); b.Navigation("Cars");
b.Navigation("Repairs");
}); });
modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Executor", b => modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Executor", b =>
@ -536,6 +529,8 @@ namespace ServiceStationDatabaseImplement.Migrations
modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Repair", b => modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Repair", b =>
{ {
b.Navigation("Defects");
b.Navigation("SpareParts"); b.Navigation("SpareParts");
}); });
@ -549,13 +544,13 @@ namespace ServiceStationDatabaseImplement.Migrations
modelBuilder.Entity("ServiceStationDatabaseImplement.Models.TechnicalWork", b => modelBuilder.Entity("ServiceStationDatabaseImplement.Models.TechnicalWork", b =>
{ {
b.Navigation("Cars"); b.Navigation("Cars");
b.Navigation("Works");
}); });
modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Work", b => modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Work", b =>
{ {
b.Navigation("SpareParts"); b.Navigation("SpareParts");
b.Navigation("TechnicalWorks");
}); });
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }

View File

@ -65,26 +65,49 @@ namespace ServiceStationDatabaseImplement.Migrations
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Defects", name: "TechnicalWorks",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
DefectType = table.Column<string>(type: "nvarchar(max)", nullable: false), WorkType = table.Column<string>(type: "nvarchar(max)", nullable: false),
DefectPrice = table.Column<double>(type: "float", nullable: false), DateStartWork = table.Column<DateTime>(type: "datetime2", nullable: true),
WorkPrice = table.Column<double>(type: "float", nullable: false),
ExecutorId = table.Column<int>(type: "int", nullable: false) ExecutorId = table.Column<int>(type: "int", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Defects", x => x.Id); table.PrimaryKey("PK_TechnicalWorks", x => x.Id);
table.ForeignKey( table.ForeignKey(
name: "FK_Defects_Executors_ExecutorId", name: "FK_TechnicalWorks_Executors_ExecutorId",
column: x => x.ExecutorId, column: x => x.ExecutorId,
principalTable: "Executors", principalTable: "Executors",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable(
name: "Repairs",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
RepairName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
RepairPrice = table.Column<double>(type: "float", nullable: false),
GuarantorId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Repairs", x => x.Id);
table.ForeignKey(
name: "FK_Repairs_Guarantors_GuarantorId",
column: x => x.GuarantorId,
principalTable: "Guarantors",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "SpareParts", name: "SpareParts",
columns: table => new columns: table => new
@ -106,6 +129,32 @@ namespace ServiceStationDatabaseImplement.Migrations
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable(
name: "CarTechnicalWorks",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
CarId = table.Column<int>(type: "int", nullable: false),
TechnicalWorkId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_CarTechnicalWorks", x => x.Id);
table.ForeignKey(
name: "FK_CarTechnicalWorks_Cars_CarId",
column: x => x.CarId,
principalTable: "Cars",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_CarTechnicalWorks_TechnicalWorks_TechnicalWorkId",
column: x => x.TechnicalWorkId,
principalTable: "TechnicalWorks",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Works", name: "Works",
columns: table => new columns: table => new
@ -116,7 +165,7 @@ namespace ServiceStationDatabaseImplement.Migrations
Status = table.Column<int>(type: "int", nullable: false), Status = table.Column<int>(type: "int", nullable: false),
WorkPrice = table.Column<double>(type: "float", nullable: false), WorkPrice = table.Column<double>(type: "float", nullable: false),
GuarantorId = table.Column<int>(type: "int", nullable: false), GuarantorId = table.Column<int>(type: "int", nullable: false),
TechnicalWorkId = table.Column<int>(type: "int", nullable: false) TechnicalWorkId = table.Column<int>(type: "int", nullable: true)
}, },
constraints: table => constraints: table =>
{ {
@ -127,59 +176,62 @@ namespace ServiceStationDatabaseImplement.Migrations
principalTable: "Guarantors", principalTable: "Guarantors",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Works_TechnicalWorks_TechnicalWorkId",
column: x => x.TechnicalWorkId,
principalTable: "TechnicalWorks",
principalColumn: "Id");
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "CarDefects", name: "Defects",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
CarId = table.Column<int>(type: "int", nullable: false), DefectType = table.Column<string>(type: "nvarchar(max)", nullable: false),
DefectId = table.Column<int>(type: "int", nullable: false) DefectPrice = table.Column<double>(type: "float", nullable: false),
ExecutorId = table.Column<int>(type: "int", nullable: false),
RepairId = table.Column<int>(type: "int", nullable: true)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_CarDefects", x => x.Id); table.PrimaryKey("PK_Defects", x => x.Id);
table.ForeignKey( table.ForeignKey(
name: "FK_CarDefects_Cars_CarId", name: "FK_Defects_Executors_ExecutorId",
column: x => x.CarId, column: x => x.ExecutorId,
principalTable: "Cars", principalTable: "Executors",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_CarDefects_Defects_DefectId", name: "FK_Defects_Repairs_RepairId",
column: x => x.DefectId, column: x => x.RepairId,
principalTable: "Defects", principalTable: "Repairs",
principalColumn: "Id", principalColumn: "Id");
onDelete: ReferentialAction.Restrict);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Repairs", name: "SparePartRepairs",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
RepairName = table.Column<string>(type: "nvarchar(max)", nullable: false), SparePartId = table.Column<int>(type: "int", nullable: false),
Status = table.Column<int>(type: "int", nullable: false), RepairId = table.Column<int>(type: "int", nullable: false)
RepairPrice = table.Column<double>(type: "float", nullable: false),
GuarantorId = table.Column<int>(type: "int", nullable: false),
DefectId = table.Column<int>(type: "int", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Repairs", x => x.Id); table.PrimaryKey("PK_SparePartRepairs", x => x.Id);
table.ForeignKey( table.ForeignKey(
name: "FK_Repairs_Defects_DefectId", name: "FK_SparePartRepairs_Repairs_RepairId",
column: x => x.DefectId, column: x => x.RepairId,
principalTable: "Defects", principalTable: "Repairs",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_Repairs_Guarantors_GuarantorId", name: "FK_SparePartRepairs_SpareParts_SparePartId",
column: x => x.GuarantorId, column: x => x.SparePartId,
principalTable: "Guarantors", principalTable: "SpareParts",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Restrict); onDelete: ReferentialAction.Restrict);
}); });
@ -211,82 +263,27 @@ namespace ServiceStationDatabaseImplement.Migrations
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "TechnicalWorks", name: "CarDefects",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
WorkType = table.Column<string>(type: "nvarchar(max)", nullable: false),
DateStartWork = table.Column<DateTime>(type: "datetime2", nullable: true),
WorkPrice = table.Column<double>(type: "float", nullable: false),
ExecutorId = table.Column<int>(type: "int", nullable: false),
WorkId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TechnicalWorks", x => x.Id);
table.ForeignKey(
name: "FK_TechnicalWorks_Executors_ExecutorId",
column: x => x.ExecutorId,
principalTable: "Executors",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_TechnicalWorks_Works_WorkId",
column: x => x.WorkId,
principalTable: "Works",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "SparePartRepairs",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
SparePartId = table.Column<int>(type: "int", nullable: false),
RepairId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SparePartRepairs", x => x.Id);
table.ForeignKey(
name: "FK_SparePartRepairs_Repairs_RepairId",
column: x => x.RepairId,
principalTable: "Repairs",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_SparePartRepairs_SpareParts_SparePartId",
column: x => x.SparePartId,
principalTable: "SpareParts",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "CarTechnicalWorks",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "int", nullable: false) Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
CarId = table.Column<int>(type: "int", nullable: false), CarId = table.Column<int>(type: "int", nullable: false),
TechnicalWorkId = table.Column<int>(type: "int", nullable: false) DefectId = table.Column<int>(type: "int", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_CarTechnicalWorks", x => x.Id); table.PrimaryKey("PK_CarDefects", x => x.Id);
table.ForeignKey( table.ForeignKey(
name: "FK_CarTechnicalWorks_Cars_CarId", name: "FK_CarDefects_Cars_CarId",
column: x => x.CarId, column: x => x.CarId,
principalTable: "Cars", principalTable: "Cars",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_CarTechnicalWorks_TechnicalWorks_TechnicalWorkId", name: "FK_CarDefects_Defects_DefectId",
column: x => x.TechnicalWorkId, column: x => x.DefectId,
principalTable: "TechnicalWorks", principalTable: "Defects",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Restrict); onDelete: ReferentialAction.Restrict);
}); });
@ -322,9 +319,9 @@ namespace ServiceStationDatabaseImplement.Migrations
column: "ExecutorId"); column: "ExecutorId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Repairs_DefectId", name: "IX_Defects_RepairId",
table: "Repairs", table: "Defects",
column: "DefectId"); column: "RepairId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Repairs_GuarantorId", name: "IX_Repairs_GuarantorId",
@ -361,15 +358,15 @@ namespace ServiceStationDatabaseImplement.Migrations
table: "TechnicalWorks", table: "TechnicalWorks",
column: "ExecutorId"); column: "ExecutorId");
migrationBuilder.CreateIndex(
name: "IX_TechnicalWorks_WorkId",
table: "TechnicalWorks",
column: "WorkId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Works_GuarantorId", name: "IX_Works_GuarantorId",
table: "Works", table: "Works",
column: "GuarantorId"); column: "GuarantorId");
migrationBuilder.CreateIndex(
name: "IX_Works_TechnicalWorkId",
table: "Works",
column: "TechnicalWorkId");
} }
/// <inheritdoc /> /// <inheritdoc />
@ -387,15 +384,12 @@ namespace ServiceStationDatabaseImplement.Migrations
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "SparePartWorks"); name: "SparePartWorks");
migrationBuilder.DropTable(
name: "Defects");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Cars"); name: "Cars");
migrationBuilder.DropTable(
name: "TechnicalWorks");
migrationBuilder.DropTable(
name: "Repairs");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "SpareParts"); name: "SpareParts");
@ -403,7 +397,10 @@ namespace ServiceStationDatabaseImplement.Migrations
name: "Works"); name: "Works");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Defects"); name: "Repairs");
migrationBuilder.DropTable(
name: "TechnicalWorks");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Guarantors"); name: "Guarantors");

View File

@ -112,10 +112,15 @@ namespace ServiceStationDatabaseImplement.Migrations
b.Property<int>("ExecutorId") b.Property<int>("ExecutorId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int?>("RepairId")
.HasColumnType("int");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("ExecutorId"); b.HasIndex("ExecutorId");
b.HasIndex("RepairId");
b.ToTable("Defects"); b.ToTable("Defects");
}); });
@ -183,9 +188,6 @@ namespace ServiceStationDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("DefectId")
.HasColumnType("int");
b.Property<int>("GuarantorId") b.Property<int>("GuarantorId")
.HasColumnType("int"); .HasColumnType("int");
@ -201,8 +203,6 @@ namespace ServiceStationDatabaseImplement.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("DefectId");
b.HasIndex("GuarantorId"); b.HasIndex("GuarantorId");
b.ToTable("Repairs"); b.ToTable("Repairs");
@ -293,9 +293,6 @@ namespace ServiceStationDatabaseImplement.Migrations
b.Property<int>("ExecutorId") b.Property<int>("ExecutorId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("WorkId")
.HasColumnType("int");
b.Property<double>("WorkPrice") b.Property<double>("WorkPrice")
.HasColumnType("float"); .HasColumnType("float");
@ -307,8 +304,6 @@ namespace ServiceStationDatabaseImplement.Migrations
b.HasIndex("ExecutorId"); b.HasIndex("ExecutorId");
b.HasIndex("WorkId");
b.ToTable("TechnicalWorks"); b.ToTable("TechnicalWorks");
}); });
@ -326,7 +321,7 @@ namespace ServiceStationDatabaseImplement.Migrations
b.Property<int>("Status") b.Property<int>("Status")
.HasColumnType("int"); .HasColumnType("int");
b.Property<int>("TechnicalWorkId") b.Property<int?>("TechnicalWorkId")
.HasColumnType("int"); .HasColumnType("int");
b.Property<string>("WorkName") b.Property<string>("WorkName")
@ -340,6 +335,8 @@ namespace ServiceStationDatabaseImplement.Migrations
b.HasIndex("GuarantorId"); b.HasIndex("GuarantorId");
b.HasIndex("TechnicalWorkId");
b.ToTable("Works"); b.ToTable("Works");
}); });
@ -400,17 +397,17 @@ namespace ServiceStationDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("ServiceStationDatabaseImplement.Models.Repair", "Repair")
.WithMany("Defects")
.HasForeignKey("RepairId");
b.Navigation("Executor"); b.Navigation("Executor");
b.Navigation("Repair");
}); });
modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Repair", b => modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Repair", b =>
{ {
b.HasOne("ServiceStationDatabaseImplement.Models.Defect", null)
.WithMany("Repairs")
.HasForeignKey("DefectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ServiceStationDatabaseImplement.Models.Guarantor", "Guarantor") b.HasOne("ServiceStationDatabaseImplement.Models.Guarantor", "Guarantor")
.WithMany("Repairs") .WithMany("Repairs")
.HasForeignKey("GuarantorId") .HasForeignKey("GuarantorId")
@ -477,15 +474,7 @@ namespace ServiceStationDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("ServiceStationDatabaseImplement.Models.Work", "Work")
.WithMany("TechnicalWorks")
.HasForeignKey("WorkId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Executor"); b.Navigation("Executor");
b.Navigation("Work");
}); });
modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Work", b => modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Work", b =>
@ -496,7 +485,13 @@ namespace ServiceStationDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("ServiceStationDatabaseImplement.Models.TechnicalWork", "TechnicalWork")
.WithMany("Works")
.HasForeignKey("TechnicalWorkId");
b.Navigation("Guarantor"); b.Navigation("Guarantor");
b.Navigation("TechnicalWork");
}); });
modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Car", b => modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Car", b =>
@ -509,8 +504,6 @@ namespace ServiceStationDatabaseImplement.Migrations
modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Defect", b => modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Defect", b =>
{ {
b.Navigation("Cars"); b.Navigation("Cars");
b.Navigation("Repairs");
}); });
modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Executor", b => modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Executor", b =>
@ -533,6 +526,8 @@ namespace ServiceStationDatabaseImplement.Migrations
modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Repair", b => modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Repair", b =>
{ {
b.Navigation("Defects");
b.Navigation("SpareParts"); b.Navigation("SpareParts");
}); });
@ -546,13 +541,13 @@ namespace ServiceStationDatabaseImplement.Migrations
modelBuilder.Entity("ServiceStationDatabaseImplement.Models.TechnicalWork", b => modelBuilder.Entity("ServiceStationDatabaseImplement.Models.TechnicalWork", b =>
{ {
b.Navigation("Cars"); b.Navigation("Cars");
b.Navigation("Works");
}); });
modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Work", b => modelBuilder.Entity("ServiceStationDatabaseImplement.Models.Work", b =>
{ {
b.Navigation("SpareParts"); b.Navigation("SpareParts");
b.Navigation("TechnicalWorks");
}); });
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }

View File

@ -25,7 +25,10 @@ namespace ServiceStationDatabaseImplement.Models
[Required] [Required]
public int ExecutorId { get; set; } public int ExecutorId { get; set; }
public int? RepairId { get; set; }
public virtual Executor Executor { get; set; } public virtual Executor Executor { get; set; }
public virtual Repair? Repair { get; set; }
private Dictionary<int, ICarModel>? _defectCars = null; private Dictionary<int, ICarModel>? _defectCars = null;
@ -43,8 +46,6 @@ namespace ServiceStationDatabaseImplement.Models
} }
[ForeignKey("DefectId")] [ForeignKey("DefectId")]
public virtual List<CarDefect> Cars { get; set; } = new(); public virtual List<CarDefect> Cars { get; set; } = new();
[ForeignKey("DefectId")]
public virtual List<Repair> Repairs { get; set; } = new();
public static Defect? Create(ServiceStationDatabase context, DefectBindingModel model) public static Defect? Create(ServiceStationDatabase context, DefectBindingModel model)
{ {
@ -65,6 +66,11 @@ namespace ServiceStationDatabaseImplement.Models
public void Update(DefectBindingModel model) public void Update(DefectBindingModel model)
{ {
if(model == null) return; if(model == null) return;
if (model.RepairId.HasValue)
{
RepairId = model.RepairId;
return;
}
DefectType = model.DefectType; DefectType = model.DefectType;
DefectPrice = model.DefectPrice; DefectPrice = model.DefectPrice;
} }

View File

@ -28,15 +28,11 @@ namespace ServiceStationDatabaseImplement.Models
[Required] [Required]
public int GuarantorId { get; set; } public int GuarantorId { get; set; }
[Required]
public int DefectId { get; set; }
public virtual Guarantor Guarantor { get; set; } public virtual Guarantor Guarantor { get; set; }
//public virtual Defect Defect { get; set; }
private Dictionary<int, ISparePartModel>? _repairSpareParts = null; private Dictionary<int, ISparePartModel>? _repairSpareParts = null;
[NotMapped]
public Dictionary<int, ISparePartModel> RepairSpareParts public Dictionary<int, ISparePartModel> RepairSpareParts
{ {
get get
@ -51,9 +47,9 @@ namespace ServiceStationDatabaseImplement.Models
[ForeignKey("RepairId")] [ForeignKey("RepairId")]
public virtual List<SparePartRepair> SpareParts { get; set; } = new(); public virtual List<SparePartRepair> SpareParts { get; set; } = new();
[ForeignKey("RepairId")]
public virtual List<Defect> Defects { get; set; } = new();
//[ForeignKey("RepairId")]
//public virtual List<Defect> Defects { get; set; } = new();
public static Repair? Create(ServiceStationDatabase context, RepairBindingModel model) public static Repair? Create(ServiceStationDatabase context, RepairBindingModel model)
{ {
@ -65,7 +61,6 @@ namespace ServiceStationDatabaseImplement.Models
Status = model.Status, Status = model.Status,
RepairPrice = model.RepairPrice, RepairPrice = model.RepairPrice,
GuarantorId = model.GuarantorId, GuarantorId = model.GuarantorId,
DefectId = model.DefectId,
SpareParts = model.RepairSpareParts.Select(x => new SparePartRepair SpareParts = model.RepairSpareParts.Select(x => new SparePartRepair
{ {
SparePart = context.SpareParts.First(y => y.Id == x.Key) SparePart = context.SpareParts.First(y => y.Id == x.Key)
@ -88,7 +83,6 @@ namespace ServiceStationDatabaseImplement.Models
Status = Status, Status = Status,
RepairPrice = RepairPrice, RepairPrice = RepairPrice,
GuarantorId = GuarantorId, GuarantorId = GuarantorId,
DefectId = DefectId,
RepairSpareParts = RepairSpareParts RepairSpareParts = RepairSpareParts
}; };

View File

@ -25,10 +25,12 @@ namespace ServiceStationDatabaseImplement.Models
[Required] [Required]
public int ExecutorId { get; set; } public int ExecutorId { get; set; }
public virtual Executor Executor { get; set; } public virtual Executor Executor { get; set; }
public virtual Work Work { get; set; }
private Dictionary<int, ICarModel>? _technicalWorkCars = null; private Dictionary<int, ICarModel>? _technicalWorkCars = null;
[NotMapped]
public Dictionary<int, ICarModel> TechnicalWorkCars public Dictionary<int, ICarModel> TechnicalWorkCars
{ {
get get
@ -42,6 +44,8 @@ namespace ServiceStationDatabaseImplement.Models
} }
[ForeignKey("TechnicalWorkId")] [ForeignKey("TechnicalWorkId")]
public virtual List<CarTechnicalWork> Cars { get; set; } = new(); public virtual List<CarTechnicalWork> Cars { get; set; } = new();
[ForeignKey("TechnicalWorkId")]
public virtual List<Work> Works { get; set; } = new();
public static TechnicalWork? Create(ServiceStationDatabase context, TechnicalWorkBindingModel model) public static TechnicalWork? Create(ServiceStationDatabase context, TechnicalWorkBindingModel model)
{ {
@ -73,7 +77,8 @@ namespace ServiceStationDatabaseImplement.Models
WorkType = WorkType, WorkType = WorkType,
DateStartWork = DateStartWork, DateStartWork = DateStartWork,
WorkPrice = WorkPrice, WorkPrice = WorkPrice,
ExecutorId = ExecutorId ExecutorId = ExecutorId,
TechnicalWorkCars = TechnicalWorkCars
}; };
public void UpdateCars(ServiceStationDatabase context, TechnicalWorkBindingModel model) public void UpdateCars(ServiceStationDatabase context, TechnicalWorkBindingModel model)

View File

@ -28,15 +28,14 @@ namespace ServiceStationDatabaseImplement.Models
[Required] [Required]
public int GuarantorId { get; set; } public int GuarantorId { get; set; }
[Required] public int? TechnicalWorkId { get; set; }
public int TechnicalWorkId { get; set; }
public virtual Guarantor Guarantor { get; set; } public virtual Guarantor Guarantor { get; set; }
public virtual TechnicalWork? TechnicalWork { get; set; }
//public virtual TechnicalWork TechnicalWork { get; set; }
private Dictionary<int, ISparePartModel>? _workSpareParts = null; private Dictionary<int, ISparePartModel>? _workSpareParts = null;
[NotMapped]
public Dictionary<int, ISparePartModel> WorkSpareParts public Dictionary<int, ISparePartModel> WorkSpareParts
{ {
get get
@ -52,9 +51,6 @@ namespace ServiceStationDatabaseImplement.Models
[ForeignKey("WorkId")] [ForeignKey("WorkId")]
public virtual List<SparePartWork> SpareParts { get; set; } = new(); public virtual List<SparePartWork> SpareParts { get; set; } = new();
[ForeignKey("WorkId")]
public virtual List<TechnicalWork> TechnicalWorks { get; set; } = new();
public static Work? Create(ServiceStationDatabase context, WorkBindingModel model) public static Work? Create(ServiceStationDatabase context, WorkBindingModel model)
{ {
if (model == null) return null; if (model == null) return null;
@ -65,7 +61,6 @@ namespace ServiceStationDatabaseImplement.Models
Status = model.Status, Status = model.Status,
WorkPrice = model.WorkPrice, WorkPrice = model.WorkPrice,
GuarantorId = model.GuarantorId, GuarantorId = model.GuarantorId,
TechnicalWorkId = model.TechnicalWorkId,
SpareParts = model.WorkSpareParts.Select(x => new SparePartWork SpareParts = model.WorkSpareParts.Select(x => new SparePartWork
{ {
SparePart = context.SpareParts.First(y => y.Id == x.Key) SparePart = context.SpareParts.First(y => y.Id == x.Key)
@ -75,11 +70,16 @@ namespace ServiceStationDatabaseImplement.Models
public void Update(WorkBindingModel model) public void Update(WorkBindingModel model)
{ {
if(model == null) return;
if (model.TechnicalWorkId.HasValue)
{
TechnicalWorkId = model.TechnicalWorkId;
return;
}
WorkName = model.WorkName; WorkName = model.WorkName;
Status = model.Status; Status = model.Status;
WorkPrice = model.WorkPrice; WorkPrice = model.WorkPrice;
GuarantorId = model.GuarantorId; GuarantorId = model.GuarantorId;
TechnicalWorkId = model.TechnicalWorkId;
} }
public WorkViewModel GetViewModel => new() public WorkViewModel GetViewModel => new()
{ {
@ -88,7 +88,8 @@ namespace ServiceStationDatabaseImplement.Models
Status = Status, Status = Status,
WorkPrice = WorkPrice, WorkPrice = WorkPrice,
GuarantorId = GuarantorId, GuarantorId = GuarantorId,
TechnicalWorkId = TechnicalWorkId TechnicalWorkId = TechnicalWorkId,
WorkSpareParts = WorkSpareParts,
}; };
public void UpdateSpareParts(ServiceStationDatabase context, WorkBindingModel model) public void UpdateSpareParts(ServiceStationDatabase context, WorkBindingModel model)