DavidMakarov 2024-04-27 15:54:56 +04:00
commit 2ca62beea6
28 changed files with 1388 additions and 16 deletions

View File

@ -3,9 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.4.33110.190 VisualStudioVersion = 17.4.33110.190
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FactoryDataModels", "FactoryDataModels\FactoryDataModels.csproj", "{CBE4843B-F023-4C97-925E-BEFE960D0EEA}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FactoryDataModels", "FactoryDataModels\FactoryDataModels.csproj", "{CBE4843B-F023-4C97-925E-BEFE960D0EEA}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FactoryContracts", "FactoryContracts\FactoryContracts.csproj", "{87BA79A9-CF35-4CB4-98BD-86C01918C81C}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FactoryContracts", "FactoryContracts\FactoryContracts.csproj", "{87BA79A9-CF35-4CB4-98BD-86C01918C81C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FactoryBuisinessLogic", "FactoryBuisinessLogic\FactoryBuisinessLogic.csproj", "{EA960B3E-6BFB-4B16-9B0A-E1D603967FEC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FactoryDatabaseImplement", "FactoryDatabaseImplement\FactoryDatabaseImplement.csproj", "{AC09F9B2-8744-4C66-AD47-33A35613BC40}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -21,6 +25,14 @@ Global
{87BA79A9-CF35-4CB4-98BD-86C01918C81C}.Debug|Any CPU.Build.0 = Debug|Any CPU {87BA79A9-CF35-4CB4-98BD-86C01918C81C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87BA79A9-CF35-4CB4-98BD-86C01918C81C}.Release|Any CPU.ActiveCfg = Release|Any CPU {87BA79A9-CF35-4CB4-98BD-86C01918C81C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{87BA79A9-CF35-4CB4-98BD-86C01918C81C}.Release|Any CPU.Build.0 = Release|Any CPU {87BA79A9-CF35-4CB4-98BD-86C01918C81C}.Release|Any CPU.Build.0 = Release|Any CPU
{EA960B3E-6BFB-4B16-9B0A-E1D603967FEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA960B3E-6BFB-4B16-9B0A-E1D603967FEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA960B3E-6BFB-4B16-9B0A-E1D603967FEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA960B3E-6BFB-4B16-9B0A-E1D603967FEC}.Release|Any CPU.Build.0 = Release|Any CPU
{AC09F9B2-8744-4C66-AD47-33A35613BC40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AC09F9B2-8744-4C66-AD47-33A35613BC40}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC09F9B2-8744-4C66-AD47-33A35613BC40}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC09F9B2-8744-4C66-AD47-33A35613BC40}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -0,0 +1,119 @@
using FactoryContracts.BindingModels;
using FactoryContracts.BusinessLogicsContracts;
using FactoryContracts.SearchModels;
using FactoryContracts.StoragesContracts;
using FactoryContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace FactoryBusinessLogic.BusinessLogics
{
public class ClientLogic : IClientLogic
{
private readonly ILogger _logger;
private readonly IClientStorage _clientStorage;
public ClientLogic(ILogger<ExecutionPhaseLogic> logger, IClientStorage clientStorage)
{
_logger = logger;
_clientStorage = clientStorage;
}
public List<ClientViewModel>? ReadList(ClientSearchModel? model)
{
_logger.LogInformation("ReadList. Login:{Login}. Id:{Id}", model?.Login, model?.Id);
var list = model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public ClientViewModel? ReadElement(ClientSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Login:{Login}. Id:{Id}", model.Login, model.Id);
var element = _clientStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(ClientBindingModel model)
{
CheckModel(model);
if (_clientStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ClientBindingModel model)
{
CheckModel(model);
if (_clientStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ClientBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_clientStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ClientBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Login))
{
throw new ArgumentNullException("Нет логина клиента", nameof(model.Login));
}
if (string.IsNullOrEmpty(model.Email))
{
throw new ArgumentNullException("Нет почты клиента", nameof(model.Email));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет пароля клиента", nameof(model.Email));
}
_logger.LogInformation("Client. Login:{Login}. Email:{Email}. Password:{Password}.", model.Login, model.Email, model.Password);
var element = _clientStorage.GetElement(new ClientSearchModel
{
Login = model.Login
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Клиент с таким логином уже есть");
}
}
}
}

View File

@ -0,0 +1,120 @@
using FactoryContracts.BindingModels;
using FactoryContracts.BusinessLogicsContracts;
using FactoryContracts.SearchModels;
using FactoryContracts.StoragesContracts;
using FactoryContracts.ViewModels;
using FactoryDataModels.Enums;
using Microsoft.Extensions.Logging;
namespace FactoryBusinessLogic.BusinessLogics
{
public class ExecutionPhaseLogic : IExecutionPhaseLogic
{
private readonly ILogger _logger;
private readonly IExecutionPhaseStorage _executionPhaseStorage;
public ExecutionPhaseLogic(ILogger<ExecutionPhaseLogic> logger, IExecutionPhaseStorage executionPhaseStorage)
{
_logger = logger;
_executionPhaseStorage = executionPhaseStorage;
}
public List<ExecutionPhaseViewModel>? ReadList(ExecutionPhaseSearchModel? model)
{
_logger.LogInformation("ReadList. ExecutionPhaseName:{ExecutionPhaseName}. Id:{Id}", model?.ExecutionPhaseName, model?.Id);
var list = model == null ? _executionPhaseStorage.GetFullList() : _executionPhaseStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public ExecutionPhaseViewModel? ReadElement(ExecutionPhaseSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ExecutionPhaseName:{ExecutionPhaseName}. Id:{Id}", model.ExecutionPhaseName, model.Id);
var element = _executionPhaseStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(ExecutionPhaseBindingModel model)
{
CheckModel(model);
if (_executionPhaseStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ExecutionPhaseBindingModel model)
{
CheckModel(model);
if (_executionPhaseStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ExecutionPhaseBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_executionPhaseStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ExecutionPhaseBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ExecutionPhaseName))
{
throw new ArgumentNullException("Нет названия этапа выполнения", nameof(model.ExecutionPhaseName));
}
if (string.IsNullOrEmpty(model.ImplementerFIO))
{
throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO));
}
if (model.Status == ExecutionPhaseStatus.Неизвестен)
{
throw new ArgumentNullException("Состояние этапа не может быть неизвестно", nameof(model.Status));
}
_logger.LogInformation("ExecutionPhase. ExecutionPhaseName:{ExecutionPhaseName}. ImplementerFIO:{ImplementerFIO}. Status:{Status}. Id:{Id}", model.ExecutionPhaseName, model.ImplementerFIO, model.Status, model.Id);
var element = _executionPhaseStorage.GetElement(new ExecutionPhaseSearchModel
{
ExecutionPhaseName = model.ExecutionPhaseName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Этап с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,115 @@
using FactoryContracts.BindingModels;
using FactoryContracts.BusinessLogicsContracts;
using FactoryContracts.SearchModels;
using FactoryContracts.ViewModels;
using FactoryContracts.StoragesContracts;
using Microsoft.Extensions.Logging;
namespace FactoryBusinessLogic.BusinessLogics
{
public class PlanProductionLogic : IPlanProductionLogic
{
private readonly ILogger _logger;
private readonly IPlanProductionStorage _planProductionStorage;
public PlanProductionLogic(ILogger<PlanProductionLogic> logger, IPlanProductionStorage planProductionStorage)
{
_logger = logger;
_planProductionStorage = planProductionStorage;
}
public List<PlanProductionViewModel>? ReadList(PlanProductionSearchModel? model)
{
_logger.LogInformation("ReadList. ProductionName:{ProductionName}. Id:{Id}", model?.ProductionName, model?.Id);
var list = model == null ? _planProductionStorage.GetFullList() : _planProductionStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public PlanProductionViewModel? ReadElement(PlanProductionSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ProductionName:{ProductionName}. Id:{Id}", model.ProductionName, model.Id);
var element = _planProductionStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(PlanProductionBindingModel model)
{
CheckModel(model);
if (_planProductionStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(PlanProductionBindingModel model)
{
CheckModel(model);
if (_planProductionStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(PlanProductionBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_planProductionStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(PlanProductionBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ProductionName))
{
throw new ArgumentNullException("Нет названия плана производства", nameof(model.ProductionName));
}
if (model.Count <= 0)
{
throw new ArgumentNullException("Количество должно быть больше 0", nameof(model.Count));
}
_logger.LogInformation("PlanProduction. ProductionName:{ProductionName}. Count:{Count}. Id:{Id}", model.ProductionName, model.Count, model.Id);
var element = _planProductionStorage.GetElement(new PlanProductionSearchModel
{
ProductionName = model.ProductionName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("План производства с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,116 @@
using FactoryContracts.BindingModels;
using FactoryContracts.BusinessLogicsContracts;
using FactoryContracts.SearchModels;
using FactoryContracts.StoragesContracts;
using FactoryContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace FactoryBusinessLogic.BusinessLogics
{
public class WorkpieceLogic : IWorkpieceLogic
{
private readonly ILogger _logger;
private readonly IWorkpieceStorage _workpieceStorage;
public WorkpieceLogic(ILogger<ExecutionPhaseLogic> logger, IWorkpieceStorage workpieceStorage)
{
_logger = logger;
_workpieceStorage = workpieceStorage;
}
public bool Create(WorkpieceBindingModel model)
{
CheckModel(model);
if (_workpieceStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(WorkpieceBindingModel model)
{
CheckModel(model);
if (_workpieceStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(WorkpieceBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_workpieceStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public WorkpieceViewModel? ReadElement(WorkpieceSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. WorkpieceName:{WorkpieceName}. Id:{Id}", model.WorkpieceName, model.Id);
var element = _workpieceStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<WorkpieceViewModel>? ReadList(WorkpieceSearchModel? model)
{
_logger.LogInformation("ReadList. WorkpieceName:{WorkpieceName}. Id:{Id}", model?.WorkpieceName, model?.Id);
var list = model == null ? _workpieceStorage.GetFullList() : _workpieceStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
private void CheckModel(WorkpieceBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.WorkpieceName))
{
throw new ArgumentNullException("Нет названия заготовки", nameof(model.WorkpieceName));
}
if (string.IsNullOrEmpty(model.Material))
{
throw new ArgumentNullException("Нет материала для заготовки", nameof(model.Material));
}
if (model.Cost <= 0)
{
throw new ArgumentNullException("Цена заготовки должна быть больше 0", nameof(model.Cost));
}
_logger.LogInformation("Component. WorkpieceName:{WorkpieceName}. Material:{Material}. Cost:{Cost}. Id:{Id}", model.WorkpieceName, model.Material, model.Cost, model.Id);
var element = _workpieceStorage.GetElement(new WorkpieceSearchModel
{
WorkpieceName = model.WorkpieceName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Заготовка с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FactoryContracts\FactoryContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -7,6 +7,7 @@ namespace FactoryContracts.BindingModels
{ {
public int Id { get; set; } public int Id { get; set; }
public string ExecutionPhaseName { get; set; } = string.Empty;
public string ImplementerFIO { get; set; } = string.Empty; public string ImplementerFIO { get; set; } = string.Empty;
public ExecutionPhaseStatus Status { get; set; } = ExecutionPhaseStatus.Неизвестен; public ExecutionPhaseStatus Status { get; set; } = ExecutionPhaseStatus.Неизвестен;
public int ClientId { get; set; } public int ClientId { get; set; }

View File

@ -12,6 +12,6 @@ namespace FactoryContracts.BindingModels
public double Cost { get; set; } public double Cost { get; set; }
//public Dictionary<int, (IComponentModel, int)> WorkComponents { get; set; } = new(); public Dictionary<int, (IComponentModel, int)> WorkpiecesProducts { get; set; } = new();
} }
} }

View File

@ -9,12 +9,10 @@ namespace FactoryContracts.BusinessLogicsContracts
List<PlanProductionViewModel>? ReadList(PlanProductionSearchModel? model); List<PlanProductionViewModel>? ReadList(PlanProductionSearchModel? model);
PlanProductionViewModel? ReadElement(PlanProductionSearchModel model); PlanProductionViewModel? ReadElement(PlanProductionSearchModel model);
bool CreatePlanProduction(PlanProductionBindingModel model); bool Create(PlanProductionBindingModel model);
bool TakePlanProductionInWork(PlanProductionBindingModel model); bool Update(PlanProductionBindingModel model);
bool FinishPlanProduction(PlanProductionBindingModel model); bool Delete(PlanProductionBindingModel model);
bool DeliveryPlanProduction(PlanProductionBindingModel model);
} }
} }

View File

@ -4,8 +4,6 @@
{ {
public int? Id { get; set; } public int? Id { get; set; }
public string? ImplementerFIO { get; set; } public string? ExecutionPhaseName { get; set; }
public string? Password { get; set; }
} }
} }

View File

@ -5,5 +5,6 @@ namespace FactoryContracts.SearchModels
public class PlanProductionSearchModel public class PlanProductionSearchModel
{ {
public int? Id { get; set; } public int? Id { get; set; }
public string? ProductionName { get; set; }
} }
} }

View File

@ -4,6 +4,6 @@
{ {
public int? Id { get; set; } public int? Id { get; set; }
public string? WorkName { get; set; } public string? WorkpieceName { get; set; }
} }
} }

View File

@ -12,10 +12,10 @@ namespace FactoryContracts.StoragesContracts
PlanProductionViewModel? GetElement(PlanProductionSearchModel model); PlanProductionViewModel? GetElement(PlanProductionSearchModel model);
PlanProductionViewModel? Insert(ExecutionPhaseBindingModel model); PlanProductionViewModel? Insert(PlanProductionBindingModel model);
PlanProductionViewModel? Update(ExecutionPhaseBindingModel model); PlanProductionViewModel? Update(PlanProductionBindingModel model);
PlanProductionViewModel? Delete(ExecutionPhaseBindingModel model); PlanProductionViewModel? Delete(PlanProductionBindingModel model);
} }
} }

View File

@ -10,9 +10,12 @@ namespace FactoryContracts.ViewModels
[DisplayName("ФИО исполнителя")] [DisplayName("ФИО исполнителя")]
public string ImplementerFIO { get; set; } = string.Empty; public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Описание этапа")]
public string ExecutionPhaseName { get; set; } = string.Empty;
[DisplayName("Статус этапа")] [DisplayName("Статус")]
public ExecutionPhaseStatus Status { get; set; } = ExecutionPhaseStatus.Неизвестен; public ExecutionPhaseStatus Status { get; set; } = ExecutionPhaseStatus.Неизвестен;
[DisplayName("Номер клиента")] [DisplayName("Номер клиента")]
public int ClientId { get; set; } public int ClientId { get; set; }

View File

@ -4,6 +4,8 @@ namespace FactoryDataModels.Models
{ {
public interface IExecutionPhaseModel : IId public interface IExecutionPhaseModel : IId
{ {
string ExecutionPhaseName { get; }
string ImplementerFIO { get; } string ImplementerFIO { get; }
ExecutionPhaseStatus Status { get; } ExecutionPhaseStatus Status { get; }
int ClientId { get; } int ClientId { get; }

View File

@ -0,0 +1,29 @@
using FactoryDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace FactoryDatabaseImplement
{
public class FactoryDatabase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseNpgsql(@"Host=localhost;Database=Factory;Username=postgres; Password = postgres");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Client> Clients { set; get; }
public virtual DbSet<ExecutionPhase> ExecutionPhases { set; get; }
public virtual DbSet<MachinePlanProduction> MachinePlanProductions { set; get; }
public virtual DbSet<PlanProduction> PlanProductions { set; get; }
public virtual DbSet<PlanProductionWorkpiece> PlanProductionWorkpieces { set; get; }
public virtual DbSet<Workpiece> Workpieces { set; get; }
public virtual DbSet<WorkpieceProduct> WorkpieceProducts { set; get; }
}
}

View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.29" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.22" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FactoryContracts\FactoryContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,84 @@
using FactoryContracts.BindingModels;
using FactoryContracts.SearchModels;
using FactoryContracts.StoragesContracts;
using FactoryContracts.ViewModels;
using FactoryDatabaseImplement.Models;
namespace FactoryDatabaseImplement.Implements
{
public class ClientStorage : IClientStorage
{
public List<ClientViewModel> GetFullList()
{
using var context = new FactoryDatabase();
return context.Clients
.Select(x => x.GetViewModel)
.ToList();
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
if (string.IsNullOrEmpty(model.Login))
{
return new();
}
using var context = new FactoryDatabase();
return context.Clients
.Where(x => x.Login.Contains(model.Login))
.Select(x => x.GetViewModel)
.ToList();
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
if (string.IsNullOrEmpty(model.Login) && !model.Id.HasValue)
{
return null;
}
using var context = new FactoryDatabase();
return context.Clients
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Login) && x.Login == model.Login) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public ClientViewModel? Insert(ClientBindingModel model)
{
var newClient = Client.Create(model);
if (newClient == null)
{
return null;
}
using var context = new FactoryDatabase();
context.Clients.Add(newClient);
context.SaveChanges();
return newClient.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel model)
{
using var context = new FactoryDatabase();
var component = context.Clients.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
public ClientViewModel? Delete(ClientBindingModel model)
{
using var context = new FactoryDatabase();
var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Clients.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,84 @@
using FactoryContracts.BindingModels;
using FactoryContracts.SearchModels;
using FactoryContracts.StoragesContracts;
using FactoryContracts.ViewModels;
using FactoryDatabaseImplement.Models;
namespace FactoryDatabaseImplement.Implements
{
public class ExecutionPhaseStorage : IExecutionPhaseStorage
{
public List<ExecutionPhaseViewModel> GetFullList()
{
using var context = new FactoryDatabase();
return context.ExecutionPhases
.Select(x => x.GetViewModel)
.ToList();
}
public List<ExecutionPhaseViewModel> GetFilteredList(ExecutionPhaseSearchModel model)
{
if (string.IsNullOrEmpty(model.ExecutionPhaseName))
{
return new();
}
using var context = new FactoryDatabase();
return context.ExecutionPhases
.Where(x => x.ExecutionPhaseName.Contains(model.ExecutionPhaseName))
.Select(x => x.GetViewModel)
.ToList();
}
public ExecutionPhaseViewModel? GetElement(ExecutionPhaseSearchModel model)
{
if (string.IsNullOrEmpty(model.ExecutionPhaseName) && !model.Id.HasValue)
{
return null;
}
using var context = new FactoryDatabase();
return context.ExecutionPhases
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ExecutionPhaseName) && x.ExecutionPhaseName == model.ExecutionPhaseName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public ExecutionPhaseViewModel? Insert(ExecutionPhaseBindingModel model)
{
var newExecutionPhase = ExecutionPhase.Create(model);
if (newExecutionPhase == null)
{
return null;
}
using var context = new FactoryDatabase();
context.ExecutionPhases.Add(newExecutionPhase);
context.SaveChanges();
return newExecutionPhase.GetViewModel;
}
public ExecutionPhaseViewModel? Update(ExecutionPhaseBindingModel model)
{
using var context = new FactoryDatabase();
var component = context.ExecutionPhases.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
public ExecutionPhaseViewModel? Delete(ExecutionPhaseBindingModel model)
{
using var context = new FactoryDatabase();
var element = context.ExecutionPhases.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.ExecutionPhases.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,111 @@
using Microsoft.EntityFrameworkCore;
using FactoryContracts.BindingModels;
using FactoryContracts.SearchModels;
using FactoryContracts.StoragesContracts;
using FactoryContracts.ViewModels;
using FactoryDatabaseImplement.Models;
namespace FactoryDatabaseImplement.Implements
{
public class PlanProductionStorage : IPlanProductionStorage
{
public PlanProductionViewModel? Delete(PlanProductionBindingModel model)
{
using var context = new FactoryDatabase();
var element = context.PlanProductions
.Include(x => x.ExecutionPhase)
.Include(x => x.Workpieces)
.ThenInclude( x => x.Workpiece)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.PlanProductions.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public PlanProductionViewModel? GetElement(PlanProductionSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new FactoryDatabase();
if (model.Id.HasValue)
return context.PlanProductions
.Include(x => x.ExecutionPhase)
.Include(x =>x.Workpieces)
.ThenInclude(x => x.Workpiece)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel;
return null;
}
public List<PlanProductionViewModel> GetFilteredList(PlanProductionSearchModel model)
{
using var context = new FactoryDatabase();
if (model.Id.HasValue)
{
return context.PlanProductions
.Where(x => x.Id == model.Id)
.Include(x => x.ExecutionPhase)
.Include(x => x.Workpieces)
.ThenInclude(x => x.Workpiece)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public List<PlanProductionViewModel> GetFullList()
{
using var context = new FactoryDatabase();
return context.PlanProductions
.Include(x => x.ExecutionPhase)
.Include(x => x.Workpieces)
.ThenInclude(x => x.Workpiece)
.ToList()
.Select(x =>x.GetViewModel)
.ToList();
}
public PlanProductionViewModel? Insert(PlanProductionBindingModel model)
{
using var context = new FactoryDatabase();
var newPlanProduction = PlanProduction.Create(context, model);
if (newPlanProduction == null)
{
return null;
}
context.PlanProductions.Add(newPlanProduction);
context.SaveChanges();
return newPlanProduction.GetViewModel;
}
public PlanProductionViewModel? Update(PlanProductionBindingModel model)
{
using var context = new FactoryDatabase();
var order = context.PlanProductions
.Include(x => x.ExecutionPhase)
.Include(x => x.Workpieces)
.ThenInclude(x => x.Workpiece)
.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
}
order.Update(model);
context.SaveChanges();
return order.GetViewModel;
}
}
}

View File

@ -0,0 +1,106 @@
using FactoryContracts.BindingModels;
using FactoryContracts.SearchModels;
using FactoryContracts.StoragesContracts;
using FactoryContracts.ViewModels;
using FactoryDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace FactoryDatabaseImplement.Implements
{
public class WorkpieceStorage : IWorkpieceStorage
{
public List<WorkpieceViewModel> GetFullList()
{
using var context = new FactoryDatabase();
return context.Workpieces
.Include(x => x.Products)
.ThenInclude(x => x.Product)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<WorkpieceViewModel> GetFilteredList(WorkpieceSearchModel model)
{
if (string.IsNullOrEmpty(model.WorkpieceName))
{
return new();
}
using var context = new FactoryDatabase();
return context.Workpieces
.Include(x => x.Products)
.ThenInclude(x => x.Product)
.Where(x => x.WorkpieceName.Contains(model.WorkpieceName))
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public WorkpieceViewModel? GetElement(WorkpieceSearchModel model)
{
if (string.IsNullOrEmpty(model.WorkpieceName) && !model.Id.HasValue)
{
return null;
}
using var context = new FactoryDatabase();
return context.Workpieces
.Include(x => x.Products)
.ThenInclude(x => x.Product)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.WorkpieceName) && x.WorkpieceName == model.WorkpieceName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public WorkpieceViewModel? Insert(WorkpieceBindingModel model)
{
using var context = new FactoryDatabase();
var newWorkpiece = Workpiece.Create(context, model);
if (newWorkpiece == null)
{
return null;
}
context.Workpieces.Add(newWorkpiece);
context.SaveChanges();
return newWorkpiece.GetViewModel;
}
public WorkpieceViewModel? Update(WorkpieceBindingModel model)
{
using var context = new FactoryDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var work = context.Workpieces.FirstOrDefault(rec => rec.Id == model.Id);
if (work == null)
{
return null;
}
work.Update(model);
context.SaveChanges();
work.UpdateProducts(context, model);
transaction.Commit();
return work.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public WorkpieceViewModel? Delete(WorkpieceBindingModel model)
{
using var context = new FactoryDatabase();
var element = context.Workpieces
.Include(x => x.Products)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Workpieces.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,75 @@
using FactoryContracts.BindingModels;
using FactoryContracts.ViewModels;
using FactoryDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace FactoryDatabaseImplement.Models
{
public class Client : IClientModel
{
public int Id { get; private set; }
[Required]
public string Login { get; private set; } = string.Empty;
[Required]
public string Email { get; private set; } = string.Empty;
[Required]
public string Password { get; private set; } = string.Empty;
[ForeignKey("ClientId")]
public virtual List<ExecutionPhase> ExecutionPhases{ get; set; } = new();
[ForeignKey("ClientId")]
public virtual List<PlanProduction> PlanProductions { get; set; } = new();
[ForeignKey("ClientId")]
public virtual List<Workpiece> Workpieces { get; set; } = new();
public static Client? Create(ClientBindingModel model)
{
if (model == null)
{
return null;
}
return new Client()
{
Id = model.Id,
Login = model.Login,
Email= model.Email,
Password = model.Password,
};
}
public static Client Create(ClientViewModel model)
{
return new Client
{
Id = model.Id,
Login = model.Login,
Email = model.Email,
Password = model.Password,
};
}
public void Update(ClientBindingModel model)
{
if (model == null)
{
return;
}
Login = model.Login;
Email = model.Email;
Password = model.Password;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
Login = Login,
Email = Email,
Password = Password,
};
}
}

View File

@ -0,0 +1,75 @@
using FactoryContracts.BindingModels;
using FactoryContracts.ViewModels;
using FactoryDataModels.Enums;
using FactoryDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace FactoryDatabaseImplement.Models
{
public class ExecutionPhase : IExecutionPhaseModel
{
public int Id { get; private set; }
[Required]
public int ClientId { get; private set; }
public virtual Client Client { get; private set; } = new();
[Required]
public string ExecutionPhaseName { get; private set; } = string.Empty;
[Required]
public string ImplementerFIO { get; private set; } = string.Empty;
[Required]
public ExecutionPhaseStatus Status { get; private set; } = ExecutionPhaseStatus.Неизвестен;
[ForeignKey("ExecutionPhaseId")]
public virtual List<PlanProduction> PlanProductions { get; set; } = new();
public static ExecutionPhase? Create(ExecutionPhaseBindingModel model)
{
if (model == null)
{
return null;
}
return new ExecutionPhase()
{
Id = model.Id,
ExecutionPhaseName = model.ExecutionPhaseName,
ImplementerFIO = model.ImplementerFIO,
ClientId = model.ClientId,
Status = model.Status,
};
}
public static ExecutionPhase Create(ExecutionPhaseViewModel model)
{
return new ExecutionPhase
{
Id = model.Id,
ExecutionPhaseName = model.ExecutionPhaseName,
ImplementerFIO = model.ImplementerFIO,
ClientId = model.ClientId,
Status = model.Status,
};
}
public void Update(ExecutionPhaseBindingModel model)
{
if (model == null)
{
return;
}
ExecutionPhaseName = model.ExecutionPhaseName;
ImplementerFIO = model.ImplementerFIO;
Status = model.Status;
}
public ExecutionPhaseViewModel GetViewModel => new()
{
Id = Id,
ExecutionPhaseName = ExecutionPhaseName,
ImplementerFIO = ImplementerFIO,
ClientId = ClientId,
Status = Status,
};
}
}

View File

@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;
namespace FactoryDatabaseImplement.Models
{
public class MachinePlanProduction
{
public int Id { get; set; }
//[Required]
//public int MachineId { get; set; }
[Required]
public int PlanProductionId { get; set; }
public virtual PlanProduction PlanProduction { get; set; } = new();
//public virtual Machine Machine{ get; set; } = new();
}
}

View File

@ -0,0 +1,120 @@
using FactoryContracts.BindingModels;
using FactoryContracts.ViewModels;
using FactoryDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace FactoryDatabaseImplement.Models
{
public class PlanProduction : IPlanProductionModel
{
public int Id { get; private set; }
[Required]
public int ExecutionPhaseId { get; private set; }
public virtual ExecutionPhase ExecutionPhase { get; private set; } = new();
[Required]
public int ClientId { get; private set; }
public virtual Client Client { get; private set; } = new();
[Required]
public string ProductionName { get; private set; } = string.Empty;
[Required]
public int Count { get; private set; }
[Required]
public DateTime Term { get; private set; }
private Dictionary<int, (IWorkpieceModel, int)>? _planProductionWorkpieces = null;
[NotMapped]
public Dictionary<int, (IWorkpieceModel, int)> PlanProductionWorkpieces
{
get
{
if (_planProductionWorkpieces == null)
{
_planProductionWorkpieces = Workpieces
.ToDictionary(recPC => recPC.WorkpieceId, recPC => (recPC.Workpiece as IWorkpieceModel, recPC.Count));
}
return _planProductionWorkpieces;
}
}
[ForeignKey("PlanProductionId")]
public virtual List<PlanProductionWorkpiece> Workpieces{ get; set; } = new();
[ForeignKey("PlanProductionId")]
public virtual List<MachinePlanProduction> Machines { get; set; } = new();
public static PlanProduction Create(FactoryDatabase context, PlanProductionBindingModel model)
{
if (model == null)
{
return null;
}
return new PlanProduction()
{
Id = model.Id,
ClientId = model.ClientId,
Count = model.Count,
ExecutionPhaseId = model.ExecutionPhaseId,
ProductionName = model.ProductionName,
Term = model.Term,
Workpieces = model.PlanProductionWorkpieces.Select(x => new PlanProductionWorkpiece
{
Workpiece = context.Workpieces.First(y => y.Id == x.Key),
Count = x.Value.Item2
}).ToList()
};
}
public void Update(PlanProductionBindingModel model)
{
if (model == null)
{
return;
}
Count = model.Count;
ExecutionPhaseId = model.ExecutionPhaseId;
ProductionName = model.ProductionName;
Term = model.Term;
}
public PlanProductionViewModel GetViewModel => new()
{
Id = Id,
ClientId = ClientId,
ExecutionPhaseId = ExecutionPhaseId,
ProductionName = ProductionName,
Term = Term,
Count = Count,
PlanProductionWorkpieces = PlanProductionWorkpieces
};
public void UpdateWorkpieces(FactoryDatabase context, PlanProductionBindingModel model)
{
var planProductionWorkpieces = context.PlanProductionWorkpieces.Where(rec => rec.PlanProductionId == model.Id).ToList();
if (planProductionWorkpieces != null && planProductionWorkpieces.Count > 0)
{
context.PlanProductionWorkpieces.RemoveRange(planProductionWorkpieces.Where(rec => !model.PlanProductionWorkpieces.ContainsKey(rec.WorkpieceId)));
context.SaveChanges();
foreach (var updateWorkpiece in planProductionWorkpieces)
{
updateWorkpiece.Count = model.PlanProductionWorkpieces[updateWorkpiece.WorkpieceId].Item2;
model.PlanProductionWorkpieces.Remove(updateWorkpiece.WorkpieceId);
}
context.SaveChanges();
}
var plan = context.PlanProductions.First(x => x.Id == Id);
foreach (var pc in model.PlanProductionWorkpieces)
{
context.PlanProductionWorkpieces.Add(new PlanProductionWorkpiece
{
PlanProduction = plan,
Workpiece = context.Workpieces.First(x => x.Id == pc.Key),
Count = pc.Value.Item2
});
context.SaveChanges();
}
_planProductionWorkpieces = null;
}
}
}

View File

@ -0,0 +1,22 @@
using System.ComponentModel.DataAnnotations;
namespace FactoryDatabaseImplement.Models
{
public class PlanProductionWorkpiece
{
public int Id { get; set; }
[Required]
public int PlanProductionId { get; set; }
[Required]
public int WorkpieceId { get; set; }
[Required]
public int Count { get; set; }
public virtual PlanProduction PlanProduction { get; set; } = new();
public virtual Workpiece Workpiece { get; set; } = new();
}
}

View File

@ -0,0 +1,107 @@
using FactoryContracts.BindingModels;
using FactoryContracts.ViewModels;
using FactoryDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace FactoryDatabaseImplement.Models
{
public class Workpiece : IWorkpieceModel
{
public int Id { get; set; }
[Required]
public string WorkpieceName { get; set; } = string.Empty;
[Required]
public int ClientId { get; set; }
public virtual Client Client { get; set; } = new Client();
[Required]
public string Material { get; set; } = string.Empty;
[Required]
public double Cost { get; set; }
private Dictionary<int, (IProductModel, int)>? _workpieceProducts = null;
[NotMapped]
public Dictionary<int, (IWorkpieceModel, int)> WorkpieceProducts
{
get
{
if (_workpieceProducts == null)
{
_workpieceProducts = Products
.ToDictionary(recPC => recPC.ProductId, recPC => (recPC.Product as IProductModel, recPC.Count));
}
return _workpieceProducts;
}
}
[ForeignKey("WorkpieceId")]
public virtual List<WorkpieceProduct> Products { get; set; } = new();
[ForeignKey("WorkpieceId")]
public virtual List<PlanProductionWorkpiece> PlanProductions { get; set; } = new();
public static Workpiece Create(FactoryDatabase context, WorkpieceBindingModel model)
{
return new Workpiece()
{
Id = model.Id,
WorkpieceName = model.WorkpieceName,
Cost = model.Cost,
Material = model.Material,
ClientId = model.ClientId,
Products = model.WorkpiecesProducts.Select(x => new WorkpieceProduct
{
Product = context.Products.First(y => y.Id == x.Key),
Count = x.Value.Item2
}).ToList()
};
}
public void Update(WorkpieceBindingModel model)
{
WorkpieceName = model.WorkpieceName;
Cost = model.Cost;
Material = model.Material;
}
public WorkpieceViewModel GetViewModel => new()
{
Id = Id,
WorkpieceName = WorkpieceName,
Cost = Cost,
Material = Material,
ClientId = ClientId,
WorkpiecesProducts = WorkpieceProducts
};
public void UpdateProducts(FactoryDatabase context, WorkpieceBindingModel model)
{
var workpieceProducts = context.WorkpieceProducts.Where(rec => rec.WorkpieceId == model.Id).ToList();
if (workpieceProducts != null && workpieceProducts.Count > 0)
{
context.WorkpieceProducts.RemoveRange(workpieceProducts.Where(rec => !model.WorkpiecesProducts.ContainsKey(rec.ProductId)));
context.SaveChanges();
foreach (var updateProduct in workpieceProducts)
{
updateProduct.Count = model.WorkComponents[updateProduct.ProductId].Item2;
model.WorkpiecesProducts.Remove(updateProduct.ProductId);
}
context.SaveChanges();
}
var workpiece = context.Workpieces.First(x => x.Id == Id);
foreach (var pc in model.WorkpiecesProducts)
{
context.WorkpieceProducts.Add(new WorkpieceProduct
{
Workpiece = workpiece,
Product = context.Products.First(x => x.Id == pc.Key),
Count = pc.Value.Item2
});
context.SaveChanges();
}
_workpieceProducts = null;
}
}
}

View File

@ -0,0 +1,21 @@
using System.ComponentModel.DataAnnotations;
namespace FactoryDatabaseImplement.Models
{
public class WorkpieceProduct
{
public int Id { get; set; }
[Required]
public int WorkpieceId { get; set; }
[Required]
public int ProductId { get; set; }
[Required]
public int Count { get; set; }
public virtual Product Product { get; set; } = new();
public virtual Workpiece Workpiece { get; set; } = new();
}
}