rough
This commit is contained in:
parent
5ccc478238
commit
ef1e3da92e
@ -5,6 +5,16 @@ VisualStudioVersion = 17.9.34728.123
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoRepairShop", "AutoRepairShop\AutoRepairShop.csproj", "{E8434326-6476-45B5-9EA4-8EC82479B8CA}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoRepairShopBusinessLogic", "AutoRepairShopBusinessLogic\AutoRepairShopBusinessLogic.csproj", "{20D4586B-D87D-4BD1-8840-C7EADFBADF85}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoRepairShopContracts", "AutoRepairShopContracts\AutoRepairShopContracts.csproj", "{315E839A-4DB8-4E0D-BFC1-19684FC53D07}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoRepairShopDataModels", "AutoRepairShopDataModels\AutoRepairShopDataModels.csproj", "{D279E3B7-D840-4B28-B9ED-DDD81804DF71}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoRepairShopDatabaseImplement", "AutoRepairShopDatabaseImplement\AutoRepairShopDatabaseImplement.csproj", "{208B8AB2-3C23-49E8-BB82-A8DFBD7849A6}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoRepairShopView", "AutoRepairShopView\AutoRepairShopView.csproj", "{11B9EC2E-9CA7-454E-8872-19AD291AC2A6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -15,6 +25,26 @@ Global
|
||||
{E8434326-6476-45B5-9EA4-8EC82479B8CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E8434326-6476-45B5-9EA4-8EC82479B8CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E8434326-6476-45B5-9EA4-8EC82479B8CA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{20D4586B-D87D-4BD1-8840-C7EADFBADF85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{20D4586B-D87D-4BD1-8840-C7EADFBADF85}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{20D4586B-D87D-4BD1-8840-C7EADFBADF85}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{20D4586B-D87D-4BD1-8840-C7EADFBADF85}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{315E839A-4DB8-4E0D-BFC1-19684FC53D07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{315E839A-4DB8-4E0D-BFC1-19684FC53D07}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{315E839A-4DB8-4E0D-BFC1-19684FC53D07}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{315E839A-4DB8-4E0D-BFC1-19684FC53D07}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D279E3B7-D840-4B28-B9ED-DDD81804DF71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D279E3B7-D840-4B28-B9ED-DDD81804DF71}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D279E3B7-D840-4B28-B9ED-DDD81804DF71}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D279E3B7-D840-4B28-B9ED-DDD81804DF71}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{208B8AB2-3C23-49E8-BB82-A8DFBD7849A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{208B8AB2-3C23-49E8-BB82-A8DFBD7849A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{208B8AB2-3C23-49E8-BB82-A8DFBD7849A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{208B8AB2-3C23-49E8-BB82-A8DFBD7849A6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{11B9EC2E-9CA7-454E-8872-19AD291AC2A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{11B9EC2E-9CA7-454E-8872-19AD291AC2A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{11B9EC2E-9CA7-454E-8872-19AD291AC2A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{11B9EC2E-9CA7-454E-8872-19AD291AC2A6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -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.Abstractions" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AutoRepairShopContracts\AutoRepairShopContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,113 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.BusinessLogicsContracts;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.StoragesContracts;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ClientLogic : IClientLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IClientStorage _clientStorage;
|
||||
|
||||
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage clientStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_clientStorage = clientStorage;
|
||||
}
|
||||
|
||||
public bool Create(ClientBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_clientStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert 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;
|
||||
}
|
||||
|
||||
public ClientViewModel? ReadElement(ClientSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Email: {Email} Id:{ Id}", model.JobTitle, 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 List<ClientViewModel>? ReadList(ClientSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Email: {Email}. Id:{ Id}", model?.JobTitle, 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 bool Update(ClientBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_clientStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update 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.ClientFIO))
|
||||
{
|
||||
throw new ArgumentNullException("Нет ФИО пользователя",
|
||||
nameof(model.ClientFIO));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.JobTitle))
|
||||
{
|
||||
throw new ArgumentNullException("Нет должности пользователя",
|
||||
nameof(model.JobTitle));
|
||||
}
|
||||
_logger.LogInformation("Component. ClientFIO:{ClientFIO}. Email:{ Email}. Id: { Id}", model.ClientFIO, model.JobTitle, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.BusinessLogicsContracts;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.StoragesContracts;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ManagerLogic : IManagerLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IManagerStorage _managerStorage;
|
||||
|
||||
public ManagerLogic(ILogger<ManagerLogic> logger, IManagerStorage managerStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_managerStorage = managerStorage;
|
||||
}
|
||||
|
||||
public bool Create(ManagerBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_managerStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ManagerBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_managerStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ManagerViewModel? ReadElement(ManagerSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Email: {Email} Id:{ Id}", model.Email, model.Id);
|
||||
var element = _managerStorage.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<ManagerViewModel>? ReadList(ManagerSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Email: {Email}. Id:{ Id}", model?.Email, model?.Id);
|
||||
var list = model == null ? _managerStorage.GetFullList() : _managerStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(ManagerBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_managerStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ManagerBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ManagerFIO))
|
||||
{
|
||||
throw new ArgumentNullException("Нет ФИО пользователя",
|
||||
nameof(model.ManagerFIO));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
throw new ArgumentNullException("Нет почтового адреса пользователя",
|
||||
nameof(model.Email));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Нет пароля пользователя",
|
||||
nameof(model.Password));
|
||||
}
|
||||
_logger.LogInformation("Component. ManagerFIO:{ManagerFIO}. Email:{ Email}. Id: { Id}", model.ManagerFIO, model.Email, model.Id);
|
||||
var element = _managerStorage.GetElement(new ManagerSearchModel { Email = model.Email });
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Пользователь с таким логином уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.BusinessLogicsContracts;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.StoragesContracts;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class PointLogic : IPointLogic
|
||||
{
|
||||
private readonly ILogger<PointLogic> _logger;
|
||||
private readonly IPointStorage _pointStorage;
|
||||
|
||||
public PointLogic(ILogger<PointLogic> logger, IPointStorage pointStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_pointStorage = pointStorage;
|
||||
}
|
||||
|
||||
public bool Create(PointBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_pointStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(PointBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_pointStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public PointViewModel? ReadElement(PointSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
|
||||
var element = _pointStorage.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<PointViewModel>? ReadList(PointSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _pointStorage.GetFullList() : _pointStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(PointBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_pointStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(PointBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.Amount <= 0)
|
||||
{
|
||||
throw new ArgumentException("Amount must be greater than 0", nameof(model.Amount));
|
||||
}
|
||||
_logger.LogInformation("Component. Amount:{Amount}. Id: { Id}", model.Amount, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.BusinessLogicsContracts;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.StoragesContracts;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class TaskLogic : ITaskLogic
|
||||
{
|
||||
private readonly ILogger<TaskLogic> _logger;
|
||||
private readonly ITaskStorage _taskStorage;
|
||||
|
||||
public TaskLogic(ILogger<TaskLogic> logger, ITaskStorage taskStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_taskStorage = taskStorage;
|
||||
}
|
||||
|
||||
public bool Create(TaskBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_taskStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(TaskBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_taskStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public TaskViewModel? ReadElement(TaskSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
|
||||
var element = _taskStorage.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<TaskViewModel>? ReadList(TaskSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _taskStorage.GetFullList() : _taskStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(TaskBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_taskStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(TaskBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Description))
|
||||
{
|
||||
throw new ArgumentNullException("Description is required",
|
||||
nameof(model.Description));
|
||||
}
|
||||
_logger.LogInformation("Component. Description:{Description}. Id: { Id}", model.Description, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.BusinessLogicsContracts;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.StoragesContracts;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class WorkLogic : IWorkLogic
|
||||
{
|
||||
private readonly ILogger<WorkLogic> _logger;
|
||||
private readonly IWorkStorage _workStorage;
|
||||
|
||||
public WorkLogic(ILogger<WorkLogic> logger, IWorkStorage workStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_workStorage = workStorage;
|
||||
}
|
||||
|
||||
public bool Create(WorkBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_workStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(WorkBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_workStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public WorkViewModel? ReadElement(WorkSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
|
||||
var element = _workStorage.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<WorkViewModel>? ReadList(WorkSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _workStorage.GetFullList() : _workStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(WorkBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_workStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(WorkBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Type))
|
||||
{
|
||||
throw new ArgumentNullException("Type is required",
|
||||
nameof(model.Type));
|
||||
}
|
||||
_logger.LogInformation("Component. Type:{Type}. Id: { Id}", model.Type, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AutoRepairShopDataModels\AutoRepairShopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,16 @@
|
||||
using AutoRepairShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.BindingModels
|
||||
{
|
||||
public class ClientBindingModel : IClientModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
public string JobTitle { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using AutoRepairShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.BindingModels
|
||||
{
|
||||
public class ManagerBindingModel : IManagerModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ManagerFIO { get; set; } = string.Empty;
|
||||
public string JobTitle { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string Login { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using AutoRepairShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.BindingModels
|
||||
{
|
||||
public class PointBindingModel : IPointModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int Amount { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using AutoRepairShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.BindingModels
|
||||
{
|
||||
public class TaskBindingModel : ITaskModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using AutoRepairShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.BindingModels
|
||||
{
|
||||
public class WorkBindingModel : IWorkModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int PointId { get; set; }
|
||||
public string Type { get; set; } = string.Empty;
|
||||
public List<PointBindingModel> Points { get; set; }
|
||||
public Dictionary<int, (ITaskModel, int)> WorkTasks { get; set; } = new();
|
||||
public Dictionary<int, (IClientModel, int)> WorkClients { get; set; } = new();
|
||||
public IManagerModel Manager { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IClientLogic
|
||||
{
|
||||
List<ClientViewModel>? ReadList(ClientSearchModel? model);
|
||||
ClientViewModel? ReadElement(ClientSearchModel model);
|
||||
bool Create(ClientBindingModel model);
|
||||
bool Update(ClientBindingModel model);
|
||||
bool Delete(ClientBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IManagerLogic
|
||||
{
|
||||
List<ManagerViewModel>? ReadList(ManagerSearchModel? model);
|
||||
ManagerViewModel? ReadElement(ManagerSearchModel model);
|
||||
bool Create(ManagerBindingModel model);
|
||||
bool Update(ManagerBindingModel model);
|
||||
bool Delete(ManagerBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IPointLogic
|
||||
{
|
||||
List<PointViewModel>? ReadList(PointSearchModel? model);
|
||||
PointViewModel? ReadElement(PointSearchModel model);
|
||||
bool Create(PointBindingModel model);
|
||||
bool Update(PointBindingModel model);
|
||||
bool Delete(PointBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface ITaskLogic
|
||||
{
|
||||
List<TaskViewModel>? ReadList(TaskSearchModel? model);
|
||||
TaskViewModel? ReadElement(TaskSearchModel model);
|
||||
bool Create(TaskBindingModel model);
|
||||
bool Update(TaskBindingModel model);
|
||||
bool Delete(TaskBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IWorkLogic
|
||||
{
|
||||
List<WorkViewModel>? ReadList(WorkSearchModel? model);
|
||||
WorkViewModel? ReadElement(WorkSearchModel model);
|
||||
bool Create(WorkBindingModel model);
|
||||
bool Update(WorkBindingModel model);
|
||||
bool Delete(WorkBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.SearchModels
|
||||
{
|
||||
public class ClientSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ClientFIO { get; set; }
|
||||
public string? JobTitle { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.SearchModels
|
||||
{
|
||||
public class ManagerSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ManagerFIO { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? Login { get; set; }
|
||||
public string? Password { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.SearchModels
|
||||
{
|
||||
public class PointSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? Amount { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.SearchModels
|
||||
{
|
||||
public class TaskSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.SearchModels
|
||||
{
|
||||
public class WorkSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string Type { get; set; }
|
||||
public string Client { get; set; }
|
||||
public string Manager { get; set; }
|
||||
public string Point { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.StoragesContracts
|
||||
{
|
||||
public interface IClientStorage
|
||||
{
|
||||
List<ClientViewModel> GetFullList();
|
||||
List<ClientViewModel> GetFilteredList(ClientSearchModel model);
|
||||
ClientViewModel? GetElement(ClientSearchModel model);
|
||||
ClientViewModel? Insert(ClientBindingModel model);
|
||||
ClientViewModel? Update(ClientBindingModel model);
|
||||
ClientViewModel? Delete(ClientBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.StoragesContracts
|
||||
{
|
||||
public interface IManagerStorage
|
||||
{
|
||||
List<ManagerViewModel> GetFullList();
|
||||
List<ManagerViewModel> GetFilteredList(ManagerSearchModel model);
|
||||
ManagerViewModel? GetElement(ManagerSearchModel model);
|
||||
ManagerViewModel? Insert(ManagerBindingModel model);
|
||||
ManagerViewModel? Update(ManagerBindingModel model);
|
||||
ManagerViewModel? Delete(ManagerBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.StoragesContracts
|
||||
{
|
||||
public interface IPointStorage
|
||||
{
|
||||
List<PointViewModel> GetFullList();
|
||||
List<PointViewModel> GetFilteredList(PointSearchModel model);
|
||||
PointViewModel? GetElement(PointSearchModel model);
|
||||
PointViewModel? Insert(PointBindingModel model);
|
||||
PointViewModel? Update(PointBindingModel model);
|
||||
PointViewModel? Delete(PointBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.StoragesContracts
|
||||
{
|
||||
public interface ITaskStorage
|
||||
{
|
||||
List<TaskViewModel> GetFullList();
|
||||
List<TaskViewModel> GetFilteredList(TaskSearchModel model);
|
||||
TaskViewModel? GetElement(TaskSearchModel model);
|
||||
TaskViewModel? Insert(TaskBindingModel model);
|
||||
TaskViewModel? Update(TaskBindingModel model);
|
||||
TaskViewModel? Delete(TaskBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.StoragesContracts
|
||||
{
|
||||
public interface IWorkStorage
|
||||
{
|
||||
List<WorkViewModel> GetFullList();
|
||||
List<WorkViewModel> GetFilteredList(WorkSearchModel model);
|
||||
WorkViewModel? GetElement(WorkSearchModel model);
|
||||
WorkViewModel? Insert(WorkBindingModel model);
|
||||
WorkViewModel? Update(WorkBindingModel model);
|
||||
WorkViewModel? Delete(WorkBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using AutoRepairShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.ViewModels
|
||||
{
|
||||
public class ClientViewModel : IClientModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("ФИО клиента")]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
[DisplayName("Должность")]
|
||||
public string JobTitle { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using AutoRepairShopContracts.BusinessLogicsContracts;
|
||||
using AutoRepairShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.ViewModels
|
||||
{
|
||||
public class ManagerViewModel : IManagerModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("ФИО клиента")]
|
||||
public string ManagerFIO { get; set; } = string.Empty;
|
||||
[DisplayName("Логин (эл. почта)")]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string Login { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using AutoRepairShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.ViewModels
|
||||
{
|
||||
public class PointViewModel : IPointModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Количество")]
|
||||
public int Amount { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using AutoRepairShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.ViewModels
|
||||
{
|
||||
public class TaskViewModel : ITaskModel
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Описание")]
|
||||
public string Description { get; set; }
|
||||
|
||||
[DisplayName("Дата выполнения")]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
[DisplayName("Клиент")]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
using AutoRepairShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopContracts.ViewModels
|
||||
{
|
||||
public class WorkViewModel : IWorkModel
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Тип работы")]
|
||||
public string Type { get; set; }
|
||||
[DisplayName("Баллы")]
|
||||
public Point Point { get; set; }
|
||||
[DisplayName("Руководитель")]
|
||||
public IManagerModel Manager { get; set; }
|
||||
[DisplayName("Задания")]
|
||||
public Dictionary<int, (ITaskModel, int)> WorkTasks { get; set; } = new();
|
||||
[DisplayName("Клиенты")]
|
||||
public Dictionary<int, (IClientModel, int)> WorkClients { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
12
AutoRepairShop/AutoRepairShopDataModels/IId.cs
Normal file
12
AutoRepairShop/AutoRepairShopDataModels/IId.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopDataModels
|
||||
{
|
||||
public interface IId
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopDataModels.Models
|
||||
{
|
||||
public interface IClientModel : IId
|
||||
{
|
||||
string ClientFIO { get; }
|
||||
string JobTitle { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopDataModels.Models
|
||||
{
|
||||
public interface IManagerModel : IId
|
||||
{
|
||||
string ManagerFIO { get; }
|
||||
string Email { get; }
|
||||
string Login { get; }
|
||||
string Password { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopDataModels.Models
|
||||
{
|
||||
public interface IPointModel : IId
|
||||
{
|
||||
int Amount { get; }
|
||||
}
|
||||
}
|
14
AutoRepairShop/AutoRepairShopDataModels/Models/ITaskModel.cs
Normal file
14
AutoRepairShop/AutoRepairShopDataModels/Models/ITaskModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopDataModels.Models
|
||||
{
|
||||
public interface ITaskModel : IId
|
||||
{
|
||||
string Description { get; }
|
||||
DateTime? DateImplement { get; }
|
||||
}
|
||||
}
|
17
AutoRepairShop/AutoRepairShopDataModels/Models/IWorkModel.cs
Normal file
17
AutoRepairShop/AutoRepairShopDataModels/Models/IWorkModel.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopDataModels.Models
|
||||
{
|
||||
public interface IWorkModel : IId
|
||||
{
|
||||
int Id { get; }
|
||||
string Type { get; }
|
||||
Dictionary<int, (ITaskModel, int)> WorkTasks { get; }
|
||||
Dictionary<int, (IClientModel, int)> WorkClients { get; }
|
||||
IManagerModel Manager { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
using AutoRepairShopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Npgsql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Task = AutoRepairShopDatabaseImplement.Models.Task;
|
||||
|
||||
namespace AutoRepairShopDatabaseImplement
|
||||
{
|
||||
public class AutoRepairShopDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseNpgsql("Host=10.211.55.3;Database=AutoRepairShopDatabaseFull;Username=postgres;Password=postgres");
|
||||
}
|
||||
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
public virtual DbSet<Point> Points { set; get; }
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
public virtual DbSet<Manager> Managers { set; get; }
|
||||
public virtual DbSet<Task> Tasks { set; get; }
|
||||
public virtual DbSet<Work> Works { set; get; }
|
||||
public virtual DbSet<WorkClients> WorkClients { set; get; }
|
||||
public virtual DbSet<WorkTasks> WorkTasks { set; get; }
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.12" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql" Version="8.0.2" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.1" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AutoRepairShopContracts\AutoRepairShopContracts.csproj" />
|
||||
<ProjectReference Include="..\AutoRepairShopDataModels\AutoRepairShopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,89 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.StoragesContracts;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using AutoRepairShopDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopDatabaseImplement.Implements
|
||||
{
|
||||
public class ClientStorage : IClientStorage
|
||||
{
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
using var context = new AutoRepairShopDatabase();
|
||||
var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Clients.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.JobTitle) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new AutoRepairShopDatabase();
|
||||
return context.Clients.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.JobTitle) && x.JobTitle == model.JobTitle) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.JobTitle))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new AutoRepairShopDatabase();
|
||||
return context.Clients
|
||||
.Where(x => x.JobTitle.Equals(model.JobTitle))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFullList()
|
||||
{
|
||||
using var context = new AutoRepairShopDatabase();
|
||||
return context.Clients
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ClientViewModel? Insert(ClientBindingModel model)
|
||||
{
|
||||
var newClient = Client.Create(model);
|
||||
if (newClient == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new AutoRepairShopDatabase();
|
||||
context.Clients.Add(newClient);
|
||||
context.SaveChanges();
|
||||
return newClient.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Update(ClientBindingModel model)
|
||||
{
|
||||
using var context = new AutoRepairShopDatabase();
|
||||
var client = context.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (client == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
client.Update(model);
|
||||
context.SaveChanges();
|
||||
return client.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.StoragesContracts;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using AutoRepairShopDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopDatabaseImplement.Implements
|
||||
{
|
||||
public class ManagerStorage : IManagerStorage
|
||||
{
|
||||
public ManagerViewModel? Delete(ManagerBindingModel model)
|
||||
{
|
||||
using var context = new AutoRepairShopDatabase();
|
||||
var manager = context.Managers.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (manager != null)
|
||||
{
|
||||
context.Managers.Remove(manager);
|
||||
context.SaveChanges();
|
||||
return manager.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public ManagerViewModel? GetElement(ManagerSearchModel model)
|
||||
{
|
||||
using var context = new AutoRepairShopDatabase();
|
||||
var manager = context.Managers.FirstOrDefault(x =>
|
||||
x.Email.Equals(model.Email, StringComparison.OrdinalIgnoreCase));
|
||||
return manager != null ? manager.GetViewModel : null;
|
||||
}
|
||||
public List<ManagerViewModel> GetFilteredList(ManagerSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
return new List<ManagerViewModel>();
|
||||
}
|
||||
using var context = new AutoRepairShopDatabase();
|
||||
var managers = context.Managers
|
||||
.Where(x => x.Email.Equals(model.Email, StringComparison.OrdinalIgnoreCase))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
return managers;
|
||||
}
|
||||
public List<ManagerViewModel> GetFullList()
|
||||
{
|
||||
using var context = new AutoRepairShopDatabase();
|
||||
var managers = context.Managers
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
return managers;
|
||||
}
|
||||
public ManagerViewModel? Insert(ManagerBindingModel model)
|
||||
{
|
||||
var newManager = Manager.Create(model);
|
||||
if (newManager == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new AutoRepairShopDatabase();
|
||||
context.Managers.Add(newManager);
|
||||
context.SaveChanges();
|
||||
return newManager.GetViewModel;
|
||||
}
|
||||
public ManagerViewModel? Update(ManagerBindingModel model)
|
||||
{
|
||||
using var context = new AutoRepairShopDatabase();
|
||||
var manager = context.Managers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (manager == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
manager.Update(model);
|
||||
context.SaveChanges();
|
||||
return manager.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.StoragesContracts;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using AutoRepairShopDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopDatabaseImplement.Implements
|
||||
{
|
||||
public class PointStorage : IPointStorage
|
||||
{
|
||||
public PointViewModel? Delete(PointBindingModel model)
|
||||
{
|
||||
using var context = new AutoRepairShopDatabase();
|
||||
var point = context.Points.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (point != null)
|
||||
{
|
||||
context.Points.Remove(point);
|
||||
context.SaveChanges();
|
||||
return point.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PointViewModel? GetElement(PointSearchModel model)
|
||||
{
|
||||
using var context = new AutoRepairShopDatabase();
|
||||
var point = context.Points.FirstOrDefault(x => x.Id == model.Id);
|
||||
return point != null ? point.GetViewModel : null;
|
||||
}
|
||||
|
||||
public List<PointViewModel> GetFilteredList(PointSearchModel model)
|
||||
{
|
||||
using var context = new AutoRepairShopDatabase();
|
||||
var points = context.Points
|
||||
.Where(x => x.Amount == model.Amount)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
return points;
|
||||
}
|
||||
public List<PointViewModel> GetFullList()
|
||||
{
|
||||
using var context = new AutoRepairShopDatabase();
|
||||
var points = context.Points
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
return points;
|
||||
}
|
||||
public PointViewModel? Insert(PointBindingModel model)
|
||||
{
|
||||
var newPoint = Point.Create(model);
|
||||
if (newPoint == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using (var context = new AutoRepairShopDatabase())
|
||||
{
|
||||
context.Points.Add(newPoint);
|
||||
context.SaveChanges();
|
||||
}
|
||||
return newPoint.GetViewModel;
|
||||
}
|
||||
public PointViewModel? Update(PointBindingModel model)
|
||||
{
|
||||
using var context = new AutoRepairShopDatabase();
|
||||
var point = context.Points.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (point == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
point.Update(model);
|
||||
context.SaveChanges();
|
||||
return point.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.StoragesContracts;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using AutoRepairShopDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace AutoRepairShopDatabaseImplement.Implements
|
||||
{
|
||||
public class TaskStorage : ITaskStorage
|
||||
{
|
||||
public TaskViewModel? Insert(TaskBindingModel model)
|
||||
{
|
||||
var context = new AutoRepairShopDatabase();
|
||||
var newTask = Models.Task.Create(context, model);
|
||||
if (newTask == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
context.Tasks.Add(newTask);
|
||||
context.SaveChanges();
|
||||
return newTask.GetViewModel;
|
||||
}
|
||||
|
||||
public TaskViewModel? GetElement(TaskSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Description) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using (var context = new AutoRepairShopDatabase())
|
||||
{
|
||||
return context.Tasks.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.Description) && x.Description == model.Description) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
public List<TaskViewModel> GetFilteredList(TaskSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Description))
|
||||
{
|
||||
return new List<TaskViewModel>();
|
||||
}
|
||||
using (var context = new AutoRepairShopDatabase())
|
||||
{
|
||||
return context.Tasks
|
||||
.Where(x => x.Description.Equals(model.Description, StringComparison.OrdinalIgnoreCase))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public List<TaskViewModel> GetFullList()
|
||||
{
|
||||
using (var context = new AutoRepairShopDatabase())
|
||||
{
|
||||
return context.Tasks
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public TaskViewModel? Update(TaskBindingModel model)
|
||||
{
|
||||
using (var context = new AutoRepairShopDatabase())
|
||||
{
|
||||
var task = context.Tasks.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (task == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
task.Update(model);
|
||||
context.SaveChanges();
|
||||
return task.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
public TaskViewModel? Delete(TaskBindingModel model)
|
||||
{
|
||||
using (var context = new AutoRepairShopDatabase())
|
||||
{
|
||||
var task = context.Tasks.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (task != null)
|
||||
{
|
||||
context.Tasks.Remove(task);
|
||||
context.SaveChanges();
|
||||
}
|
||||
return task?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.SearchModels;
|
||||
using AutoRepairShopContracts.StoragesContracts;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using AutoRepairShopDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoRepairShopDatabaseImplement.Implements
|
||||
{
|
||||
public class WorkStorage : IWorkStorage
|
||||
{
|
||||
public WorkViewModel? Insert(WorkBindingModel model)
|
||||
{
|
||||
using (var context = new AutoRepairShopDatabase())
|
||||
{
|
||||
var newWork = Work.Create(context, model);
|
||||
if (newWork == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
context.Works.Add(newWork);
|
||||
context.SaveChanges();
|
||||
|
||||
return newWork.GetViewModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public WorkViewModel? GetElement(WorkSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Type) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using (var context = new AutoRepairShopDatabase())
|
||||
{
|
||||
return context.Works.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.Type) && x.Type == model.Type) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
public List<WorkViewModel> GetFilteredList(WorkSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Type))
|
||||
{
|
||||
return new List<WorkViewModel>();
|
||||
}
|
||||
using (var context = new AutoRepairShopDatabase())
|
||||
{
|
||||
return context.Works
|
||||
.Where(x => x.Type.Equals(model.Type, StringComparison.OrdinalIgnoreCase))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public List<WorkViewModel> GetFullList()
|
||||
{
|
||||
using (var context = new AutoRepairShopDatabase())
|
||||
{
|
||||
return context.Works
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public WorkViewModel? Update(WorkBindingModel model)
|
||||
{
|
||||
using (var context = new AutoRepairShopDatabase())
|
||||
{
|
||||
var work = context.Works.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (work == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
work.Update(model);
|
||||
context.SaveChanges();
|
||||
return work.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
public WorkViewModel? Delete(WorkBindingModel model)
|
||||
{
|
||||
using (var context = new AutoRepairShopDatabase())
|
||||
{
|
||||
var work = context.Works.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (work != null)
|
||||
{
|
||||
context.Works.Remove(work);
|
||||
context.SaveChanges();
|
||||
}
|
||||
return work?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using AutoRepairShopDataModels.Models;
|
||||
|
||||
namespace AutoRepairShopDatabaseImplement.Models
|
||||
{
|
||||
public class Client : IClientModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string ClientFIO { get; set; }
|
||||
[Required]
|
||||
public string JobTitle { get; set; }
|
||||
// для реализации связи многие ко многим с изделиями
|
||||
[ForeignKey("ClientId")]
|
||||
public virtual List<WorkClients> WorkClients { get; set; } = new();
|
||||
public static Client? Create(ClientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Client()
|
||||
{
|
||||
Id = model.Id,
|
||||
ClientFIO = model.ClientFIO,
|
||||
JobTitle = model.JobTitle
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ClientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ClientFIO = model.ClientFIO;
|
||||
JobTitle = model.JobTitle;
|
||||
}
|
||||
|
||||
public static List<Client> GetFilteredList(List<Client> clients, Func<Client, bool> filter)
|
||||
{
|
||||
return clients.Where(filter).ToList();
|
||||
}
|
||||
public ClientViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ClientFIO = ClientFIO,
|
||||
JobTitle = JobTitle
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using AutoRepairShopDataModels.Models;
|
||||
|
||||
namespace AutoRepairShopDatabaseImplement.Models
|
||||
{
|
||||
public class Manager : IManagerModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string ManagerFIO { get; set; }
|
||||
[Required]
|
||||
public string Email { get; set; }
|
||||
[Required]
|
||||
public string Login { get; set; }
|
||||
[Required]
|
||||
public string Password { get; set; }
|
||||
public static Manager? Create(ManagerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Manager()
|
||||
{
|
||||
Id = model.Id,
|
||||
ManagerFIO = model.ManagerFIO,
|
||||
Email = model.Email,
|
||||
Login = model.Login,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
public void Update(ManagerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ManagerFIO = model.ManagerFIO;
|
||||
Email = model.Email;
|
||||
Login = model.Login;
|
||||
Password = model.Password;
|
||||
}
|
||||
public ManagerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ManagerFIO = ManagerFIO,
|
||||
Email = Email,
|
||||
Login = Login,
|
||||
Password = Password
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using AutoRepairShopDataModels.Models;
|
||||
|
||||
namespace AutoRepairShopDatabaseImplement.Models
|
||||
{
|
||||
public class Point : IPointModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int Amount { get; set; }
|
||||
public static Point? Create(PointBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Point()
|
||||
{
|
||||
Id = model.Id,
|
||||
Amount = model.Amount
|
||||
};
|
||||
}
|
||||
public void Update(PointBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Amount = model.Amount;
|
||||
}
|
||||
public PointViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Amount = Amount
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using AutoRepairShopDataModels.Models;
|
||||
|
||||
namespace AutoRepairShopDatabaseImplement.Models
|
||||
{
|
||||
public class Task : ITaskModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Description { get; set; }
|
||||
public DateTime? DateImplement { get; set; }
|
||||
|
||||
[ForeignKey("TaskId")]
|
||||
public virtual List<WorkTasks> WorkTasks { get; set; } = new();
|
||||
public static Task Create(AutoRepairShopDatabase context, TaskBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var newTask = new Task
|
||||
{
|
||||
Id = model.Id,
|
||||
Description = model.Description,
|
||||
DateImplement = model.DateImplement
|
||||
};
|
||||
|
||||
return newTask;
|
||||
}
|
||||
public void Update(TaskBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Description = model.Description;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
|
||||
public static List<Task> GetFilteredList(List<Task> tasks, Func<Task, bool> filter)
|
||||
{
|
||||
return tasks.Where(filter).ToList();
|
||||
}
|
||||
|
||||
public TaskViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Description = Description,
|
||||
DateImplement = DateImplement
|
||||
};
|
||||
}
|
||||
}
|
112
AutoRepairShop/AutoRepairShopDatabaseImplement/Models/Work.cs
Normal file
112
AutoRepairShop/AutoRepairShopDatabaseImplement/Models/Work.cs
Normal file
@ -0,0 +1,112 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AutoRepairShopContracts.BindingModels;
|
||||
using AutoRepairShopContracts.ViewModels;
|
||||
using AutoRepairShopDataModels.Models;
|
||||
|
||||
namespace AutoRepairShopDatabaseImplement.Models
|
||||
{
|
||||
public class Work : IWorkModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Type { get; set; }
|
||||
|
||||
private Dictionary<int, (ITaskModel, int)> _workTasks = new();
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (ITaskModel, int)> WorkTasks
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_workTasks == null)
|
||||
{
|
||||
_workTasks = Tasks.ToDictionary(recPC => recPC.TaskId, recPC => (recPC.Task as ITaskModel, recPC.Count));
|
||||
}
|
||||
|
||||
return _workTasks;
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<int, (IClientModel, int)> _workClients = new();
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IClientModel, int)> WorkClients
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_workClients == null)
|
||||
{
|
||||
_workClients = Clients.ToDictionary(recPC => recPC.ClientId, recPC => (recPC.Client as IClientModel, recPC.Count));
|
||||
}
|
||||
|
||||
return _workClients;
|
||||
}
|
||||
}
|
||||
|
||||
[ForeignKey("WorkId")]
|
||||
public virtual List<WorkTasks> Tasks { get; set; } = new();
|
||||
|
||||
[ForeignKey("WorkId")]
|
||||
public virtual List<WorkClients> Clients { get; set; } = new();
|
||||
|
||||
[ForeignKey("PointId")]
|
||||
public int PointId { get; set; }
|
||||
|
||||
public virtual Point Point { get; set; }
|
||||
|
||||
public IManagerModel Manager { get; set; }
|
||||
|
||||
public static Work Create(AutoRepairShopDatabase context, WorkBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Work()
|
||||
{
|
||||
Id = model.Id,
|
||||
Type = model.Type,
|
||||
Tasks = model.WorkTasks.Select(x => new WorkTasks
|
||||
{
|
||||
Task = context.Tasks.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList(),
|
||||
Clients = model.WorkClients.Select(x => new WorkClients
|
||||
{
|
||||
Client = context.Clients.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList(),
|
||||
PointId = model.PointId,
|
||||
Point = context.Points.First(p => p.Id == model.PointId),
|
||||
Manager = model.Manager
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(WorkBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Type = model.Type;
|
||||
PointId = model.PointId;
|
||||
Manager = model.Manager;
|
||||
}
|
||||
|
||||
public WorkViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Type = Type,
|
||||
Manager = Manager
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AutoRepairShopDataModels.Models;
|
||||
|
||||
namespace AutoRepairShopDatabaseImplement.Models
|
||||
{
|
||||
public class WorkClients
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int ClientId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Client Client { get; set; } = new();
|
||||
public virtual Work Work { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AutoRepairShopDataModels.Models;
|
||||
|
||||
namespace AutoRepairShopDatabaseImplement.Models
|
||||
{
|
||||
public class WorkTasks
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int TaskId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Task Task { get; set; } = new();
|
||||
public virtual Work Work { get; set; } = new();
|
||||
}
|
||||
}
|
26
AutoRepairShop/AutoRepairShopView/AutoRepairShopView.csproj
Normal file
26
AutoRepairShop/AutoRepairShopView/AutoRepairShopView.csproj
Normal file
@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.12">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.12" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.9" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AutoRepairShopBusinessLogic\AutoRepairShopBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\AutoRepairShopContracts\AutoRepairShopContracts.csproj" />
|
||||
<ProjectReference Include="..\AutoRepairShopDatabaseImplement\AutoRepairShopDatabaseImplement.csproj" />
|
||||
<ProjectReference Include="..\AutoRepairShopDataModels\AutoRepairShopDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
53
AutoRepairShop/AutoRepairShopView/Program.cs
Normal file
53
AutoRepairShop/AutoRepairShopView/Program.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using AutoRepairShopBusinessLogic;
|
||||
using AutoRepairShopBusinessLogic.BusinessLogic;
|
||||
using AutoRepairShopContracts.BusinessLogicsContracts;
|
||||
using AutoRepairShopContracts.StoragesContracts;
|
||||
using AutoRepairShopDatabaseImplement.Implements;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
using System;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace FurnitureAssembly
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
// ApplicationConfiguration.Initialize();
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
// Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||
|
||||
}
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddLogging(option =>
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddNLog("nlog.config");
|
||||
});
|
||||
services.AddTransient<IClientStorage, ClientStorage>();
|
||||
services.AddTransient<IManagerStorage, ManagerStorage>();
|
||||
services.AddTransient<IWorkStorage, WorkStorage>();
|
||||
services.AddTransient<ITaskStorage, TaskStorage>();
|
||||
services.AddTransient<IPointStorage, PointStorage>();
|
||||
|
||||
services.AddTransient<IClientLogic, ClientLogic>();
|
||||
services.AddTransient<IManagerLogic, ManagerLogic>();
|
||||
services.AddTransient<IWorkLogic, WorkLogic>();
|
||||
services.AddTransient<ITaskLogic, TaskLogic>();
|
||||
services.AddTransient<IPointLogic, PointLogic>();
|
||||
}
|
||||
}
|
||||
}
|
18
AutoRepairShop/AutoRepairShopView/nlog.config
Normal file
18
AutoRepairShop/AutoRepairShopView/nlog.config
Normal file
@ -0,0 +1,18 @@
|
||||
<?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="logs/log-${shortdate}.log" />
|
||||
</targets>
|
||||
<target name="console" xsi:type="Console" layout="Access Log|${level:uppercase=true}|${logger}|${message}">
|
||||
<highlight-row condition="true" foregroundColor="red"/>
|
||||
</target>
|
||||
|
||||
<rules>
|
||||
<logger name="*" minlevel="Info" writeTo="tofile,console" />
|
||||
</rules>
|
||||
</nlog>
|
||||
</configuration>
|
Loading…
Reference in New Issue
Block a user