Compare commits

..

No commits in common. "LabWork08" and "main" have entirely different histories.

152 changed files with 51 additions and 10189 deletions

View File

@ -3,17 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.3.32825.248 VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConstructionCompanyView", "ConstructionCompanyView\ConstructionCompanyView.csproj", "{E6C11D11-F20B-4A39-8FDA-82C75463ACBE}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConstructionCompanyView", "ConstructionCompanyView\ConstructionCompanyView.csproj", "{E6C11D11-F20B-4A39-8FDA-82C75463ACBE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConstructionCompanyDataModels", "ConstructionCompanyDataModels\ConstructionCompanyDataModels.csproj", "{78CB5CC6-B587-41DD-B595-13138E6351C8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConstructionCompanyContracts", "ConstructionCompanyContracts\ConstructionCompanyContracts.csproj", "{CFB66158-7025-4605-9739-C4A2F07D2EB6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConstructionCompanyBusinessLogic", "ConstructionCompanyBusiness\ConstructionCompanyBusinessLogic.csproj", "{FB447245-07E1-4E0D-A4FC-701E295B7575}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConstructionCompanyPsqlImplement", "ConstructionCompanyPsqlImplement\ConstructionCompanyPsqlImplement.csproj", "{A92A2186-2021-4B42-B632-447A45EC3A58}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConstructionCompanyMongoDBImplement", "ConstructionCompanyMongoDBImplement\ConstructionCompanyMongoDBImplement.csproj", "{52991C32-415C-46C5-8995-007D01C70968}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -25,26 +15,6 @@ Global
{E6C11D11-F20B-4A39-8FDA-82C75463ACBE}.Debug|Any CPU.Build.0 = Debug|Any CPU {E6C11D11-F20B-4A39-8FDA-82C75463ACBE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6C11D11-F20B-4A39-8FDA-82C75463ACBE}.Release|Any CPU.ActiveCfg = Release|Any CPU {E6C11D11-F20B-4A39-8FDA-82C75463ACBE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6C11D11-F20B-4A39-8FDA-82C75463ACBE}.Release|Any CPU.Build.0 = Release|Any CPU {E6C11D11-F20B-4A39-8FDA-82C75463ACBE}.Release|Any CPU.Build.0 = Release|Any CPU
{78CB5CC6-B587-41DD-B595-13138E6351C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{78CB5CC6-B587-41DD-B595-13138E6351C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{78CB5CC6-B587-41DD-B595-13138E6351C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{78CB5CC6-B587-41DD-B595-13138E6351C8}.Release|Any CPU.Build.0 = Release|Any CPU
{CFB66158-7025-4605-9739-C4A2F07D2EB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CFB66158-7025-4605-9739-C4A2F07D2EB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CFB66158-7025-4605-9739-C4A2F07D2EB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CFB66158-7025-4605-9739-C4A2F07D2EB6}.Release|Any CPU.Build.0 = Release|Any CPU
{FB447245-07E1-4E0D-A4FC-701E295B7575}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB447245-07E1-4E0D-A4FC-701E295B7575}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB447245-07E1-4E0D-A4FC-701E295B7575}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB447245-07E1-4E0D-A4FC-701E295B7575}.Release|Any CPU.Build.0 = Release|Any CPU
{A92A2186-2021-4B42-B632-447A45EC3A58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A92A2186-2021-4B42-B632-447A45EC3A58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A92A2186-2021-4B42-B632-447A45EC3A58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A92A2186-2021-4B42-B632-447A45EC3A58}.Release|Any CPU.Build.0 = Release|Any CPU
{52991C32-415C-46C5-8995-007D01C70968}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{52991C32-415C-46C5-8995-007D01C70968}.Debug|Any CPU.Build.0 = Debug|Any CPU
{52991C32-415C-46C5-8995-007D01C70968}.Release|Any CPU.ActiveCfg = Release|Any CPU
{52991C32-415C-46C5-8995-007D01C70968}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -1,106 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class EmployeeLogic : IEmployeeLogic
{
private readonly ILogger _logger;
private readonly IEmployeeStorage _employeeStorage;
public EmployeeLogic(ILogger<EmployeeLogic> logger, IEmployeeStorage employeeStorage)
{
_logger = logger;
_employeeStorage = employeeStorage;
}
public List<EmployeeViewModel>? ReadList(EmployeeSearchModel? model)
{
_logger.LogInformation("ReadList. EmployeeName:{EmployeeName}. Id:{Id}", model?.EmployeeName, model?.Id);
var list = model == null ? _employeeStorage.GetFullList() : _employeeStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public EmployeeViewModel? ReadElement(EmployeeSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. EmployeeName:{EmployeeName}. Id:{Id}", model.EmployeeName, model.Id);
var element = _employeeStorage.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(EmployeeBindingModel model)
{
CheckModel(model);
if (_employeeStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(EmployeeBindingModel model)
{
CheckModel(model);
if (_employeeStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(EmployeeBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_employeeStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(EmployeeBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.EmployeeName))
{
throw new ArgumentNullException("Нет названия материала", nameof(model.EmployeeName));
}
_logger.LogInformation("Employee. EmployeeName:{EmployeeName}. PositionID:{PositionID}. Id:{Id}", model.EmployeeName, model.PositionID, model.Id);
}
}
}

View File

@ -1,92 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class EmployeeOrderLogic : IEmployeeOrderLogic
{
private readonly ILogger _logger;
private readonly IEmployeeOrderStorage _employeeOrderStorage;
public EmployeeOrderLogic(ILogger<EmployeeOrderLogic> logger, IEmployeeOrderStorage employeeOrderStorage)
{
_logger = logger;
_employeeOrderStorage = employeeOrderStorage;
}
public List<EmployeeOrderViewModel>? ReadList(EmployeeOrderSearchModel? model)
{
_logger.LogInformation("ReadList. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId);
var list = model == null ? _employeeOrderStorage.GetFullList() : _employeeOrderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public EmployeeOrderViewModel? ReadElement(EmployeeOrderSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadList. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId);
var element = _employeeOrderStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId);
return element;
}
public bool Create(EmployeeOrderBindingModel model)
{
CheckModel(model);
if (_employeeOrderStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(EmployeeOrderBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId);
if (_employeeOrderStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(EmployeeOrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
_logger.LogInformation("EmployeeOrder. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId);
}
}
}

View File

@ -1,122 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class MaterialLogic : IMaterialLogic
{
private readonly ILogger _logger;
private readonly IMaterialStorage _materialStorage;
public MaterialLogic(ILogger<MaterialLogic> logger, IMaterialStorage materialStorage)
{
_logger = logger;
_materialStorage = materialStorage;
}
public List<MaterialViewModel>? ReadList(MaterialSearchModel? model)
{
_logger.LogInformation("ReadList. MaterialName:{MaterialName}. Id:{Id}", model?.MaterialName, model?.Id);
var list = model == null ? _materialStorage.GetFullList() : _materialStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public MaterialViewModel? ReadElement(MaterialSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. MaterialName:{MaterialName}. Id:{Id}", model.MaterialName, model.Id);
var element = _materialStorage.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(MaterialBindingModel model)
{
CheckModel(model);
if (_materialStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(MaterialBindingModel model)
{
CheckModel(model);
if (_materialStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(MaterialBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_materialStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(MaterialBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.MaterialName))
{
throw new ArgumentNullException("Нет названия материала", nameof(model.MaterialName));
}
if (model.Quantity < 0)
{
throw new ArgumentNullException("Количество материалов должна быть не меньше 0!", nameof(model.Quantity));
}
_logger.LogInformation("Material. IngredietnName:{MaterialName}. Cost:{Quantity}. Id:{Id}", model.MaterialName, model.Quantity, model.Id);
}
public List<EmployeeViewModel>? ReadEmployeesUsingMaterial(MaterialBindingModel model)
{
CheckModel(model, false);
var list = _materialStorage.GetEmployeesUsingMaterial(model);
if (list == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
return list;
}
}
}

View File

@ -1,96 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class MaterialOrderLogic : IMaterialOrderLogic
{
private readonly ILogger _logger;
private readonly IMaterialOrderStorage _employeeOrderStorage;
public MaterialOrderLogic(ILogger<MaterialOrderLogic> logger, IMaterialOrderStorage employeeOrderStorage)
{
_logger = logger;
_employeeOrderStorage = employeeOrderStorage;
}
public List<MaterialOrderViewModel>? ReadList(MaterialOrderSearchModel? model)
{
_logger.LogInformation("ReadList. MaterialId:{MaterialId}. OrderId:{OrderId}", model?.MaterialId, model?.OrderId);
var list = model == null ? _employeeOrderStorage.GetFullList() : _employeeOrderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public MaterialOrderViewModel? ReadElement(MaterialOrderSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadList. MaterialId:{MaterialId}. OrderId:{OrderId}", model?.MaterialId, model?.OrderId);
var element = _employeeOrderStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. MaterialId:{MaterialId}. OrderId:{OrderId}", model?.MaterialId, model?.OrderId);
return element;
}
public bool Create(MaterialOrderBindingModel model)
{
CheckModel(model);
if (_employeeOrderStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(MaterialOrderBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. MaterialId:{MaterialId}. OrderId:{OrderId}", model?.MaterialId, model?.OrderId);
if (_employeeOrderStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(MaterialOrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.Quantity <= 0)
{
throw new InvalidOperationException("Количество должна быть больше 0!");
}
_logger.LogInformation("MaterialOrder. MaterialId:{MaterialId}. OrderId:{OrderId}", model?.MaterialId, model?.OrderId);
}
}
}

View File

@ -1,145 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Enums;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class OrderLogic : IOrderLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
{
_logger = logger;
_orderStorage = orderStorage;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list.OrderBy(x => x.Id).ToList();
}
public OrderViewModel? ReadElement(OrderSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
var element = _orderStorage.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 CreateOrder(OrderBindingModel model)
{
CheckModel(model);
if (model.Status != OrderStatus.Неизвестен) return false;
model.Status = OrderStatus.Принят;
if (_orderStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool FinishOrder(OrderBindingModel model)
{
CheckModel(model, false);
var element = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id
});
if (element == null)
{
_logger.LogWarning("Read operation failed");
return false;
}
if (element.Status != OrderStatus.Выполняется)
{
_logger.LogWarning("Status change operation failed");
throw new InvalidOperationException("Заказ должен быть переведен в статус выполнения перед готовностью!");
}
model.Status = OrderStatus.Завершён;
model.DateEnd = DateTime.Today;
_orderStorage.Update(model);
return true;
}
public bool TakeOrderInWork(OrderBindingModel model)
{
CheckModel(model, false);
var element = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id
});
if (element == null)
{
_logger.LogWarning("Read operation failed");
return false;
}
if (element.Status != OrderStatus.Принят)
{
_logger.LogWarning("Status change operation failed");
throw new InvalidOperationException("Заказ должен быть переведен в статус принятого перед его выполнением!");
}
model.Status = OrderStatus.Выполняется;
_orderStorage.Update(model);
return true;
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Description))
{
throw new ArgumentNullException("Нет описания заказа", nameof(model.Description));
}
if (string.IsNullOrEmpty(model.Adress))
{
throw new ArgumentNullException("Нет адреса заказа", nameof(model.Adress));
}
if (model.Price <= 0)
{
throw new InvalidOperationException("Цена должна быть больше 0!");
}
if (string.IsNullOrEmpty(model.CustomerNumber))
{
throw new ArgumentNullException("Нет телефона", nameof(model.CustomerNumber));
}
_logger.LogInformation("Order. Description:{Description}. Adress:{Adress}. Price:{Price} Id:{Id}", model.Description, model.Adress, model.Price, model.Id);
}
}
}

View File

@ -1,116 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class PositionLogic : IPositionLogic
{
private readonly ILogger _logger;
private readonly IPositionStorage _positionStorage;
public PositionLogic(ILogger<PositionLogic> logger, IPositionStorage positionStorage)
{
_logger = logger;
_positionStorage = positionStorage;
}
public List<PositionViewModel>? ReadList(PositionSearchModel? model)
{
_logger.LogInformation("ReadList. PositionName:{PositionName}. Id:{Id}", model?.PositionName, model?.Id);
var list = model == null ? _positionStorage.GetFullList() : _positionStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public PositionViewModel? ReadElement(PositionSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. PositionName:{PositionName}. Id:{Id}", model.PositionName, model.Id);
var element = _positionStorage.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(PositionBindingModel model)
{
CheckModel(model);
if (_positionStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(PositionBindingModel model)
{
CheckModel(model);
if (_positionStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(PositionBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_positionStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(PositionBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.PositionName))
{
throw new ArgumentNullException("Нет названия материала", nameof(model.PositionName));
}
if (model.Salary < 0)
{
throw new ArgumentNullException("Зарплата должна быть не меньше 0!", nameof(model.Salary));
}
_logger.LogInformation("Position. IngredietnName:{PositionName}. Salary:{Salary}. Id:{Id}", model.PositionName, model.Salary, model.Id);
}
public List<BrigadeReportViewModel> ReadPositionsAverage(DateTime dateFrom, DateTime dateTo)
{
var list = _positionStorage.GetPositionsAverage(dateFrom, dateTo);
return list;
}
}
}

View File

@ -1,105 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyDataModels.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class RandomGeneratorLogic : IRandomGeneratorLogic
{
private readonly IMaterialLogic _material;
private readonly IEmployeeLogic _employee;
private readonly IPositionLogic _position;
private readonly IOrderLogic _order;
private readonly IMaterialOrderLogic _materialOrder;
private readonly IEmployeeOrderLogic _employeeOrder;
public RandomGeneratorLogic(IMaterialLogic material, IEmployeeLogic employee, IPositionLogic position, IOrderLogic order, IMaterialOrderLogic materialOrder, IEmployeeOrderLogic employeeOrder)
{
_material = material;
_employee = employee;
_position = position;
_order = order;
_materialOrder = materialOrder;
_employeeOrder = employeeOrder;
}
public void GenerateEmployees()
{
int posInd = 0;
for (int i = 0; i < 200; i++)
{
_employee.Create(new EmployeeBindingModel { EmployeeName = "testEmp" + (i + 1), PositionID = posInd });
posInd++;
if (posInd == 20) posInd = 0;
}
}
public void GenerateEmployeesOrders()
{
for (int i = 0; i < 200; i++)
{
_employeeOrder.Create(new EmployeeOrderBindingModel { EmployeeId = i, OrderId = i});
}
}
public void GenerateMaterialOrders()
{
int quantity = 1;
for (int i = 0; i < 200; i++)
{
_materialOrder.Create(new MaterialOrderBindingModel { MaterialId = i, OrderId = i, Quantity = quantity});
quantity++;
if (quantity == 7) quantity = 1;
}
}
public void GenerateAdditionalMaterialOrders()
{
Random rand = new Random();
int quantity = 1;
for (int i = 1; i <= 100; i++)
{
int mat = rand.Next(0, 10);
int ord = rand.Next(0, 100);
if (_materialOrder.ReadElement(new MaterialOrderSearchModel { MaterialId = mat, OrderId = ord}) != null)
{
i--;
continue;
}
_materialOrder.Create(new MaterialOrderBindingModel { MaterialId = mat, OrderId = ord, Quantity = quantity });
quantity++;
if (quantity == 7) quantity = 1;
}
}
public void GenerateMaterials()
{
for (int i = 0; i < 200; i++)
{
_material.Create(new MaterialBindingModel { MaterialName = "testMat" + (i + 1), Quantity = 2000 });
}
}
public void GenerateOrders()
{
for (int i = 0; i < 1000; i++)
{
_order.CreateOrder(new OrderBindingModel { Description = "order" + (i + 1), Adress = "dsdsdssd", Price=20000, Status=OrderStatus.Неизвестен, CustomerNumber="+7838347475"});
}
}
public void GeneratePositions()
{
for (int i = 0; i < 20; i++)
{
_position.Create(new PositionBindingModel { PositionName = "testPos" + (i + 1), Salary = 20000 });
}
}
}
}

View File

@ -1,18 +0,0 @@
<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="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ConstructionCompanyContracts\ConstructionCompanyContracts.csproj" />
<ProjectReference Include="..\ConstructionCompanyPsqlImplement\ConstructionCompanyPsqlImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -1,114 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class EmployeeLogic :IEmployeeLogic
{
private readonly ILogger _logger;
private readonly IEmployeeStorage _employeeStorage;
public EmployeeLogic(ILogger<EmployeeLogic> logger, IEmployeeStorage employeeStorage)
{
_logger = logger;
_employeeStorage = employeeStorage;
}
public List<EmployeeViewModel>? ReadList(EmployeeSearchModel? model)
{
_logger.LogInformation("ReadList. EmployeeName:{EmployeeName}. Id:{Id}", model?.EmployeeName, model?.Id);
var list = model == null ? _employeeStorage.GetFullList() : _employeeStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public EmployeeViewModel? ReadElement(EmployeeSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. EmployeeName:{EmployeeName}. Id:{Id}", model.EmployeeName, model.Id);
var element = _employeeStorage.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(EmployeeBindingModel model)
{
CheckModel(model);
if (_employeeStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(EmployeeBindingModel model)
{
CheckModel(model);
if (_employeeStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(EmployeeBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_employeeStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(EmployeeBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.EmployeeName))
{
throw new ArgumentNullException("Нет названия материала", nameof(model.EmployeeName));
}
_logger.LogInformation("Employee. EmployeeName:{EmployeeName}. Id:{Id}", model.EmployeeName, model.Id);
var element = _employeeStorage.GetElement(new EmployeeSearchModel
{
EmployeeName = model.EmployeeName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Сотрудник с таким названием уже есть");
}
}
}
}

View File

@ -1,118 +0,0 @@
using ConstructionCompanyContracts.BusinessLogicContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.BindingModels;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class MaterialLogic : IMaterialLogic
{
private readonly ILogger _logger;
private readonly IMaterialStorage _materialStorage;
public MaterialLogic(ILogger<MaterialLogic> logger, IMaterialStorage materialStorage)
{
_logger = logger;
_materialStorage = materialStorage;
}
public List<MaterialViewModel>? ReadList(MaterialSearchModel? model)
{
_logger.LogInformation("ReadList. MaterialName:{MaterialName}. Id:{Id}", model?.MaterialName, model?.Id);
var list = model == null ? _materialStorage.GetFullList() : _materialStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public MaterialViewModel? ReadElement(MaterialSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. MaterialName:{MaterialName}. Id:{Id}", model.MaterialName, model.Id);
var element = _materialStorage.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(MaterialBindingModel model)
{
CheckModel(model);
if (_materialStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(MaterialBindingModel model)
{
CheckModel(model);
if (_materialStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(MaterialBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_materialStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(MaterialBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.MaterialName))
{
throw new ArgumentNullException("Нет названия материала", nameof(model.MaterialName));
}
if (model.Quantity < 0)
{
throw new ArgumentNullException("Колчество материалов должна быть не меньше 0", nameof(model.Quantity));
}
_logger.LogInformation("Material. IngredietnName:{MaterialName}. Quantity:{Quantity}. Id:{Id}", model.MaterialName, model.Quantity, model.Id);
var element = _materialStorage.GetElement(new MaterialSearchModel
{
MaterialName = model.MaterialName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Материал с таким названием уже есть");
}
}
}
}

View File

@ -1,135 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Enums;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class OrderLogic : IOrderLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
{
_logger = logger;
_orderStorage = orderStorage;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public OrderViewModel? ReadElement(OrderSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
var element = _orderStorage.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 CreateOrder(OrderBindingModel model)
{
CheckModel(model);
if (model.Status != OrderStatus.Неизвестен) return false;
model.Status = OrderStatus.Принят;
if (_orderStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool FinishOrder(OrderBindingModel model)
{
CheckModel(model, false);
var element = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id
});
if (element == null)
{
_logger.LogWarning("Read operation failed");
return false;
}
if (element.Status != OrderStatus.Выполняется)
{
_logger.LogWarning("Status change operation failed");
throw new InvalidOperationException("Заказ должен быть переведен в статус выполнения перед готовностью!");
}
model.Status = OrderStatus.Завершён;
_orderStorage.Update(model);
return true;
}
public bool TakeOrderInWork(OrderBindingModel model)
{
CheckModel(model, false);
var element = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id
});
if (element == null)
{
_logger.LogWarning("Read operation failed");
return false;
}
if (element.Status != OrderStatus.Принят)
{
_logger.LogWarning("Status change operation failed");
throw new InvalidOperationException("Заказ должен быть переведен в статус принятого перед его выполнением!");
}
model.Status = OrderStatus.Выполняется;
_orderStorage.Update(model);
return true;
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
_logger.LogInformation("Order. Id:{Id}", model.Id);
var element = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Заказ с таким названием уже есть");
}
}
}
}

View File

@ -1,117 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class PositionLogic
{
private readonly ILogger _logger;
private readonly IPositionStorage _positionStorage;
public PositionLogic(ILogger<PositionLogic> logger, IPositionStorage positionStorage)
{
_logger = logger;
_positionStorage = positionStorage;
}
public List<PositionViewModel>? ReadList(PositionSearchModel? model)
{
_logger.LogInformation("ReadList. PositionName:{PositionName}. Id:{Id}", model?.PositionName, model?.Id);
var list = model == null ? _positionStorage.GetFullList() : _positionStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public PositionViewModel? ReadElement(PositionSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. PositionName:{PositionName}. Id:{Id}", model.PositionName, model.Id);
var element = _positionStorage.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(PositionBindingModel model)
{
CheckModel(model);
if (_positionStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(PositionBindingModel model)
{
CheckModel(model);
if (_positionStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(PositionBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_positionStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(PositionBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.PositionName))
{
throw new ArgumentNullException("Нет названия материала", nameof(model.PositionName));
}
if (model.Salary < 0)
{
throw new ArgumentNullException("Зарплата должна быть не меньше 0", nameof(model.Salary));
}
_logger.LogInformation("Position. PositionName:{PositionName}. Salary:{Salary}. Id:{Id}", model.PositionName, model.Salary, model.Id);
var element = _positionStorage.GetElement(new PositionSearchModel
{
PositionName = model.PositionName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Должность с таким названием уже есть");
}
}
}
}

View File

@ -1,7 +0,0 @@
namespace ConstructionCompanyBusiness
{
public class Class1
{
}
}

View File

@ -1,13 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ConstructionCompanyContracts\ConstructionCompanyContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -1,18 +0,0 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BindingModels
{
public class EmployeeBindingModel : IEmployeeModel
{
public string EmployeeName { get; set; } = string.Empty;
public int PositionID { get; set; }
public int Id {get; set; }
}
}

View File

@ -1,15 +0,0 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BindingModels
{
public class EmployeeOrderBindingModel : IEmployeeOrderModel
{
public int EmployeeId { get; set; }
public int OrderId { get; set; }
}
}

View File

@ -1,18 +0,0 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BindingModels
{
public class MaterialBindingModel : IMaterialModel
{
public string MaterialName { get; set; } = string.Empty;
public int Quantity { get; set; }
public int Id { get; set; }
}
}

View File

@ -1,16 +0,0 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BindingModels
{
public class MaterialOrderBindingModel : IMaterialOrderModel
{
public int MaterialId { get; set; }
public int OrderId { get; set; }
public int Quantity { get; set; }
}
}

View File

@ -1,29 +0,0 @@
using ConstructionCompanyDataModels.Enums;
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BindingModels
{
public class OrderBindingModel : IOrderModel
{
public string Description { get; set; } = string.Empty;
public string Adress { get; set; } = string.Empty;
public double Price { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
public string CustomerNumber { get; set; } = string.Empty;
public DateTime DateBegin { get; set; } = DateTime.Now.Date;
public DateTime? DateEnd { get; set; }
public int Id { get; set; }
}
}

View File

@ -1,18 +0,0 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BindingModels
{
public class PositionBindingModel : IPositionModel
{
public string PositionName { get; set; } = string.Empty;
public double Salary { get; set; }
public int Id { get; set; }
}
}

View File

@ -1,20 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BusinessLogicContracts
{
public interface IEmployeeLogic
{
List<EmployeeViewModel>? ReadList(EmployeeSearchModel? model);
EmployeeViewModel? ReadElement(EmployeeSearchModel model);
bool Create(EmployeeBindingModel model);
bool Update(EmployeeBindingModel model);
bool Delete(EmployeeBindingModel model);
}
}

View File

@ -1,19 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BusinessLogicContracts
{
public interface IEmployeeOrderLogic
{
List<EmployeeOrderViewModel>? ReadList(EmployeeOrderSearchModel? model);
EmployeeOrderViewModel? ReadElement(EmployeeOrderSearchModel model);
bool Create(EmployeeOrderBindingModel model);
bool Delete(EmployeeOrderBindingModel model);
}
}

View File

@ -1,21 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BusinessLogicContracts
{
public interface IMaterialLogic
{
List<MaterialViewModel>? ReadList(MaterialSearchModel? model);
MaterialViewModel? ReadElement(MaterialSearchModel model);
List<EmployeeViewModel>? ReadEmployeesUsingMaterial(MaterialBindingModel model);
bool Create(MaterialBindingModel model);
bool Update(MaterialBindingModel model);
bool Delete(MaterialBindingModel model);
}
}

View File

@ -1,19 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BusinessLogicContracts
{
public interface IMaterialOrderLogic
{
List<MaterialOrderViewModel>? ReadList(MaterialOrderSearchModel? model);
MaterialOrderViewModel? ReadElement(MaterialOrderSearchModel model);
bool Create(MaterialOrderBindingModel model);
bool Delete(MaterialOrderBindingModel model);
}
}

View File

@ -1,20 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BusinessLogicContracts
{
public interface IOrderLogic
{
List<OrderViewModel>? ReadList(OrderSearchModel? model);
OrderViewModel? ReadElement(OrderSearchModel model);
bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model);
}
}

View File

@ -1,21 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BusinessLogicContracts
{
public interface IPositionLogic
{
List<PositionViewModel>? ReadList(PositionSearchModel? model);
PositionViewModel? ReadElement(PositionSearchModel model);
List<BrigadeReportViewModel>? ReadPositionsAverage(DateTime dateFrom, DateTime dateTo);
bool Create(PositionBindingModel model);
bool Update(PositionBindingModel model);
bool Delete(PositionBindingModel model);
}
}

View File

@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.BusinessLogicContracts
{
public interface IRandomGeneratorLogic
{
public void GenerateMaterials();
public void GenerateOrders();
public void GeneratePositions();
public void GenerateEmployees();
public void GenerateEmployeesOrders();
public void GenerateMaterialOrders();
public void GenerateAdditionalMaterialOrders();
}
}

View File

@ -1,13 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ConstructionCompanyDataModels\ConstructionCompanyDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.SearchModels
{
public class EmployeeOrderSearchModel
{
public int? EmployeeId { get; set; }
public int? OrderId { get; set; }
}
}

View File

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.SearchModels
{
public class EmployeeSearchModel
{
public int? Id { get; set; }
public string? EmployeeName { get; set; }
}
}

View File

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.SearchModels
{
public class MaterialOrderSearchModel
{
public int? MaterialId { get; set; }
public int? OrderId { get; set; }
}
}

View File

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.SearchModels
{
public class MaterialSearchModel
{
public int? Id { get; set; }
public string? MaterialName { get; set; }
}
}

View File

@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.SearchModels
{
public class OrderSearchModel
{
public int? Id { get; set; }
}
}

View File

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.SearchModels
{
public class PositionSearchModel
{
public int? Id { get; set; }
public string? PositionName { get; set; }
}
}

View File

@ -1,20 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.StorageContracts
{
public interface IEmployeeOrderStorage
{
List<EmployeeOrderViewModel> GetFullList();
List<EmployeeOrderViewModel> GetFilteredList(EmployeeOrderSearchModel model);
EmployeeOrderViewModel? GetElement(EmployeeOrderSearchModel model);
EmployeeOrderViewModel? Insert(EmployeeOrderBindingModel model);
EmployeeOrderViewModel? Delete(EmployeeOrderBindingModel model);
}
}

View File

@ -1,21 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.StorageContracts
{
public interface IEmployeeStorage
{
List<EmployeeViewModel> GetFullList();
List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model);
EmployeeViewModel? GetElement(EmployeeSearchModel model);
EmployeeViewModel? Insert(EmployeeBindingModel model);
EmployeeViewModel? Update(EmployeeBindingModel model);
EmployeeViewModel? Delete(EmployeeBindingModel model);
}
}

View File

@ -1,20 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.StorageContracts
{
public interface IMaterialOrderStorage
{
List<MaterialOrderViewModel> GetFullList();
List<MaterialOrderViewModel> GetFilteredList(MaterialOrderSearchModel model);
MaterialOrderViewModel? GetElement(MaterialOrderSearchModel model);
MaterialOrderViewModel? Insert(MaterialOrderBindingModel model);
MaterialOrderViewModel? Delete(MaterialOrderBindingModel model);
}
}

View File

@ -1,22 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.StorageContracts
{
public interface IMaterialStorage
{
List<MaterialViewModel> GetFullList();
List<MaterialViewModel> GetFilteredList(MaterialSearchModel model);
List<EmployeeViewModel>? GetEmployeesUsingMaterial(MaterialBindingModel model);
MaterialViewModel? GetElement(MaterialSearchModel model);
MaterialViewModel? Insert(MaterialBindingModel model);
MaterialViewModel? Update(MaterialBindingModel model);
MaterialViewModel? Delete(MaterialBindingModel model);
}
}

View File

@ -1,21 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.StorageContracts
{
public interface IOrderStorage
{
List<OrderViewModel> GetFullList();
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
OrderViewModel? GetElement(OrderSearchModel model);
OrderViewModel? Insert(OrderBindingModel model);
OrderViewModel? Update(OrderBindingModel model);
OrderViewModel? Delete(OrderBindingModel model);
}
}

View File

@ -1,22 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.StorageContracts
{
public interface IPositionStorage
{
List<PositionViewModel> GetFullList();
List<PositionViewModel> GetFilteredList(PositionSearchModel model);
List<BrigadeReportViewModel> GetPositionsAverage(DateTime dateFrom, DateTime dateTo);
PositionViewModel? GetElement(PositionSearchModel model);
PositionViewModel? Insert(PositionBindingModel model);
PositionViewModel? Update(PositionBindingModel model);
PositionViewModel? Delete(PositionBindingModel model);
}
}

View File

@ -1,18 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.ViewModels
{
public class BrigadeReportViewModel
{
public int PositionId { get; set; }
[DisplayName("Название должности")]
public string PositionName { get; set; } = string.Empty;
[DisplayName("Среденее потребление материалров")]
public double materialAvg { get; set; }
}
}

View File

@ -1,20 +0,0 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.ViewModels
{
public class EmployeeOrderViewModel : IEmployeeOrderModel
{
public int EmployeeId { get; set; }
[DisplayName("ФИО сотрудника")]
public string EmployeeName { get; set; } = string.Empty;
public int OrderId { get; set; }
[DisplayName("Адресс заказа")]
public string OrderAdress { get; set; } = string.Empty;
}
}

View File

@ -1,22 +0,0 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.ViewModels
{
public class EmployeeViewModel : IEmployeeModel
{
[DisplayName("ФИО")]
public string EmployeeName {get; set;} = string.Empty;
public int PositionID {get; set;}
[DisplayName("Должность")]
public string PositionName { get; set;} = string.Empty;
public int Id { get; set;}
}
}

View File

@ -1,22 +0,0 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.ViewModels
{
public class MaterialOrderViewModel : IMaterialOrderModel
{
public int MaterialId { get; set; }
[DisplayName("Адресс заказа")]
public string OrderAdress { get; set; } = string.Empty;
[DisplayName("Название материала")]
public string MaterialName { get; set; } = string.Empty;
public int OrderId { get; set; }
[DisplayName("Количество")]
public int Quantity { get; set; }
}
}

View File

@ -1,19 +0,0 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.ViewModels
{
public class MaterialViewModel : IMaterialModel
{
[DisplayName("Название материала")]
public string MaterialName { get; set; } = string.Empty;
[DisplayName("Количество")]
public int Quantity {get; set; }
public int Id { get; set; }
}
}

View File

@ -1,31 +0,0 @@
using ConstructionCompanyDataModels.Enums;
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.ViewModels
{
public class OrderViewModel : IOrderModel
{
[DisplayName("Номер")]
public int Id { get; set; }
[DisplayName("Описание")]
public string Description {get;set;} = string.Empty;
[DisplayName("Адрес")]
public string Adress {get;set;} = string.Empty;
[DisplayName("Стоимость")]
public double Price { get; set; }
[DisplayName("Статус")]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
[DisplayName("Телефон заказчика")]
public string CustomerNumber { get; set; } = string.Empty;
[DisplayName("Дата создания")]
public DateTime DateBegin { get; set; } = DateTime.Now.Date;
[DisplayName("Дата выполнения")]
public DateTime? DateEnd { get; set; }
}
}

View File

@ -1,19 +0,0 @@
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyContracts.ViewModels
{
public class PositionViewModel : IPositionModel
{
[DisplayName("Название должности")]
public string PositionName { get; set; } = string.Empty;
[DisplayName("Зарплата")]
public double Salary { get; set; }
public int Id { get; set; }
}
}

View File

@ -1,9 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyDataModels.Enums
{
public enum OrderStatus
{
Неизвестен = -1,
Принят = 0,
Выполняется = 1,
Завершён = 2
}
}

View File

@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyDataModels
{
public interface IId
{
int Id { get; }
}
}

View File

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyDataModels.Models
{
public interface IEmployeeModel : IId
{
string EmployeeName { get; }
int PositionID { get; }
}
}

View File

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyDataModels.Models
{
public interface IEmployeeOrderModel
{
int EmployeeId { get; }
int OrderId { get; }
}
}

View File

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyDataModels.Models
{
public interface IMaterialModel : IId
{
string MaterialName { get; }
int Quantity { get; }
}
}

View File

@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyDataModels.Models
{
public interface IMaterialOrderModel
{
int MaterialId { get; }
int OrderId { get; }
int Quantity { get; }
}
}

View File

@ -1,20 +0,0 @@
using ConstructionCompanyDataModels.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyDataModels.Models
{
public interface IOrderModel : IId
{
string Description { get; }
string Adress { get; }
double Price { get; }
OrderStatus Status { get; }
string CustomerNumber { get; }
DateTime DateBegin { get; }
DateTime? DateEnd { get; }
}
}

View File

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyDataModels.Models
{
public interface IPositionModel : IId
{
string PositionName { get; }
double Salary { get; }
}
}

View File

@ -1,288 +0,0 @@
using ConstructionCompanyMongoDBImplement.Models;
using ConstructionCompanyContracts.BindingModels;
using MongoDB.Bson;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConstructionCompanyDataModels.Enums;
using ConstructionCompanyContracts.ViewModels;
namespace ConstructionCompanyMongoDBImplement
{
public class ConstructionCompanyDatabase
{
static string connectionString = "mongodb://localhost:27017/";
static string databaseName = "ConstructionCompany";
private static ConstructionCompanyDatabase? _instance;
private MongoClient client = new MongoClient(connectionString);
private List<Material> _materials = new List<Material>();
private List<Employee> _employees = new List<Employee>();
private List<Position> _positions = new List<Position>();
private List<Order> _orders = new List<Order>();
private List<EmployeeOrder> _employeeOrders = new List<EmployeeOrder>();
private List<MaterialOrder> _materialOrders = new List<MaterialOrder>();
public List<Material> Materials
{
get
{
refreshDb();
return _materials;
}
}
public List<Employee> Employees
{
get
{
refreshDb();
return _employees;
}
}
public List<Position> Positions
{
get
{
refreshDb();
return _positions;
}
}
public List<Order> Orders
{
get
{
refreshDb();
return _orders;
}
}
public List<EmployeeOrder> EmployeeOrders
{
get
{
refreshDb();
return _employeeOrders;
}
}
public List<MaterialOrder> MaterialOrders
{
get
{
refreshDb();
return _materialOrders;
}
}
public ConstructionCompanyDatabase()
{
refreshDb();
}
public static ConstructionCompanyDatabase GetInstance()
{
if (_instance == null)
{
_instance = new ConstructionCompanyDatabase();
}
return _instance;
}
public BsonDocument ReadDocument(BsonDocument filter, string collectionName)
{
var collection = client.GetDatabase(databaseName).GetCollection<BsonDocument>(collectionName);
BsonDocument result = collection.Find(filter).First();
return result;
}
public void flushDb()
{
var db = client.GetDatabase(databaseName);
db.GetCollection<BsonDocument>("Employees").DeleteMany(new BsonDocument());
db.GetCollection<BsonDocument>("Orders").DeleteMany(new BsonDocument());
db.GetCollection<BsonDocument>("Materials").DeleteMany(new BsonDocument());
db.GetCollection<BsonDocument>("Positions").DeleteMany(new BsonDocument());
}
public List<EmployeeViewModel> reportMaterials(int materialId)
{
var materials = client.GetDatabase(databaseName).GetCollection<BsonDocument>("Materials");
var res = materials.Aggregate()
.Lookup(
"Orders",
"_id",
"materials.materialId",
"order"
)
.Lookup(
"Employees",
"order.employeesId",
"_id",
"employee"
)
.Match(new BsonDocument { { "_id", materialId} })
.ToList();
BsonArray resEmployees = res[0][4].AsBsonArray;
List<EmployeeViewModel> result = new List<EmployeeViewModel>();
foreach (var employee in resEmployees)
{
result.Add(_employees.First(x => x.Id == employee[0].ToInt32()).GetViewModel);
}
return result;
}
public List<BrigadeReportViewModel> reportPositionsAverage(DateTime from, DateTime to)
{
var positions = client.GetDatabase(databaseName).GetCollection<BsonDocument>("Positions");
var res = positions.Aggregate()
.Lookup(
"Employees",
"_id",
"positionId",
"employee"
)
.Lookup(
"Orders",
"employee._id",
"employeesId",
"order"
)
.Unwind("order")
.Match(new BsonDocument { { "order.dateBegin", new BsonDocument("$gte", new BsonDateTime(from)) } })
.Match(new BsonDocument { { "order.dateBegin", new BsonDocument("$lte", new BsonDateTime(to)) } })
.Unwind("order.materials")
.Group(new BsonDocument
{
{"_id", "$_id"},
{"average", new BsonDocument("$avg", "$order.materials.quantity")}
})
.ToList();
var result = new List<BrigadeReportViewModel>();
foreach (var report in res)
{
int posId = report[0].ToInt32();
string posName = _positions.First(x => x.Id == posId).PositionName;
int avg = report[1].ToInt32();
result.Add(new BrigadeReportViewModel { PositionId = posId, PositionName = posName, materialAvg = avg });
}
return result;
}
public List<BsonDocument> FilterDocuments(BsonDocument filter, string collectionName)
{
var collection = client.GetDatabase(databaseName).GetCollection<BsonDocument>(collectionName);
List<BsonDocument> result = collection.Find(filter).ToList();
return result;
}
public void InsertDocument(BsonDocument bson, string collectionName)
{
var collection = client.GetDatabase(databaseName).GetCollection<BsonDocument>(collectionName);
collection.InsertOne(bson);
refreshDb();
}
public void ReplaceDocument(BsonDocument bson, BsonDocument filter, string collectionName)
{
var collection = client.GetDatabase(databaseName).GetCollection<BsonDocument>(collectionName);
collection.ReplaceOne(filter, bson);
refreshDb();
}
public void DeleteDocument(BsonDocument filter, string collectionName)
{
var collection = client.GetDatabase(databaseName).GetCollection<BsonDocument>(collectionName);
collection.DeleteOne(filter);
refreshDb();
}
private void refreshDb()
{
_materials.Clear();
_positions.Clear();
_employees.Clear();
_orders.Clear();
_employeeOrders.Clear();
_materialOrders.Clear();
IMongoDatabase database = client.GetDatabase(databaseName);
List<BsonDocument> positions = database.GetCollection<BsonDocument>("Positions").Find(new BsonDocument()).ToList();
foreach (var position in positions)
{
int id = position[0].ToInt32();
string? name = position[1].ToString();
double salary = position[2].ToDouble();
Position? newPosition = Position.Create(new PositionBindingModel { Id = id, PositionName = name, Salary = salary });
if (newPosition != null) _positions.Add(newPosition);
}
List<BsonDocument> materials = database.GetCollection<BsonDocument>("Materials").Find(new BsonDocument()).ToList();
foreach (var material in materials)
{
int id = material[0].ToInt32();
string? name = material[1].ToString();
int quantity = material[2].ToInt32();
Material? newMaterial = Material.Create(new MaterialBindingModel { Id = id, MaterialName = name, Quantity = quantity });
if (newMaterial != null) _materials.Add(newMaterial);
}
List<BsonDocument> employees = database.GetCollection<BsonDocument>("Employees").Find(new BsonDocument()).ToList();
foreach (var employee in employees)
{
int id = employee[0].ToInt32();
string? name = employee[1].ToString();
int positionId = employee[2].ToInt32();
Employee? newEmployee = Employee.Create(new EmployeeBindingModel { Id = id, EmployeeName = name, PositionID = positionId }, _positions);
if (newEmployee != null) _employees.Add(newEmployee);
}
List<BsonDocument> orders = database.GetCollection<BsonDocument>("Orders").Find(new BsonDocument()).ToList();
foreach (var order in orders)
{
int id = order[0].ToInt32();
string? description = order[1].ToString();
string? adress = order[2].ToString();
double price = order[3].ToDouble();
string? status = order[4].ToString();
OrderStatus orderStatus = OrderStatus.Неизвестен;
switch (status)
{
case "Принят":
orderStatus = OrderStatus.Принят;
break;
case "Выполняется":
orderStatus = OrderStatus.Выполняется;
break;
case "Завершён":
orderStatus = OrderStatus.Завершён;
break;
}
string? customerNumber = order[5].ToString();
DateTime dateBegin = order[6].ToUniversalTime();
DateTime? dateEnd = null;
if (order[7].ToString().Length > 5) dateEnd = order[7].ToUniversalTime();
Order? newOrder = Order.Create(new OrderBindingModel { Id = id, Description = description, Adress = adress, Price = price,
Status = orderStatus, CustomerNumber = customerNumber, DateBegin = dateBegin, DateEnd = dateEnd });
if (newOrder != null) _orders.Add(newOrder);
BsonArray employeesId = order[8].AsBsonArray;
foreach (var employee in employeesId)
{
EmployeeOrder? employeeOrder = EmployeeOrder.Create(new EmployeeOrderBindingModel { EmployeeId = employee.ToInt32(), OrderId = id }, _employees, _orders);
if (employeeOrder != null) _employeeOrders.Add(employeeOrder);
}
BsonArray orderMaterials = order[9].AsBsonArray;
foreach (var material in orderMaterials)
{
int materialId = material[0].ToInt32();
int quantity = material[1].ToInt32();
MaterialOrder? materialOrder = MaterialOrder.Create(new MaterialOrderBindingModel { MaterialId = materialId, OrderId = id, Quantity = quantity }, _materials, _orders);
if (materialOrder != null) _materialOrders.Add(materialOrder);
}
}
}
}
}

View File

@ -1,19 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Bson" Version="2.19.1" />
<PackageReference Include="MongoDB.Driver" Version="2.19.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ConstructionCompanyBusiness\ConstructionCompanyBusinessLogic.csproj" />
<ProjectReference Include="..\ConstructionCompanyDataModels\ConstructionCompanyDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -1,111 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyMongoDBImplement.Models;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyMongoDBImplement.Implements
{
public class EmployeeOrderStorage : IEmployeeOrderStorage
{
private readonly ConstructionCompanyDatabase _source;
public EmployeeOrderStorage()
{
_source = ConstructionCompanyDatabase.GetInstance();
}
public List<EmployeeOrderViewModel> GetFullList()
{
List<EmployeeOrderViewModel> result = new List<EmployeeOrderViewModel>();
foreach (var material in _source.EmployeeOrders)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<EmployeeOrderViewModel> GetFilteredList(EmployeeOrderSearchModel model)
{
if (model == null || !model.OrderId.HasValue || !model.EmployeeId.HasValue)
{
return new();
}
List<EmployeeOrderViewModel> result = new List<EmployeeOrderViewModel>();
foreach (var material in _source.EmployeeOrders)
{
if (material.EmployeeId == model.EmployeeId && material.OrderId == model.OrderId) result.Add(material.GetViewModel);
}
return result;
}
public EmployeeOrderViewModel? GetElement(EmployeeOrderSearchModel model)
{
if (model == null || !model.OrderId.HasValue || !model.EmployeeId.HasValue)
{
return new();
}
return _source.EmployeeOrders.FirstOrDefault(x => x.EmployeeId == model.EmployeeId && x.OrderId == model.OrderId)?.GetViewModel;
}
public EmployeeOrderViewModel? Insert(EmployeeOrderBindingModel model)
{
var order = _source.ReadDocument(new BsonDocument { { "_id", model.OrderId } }, "Orders");
var employeeIds = order[8].AsBsonArray;
var materials = order[9].AsBsonArray;
employeeIds.Add(model.EmployeeId);
var orderView = _source.Orders.First(x => x.Id == model.OrderId);
OrderBindingModel orderModel = new OrderBindingModel
{
Id = orderView.Id,
Description = orderView.Description,
Adress = orderView.Adress,
Price = orderView.Price,
Status = orderView.Status,
CustomerNumber = orderView.CustomerNumber,
DateBegin = orderView.DateBegin,
DateEnd = orderView.DateEnd,
};
var document = Order.UpdateBSON(orderModel, employeeIds, materials);
if (document == null)
{
return null;
}
_source.ReplaceDocument(document, new BsonDocument { { "_id", model.OrderId} }, "Orders");
var newEmployeeOrder = _source.EmployeeOrders[_source.EmployeeOrders.Count - 1];
return newEmployeeOrder.GetViewModel;
}
public EmployeeOrderViewModel? Delete(EmployeeOrderBindingModel model)
{
var deletedEmployeeOrder = _source.EmployeeOrders.First(x => x.EmployeeId == model.EmployeeId && x.OrderId == model.OrderId).GetViewModel;
var order = _source.ReadDocument(new BsonDocument { { "_id", model.OrderId } }, "Orders");
var employeeIds = order[8].AsBsonArray;
var materials = order[9].AsBsonArray;
employeeIds.Remove(model.EmployeeId);
var orderView = _source.Orders.First(x => x.Id == model.OrderId);
OrderBindingModel orderModel = new OrderBindingModel
{
Id = orderView.Id,
Description = orderView.Description,
Adress = orderView.Adress,
Price = orderView.Price,
Status = orderView.Status,
CustomerNumber = orderView.CustomerNumber,
DateBegin = orderView.DateBegin,
DateEnd = orderView.DateEnd,
};
var document = Order.UpdateBSON(orderModel, employeeIds, materials);
if (document == null)
{
return null;
}
_source.ReplaceDocument(document, new BsonDocument { { "_id", model.OrderId } }, "Orders");
return deletedEmployeeOrder;
}
}
}

View File

@ -1,102 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyMongoDBImplement.Models;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyMongoDBImplement.Implements
{
public class EmployeeStorage : IEmployeeStorage
{
private readonly ConstructionCompanyDatabase _source;
private readonly IPositionStorage _positionStorage;
public EmployeeStorage(IPositionStorage positionStorage)
{
_source = ConstructionCompanyDatabase.GetInstance();
_positionStorage = positionStorage;
}
public List<EmployeeViewModel> GetFullList()
{
List<EmployeeViewModel> result = new List<EmployeeViewModel>();
foreach (var material in _source.Employees)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model)
{
if (model == null || !model.Id.HasValue && string.IsNullOrEmpty(model.EmployeeName))
{
return new();
}
List<EmployeeViewModel> result = new List<EmployeeViewModel>();
if (!string.IsNullOrEmpty(model.EmployeeName))
{
foreach (var material in _source.Employees)
{
if (material.EmployeeName.Equals(model.EmployeeName)) result.Add(material.GetViewModel);
}
return result;
}
else
{
foreach (var material in _source.Employees)
{
if (material.Id == model.Id) result.Add(material.GetViewModel);
}
return result;
}
}
public EmployeeViewModel? GetElement(EmployeeSearchModel model)
{
if (model == null || !model.Id.HasValue)
{
return new();
}
return _source.Employees.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
public EmployeeViewModel? Insert(EmployeeBindingModel model)
{
model.Id = _source.Employees.Count > 0 ? _source.Employees.Max(x => x.Id) + 1 : 0;
var document = Employee.CreateBSON(model);
if (document == null)
{
return null;
}
_source.InsertDocument(document, "Employees");
var newEmployee = _source.Employees[_source.Employees.Count - 1];
return newEmployee.GetViewModel;
}
public EmployeeViewModel? Update(EmployeeBindingModel model)
{
var document = Employee.UpdateBSON(model);
if (document == null)
{
return null;
}
_source.ReplaceDocument(document, new BsonDocument { { "_id", model.Id } }, "Employees");
var position = _source.Positions.First(x => x.Id == model.PositionID);
_positionStorage.Update(new PositionBindingModel { Id = position.Id, PositionName = position.PositionName, Salary = position.Salary });
var updatedEmployee = _source.Employees.First(x => x.Id == model.Id);
return updatedEmployee.GetViewModel;
}
public EmployeeViewModel? Delete(EmployeeBindingModel model)
{
var deletedEmployee = _source.Employees.First(x => x.Id == model.Id).GetViewModel;
_source.DeleteDocument(new BsonDocument { { "_id", model.Id } }, "Employees");
return deletedEmployee;
}
}
}

View File

@ -1,111 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyMongoDBImplement.Models;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyMongoDBImplement.Implements
{
public class MaterialOrderStorage : IMaterialOrderStorage
{
private readonly ConstructionCompanyDatabase _source;
public MaterialOrderStorage()
{
_source = ConstructionCompanyDatabase.GetInstance();
}
public List<MaterialOrderViewModel> GetFullList()
{
List<MaterialOrderViewModel> result = new List<MaterialOrderViewModel>();
foreach (var material in _source.MaterialOrders)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<MaterialOrderViewModel> GetFilteredList(MaterialOrderSearchModel model)
{
if (model == null || !model.OrderId.HasValue || !model.MaterialId.HasValue)
{
return new();
}
List<MaterialOrderViewModel> result = new List<MaterialOrderViewModel>();
foreach (var material in _source.MaterialOrders)
{
if (material.MaterialId == model.MaterialId && material.OrderId == model.OrderId) result.Add(material.GetViewModel);
}
return result;
}
public MaterialOrderViewModel? GetElement(MaterialOrderSearchModel model)
{
if (model == null || !model.OrderId.HasValue || !model.MaterialId.HasValue)
{
return new();
}
return _source.MaterialOrders.FirstOrDefault(x => x.MaterialId == model.MaterialId && x.OrderId == model.OrderId)?.GetViewModel;
}
public MaterialOrderViewModel? Insert(MaterialOrderBindingModel model)
{
var order = _source.ReadDocument(new BsonDocument { { "_id", model.OrderId } }, "Orders");
var employeeIds = order[8].AsBsonArray;
var materials = order[9].AsBsonArray;
materials.Add(new BsonDocument {{"materialId", model.MaterialId}, {"quantity", model.Quantity}});
var orderView = _source.Orders.First(x => x.Id == model.OrderId);
OrderBindingModel orderModel = new OrderBindingModel
{
Id = orderView.Id,
Description = orderView.Description,
Adress = orderView.Adress,
Price = orderView.Price,
Status = orderView.Status,
CustomerNumber = orderView.CustomerNumber,
DateBegin = orderView.DateBegin,
DateEnd = orderView.DateEnd,
};
var document = Order.UpdateBSON(orderModel, employeeIds, materials);
if (document == null)
{
return null;
}
_source.ReplaceDocument(document, new BsonDocument { { "_id", model.OrderId } }, "Orders");
var newMaterialOrder = _source.MaterialOrders[_source.MaterialOrders.Count - 1];
return newMaterialOrder.GetViewModel;
}
public MaterialOrderViewModel? Delete(MaterialOrderBindingModel model)
{
var deletedMaterialOrder = _source.MaterialOrders.First(x => x.MaterialId == model.MaterialId && x.OrderId == model.OrderId).GetViewModel;
var order = _source.ReadDocument(new BsonDocument { { "_id", model.OrderId } }, "Orders");
var employeeIds = order[8].AsBsonArray;
var materials = order[9].AsBsonArray;
employeeIds.Remove(new BsonDocument {{"materialId", model.MaterialId}, {"quantity", model.Quantity}});
var orderView = _source.Orders.First(x => x.Id == model.OrderId);
OrderBindingModel orderModel = new OrderBindingModel
{
Id = orderView.Id,
Description = orderView.Description,
Adress = orderView.Adress,
Price = orderView.Price,
Status = orderView.Status,
CustomerNumber = orderView.CustomerNumber,
DateBegin = orderView.DateBegin,
DateEnd = orderView.DateEnd,
};
var document = Order.UpdateBSON(orderModel, employeeIds, materials);
if (document == null)
{
return null;
}
_source.ReplaceDocument(document, new BsonDocument { { "_id", model.OrderId } }, "Orders");
return deletedMaterialOrder;
}
}
}

View File

@ -1,125 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyMongoDBImplement.Models;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyMongoDBImplement.Implements
{
public class MaterialStorage : IMaterialStorage
{
private readonly ConstructionCompanyDatabase _source;
public MaterialStorage()
{
_source = ConstructionCompanyDatabase.GetInstance();
}
public List<MaterialViewModel> GetFullList()
{
List<MaterialViewModel> result = new List<MaterialViewModel>();
foreach (var material in _source.Materials)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<MaterialViewModel> GetFilteredList(MaterialSearchModel model)
{
if (model == null || !model.Id.HasValue || string.IsNullOrEmpty(model.MaterialName))
{
return new();
}
List<MaterialViewModel> result = new List<MaterialViewModel>();
if (!string.IsNullOrEmpty(model.MaterialName))
{
foreach (var material in _source.Materials)
{
if (material.MaterialName.Equals(model.MaterialName)) result.Add(material.GetViewModel);
}
return result;
}
else
{
foreach (var material in _source.Materials)
{
if (material.Id == model.Id) result.Add(material.GetViewModel);
}
return result;
}
}
public MaterialViewModel? GetElement(MaterialSearchModel model)
{
if (model == null || !model.Id.HasValue)
{
return new();
}
return _source.Materials.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
public MaterialViewModel? Insert(MaterialBindingModel model)
{
model.Id = _source.Materials.Count > 0 ? _source.Materials.Max(x => x.Id) + 1 : 0;
var document = Material.CreateBSON(model);
if (document == null)
{
return null;
}
_source.InsertDocument(document, "Materials");
var newMaterial = _source.Materials[_source.Materials.Count - 1];
return newMaterial.GetViewModel;
}
public MaterialViewModel? Update(MaterialBindingModel model)
{
var document = Material.UpdateBSON(model);
if (document == null)
{
return null;
}
_source.ReplaceDocument(document, new BsonDocument { { "_id", model.Id } }, "Materials");
var updatedMaterial = _source.Materials.First(x => x.Id == model.Id);
return updatedMaterial.GetViewModel;
}
public MaterialViewModel? Delete(MaterialBindingModel model)
{
var deletedMaterial = _source.Materials.First(x => x.Id == model.Id).GetViewModel;
_source.DeleteDocument(new BsonDocument { { "_id", model.Id } }, "Materials");
return deletedMaterial;
}
public List<EmployeeViewModel>? GetEmployeesUsingMaterial(MaterialBindingModel model)
{
if (model == null)
{
return null;
}
//List<Employee> employeesList = _source.Employees;
//BsonDocument filter = new BsonDocument { { "materials.materialId", new BsonDocument("$eq", model.Id) } };
//List<BsonDocument> fiteredOrders = _source.FilterDocuments(filter, "Orders");
//List<EmployeeViewModel> employees = new List<EmployeeViewModel>();
//foreach (var order in fiteredOrders)
//{
// var orderEmployees = order[8].AsBsonArray;
// foreach (var employee in orderEmployees)
// {
// var emp = employees.FirstOrDefault(x => x.Id == employee.ToInt32());
// if (emp == null)
// {
// employees.Add(employeesList.First(x => x.Id == employee.ToInt32()).GetViewModel);
// }
// }
//}
var employees = _source.reportMaterials(model.Id);
return employees;
}
}
}

View File

@ -1,90 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyMongoDBImplement.Models;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyMongoDBImplement.Implements
{
public class OrderStorage : IOrderStorage
{
private readonly ConstructionCompanyDatabase _source;
public OrderStorage()
{
_source = ConstructionCompanyDatabase.GetInstance();
}
public List<OrderViewModel> GetFullList()
{
List<OrderViewModel> result = new List<OrderViewModel>();
foreach (var material in _source.Orders)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (model == null || !model.Id.HasValue)
{
return new();
}
List<OrderViewModel> result = new List<OrderViewModel>();
foreach (var material in _source.Orders)
{
if (material.Id == model.Id) result.Add(material.GetViewModel);
}
return result;
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (model == null || !model.Id.HasValue)
{
return new();
}
return _source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)
{
model.Id = _source.Orders.Count > 0 ? _source.Orders.Max(x => x.Id) + 1 : 0;
var document = Order.CreateBSON(model);
if (document == null)
{
return null;
}
_source.InsertDocument(document, "Orders");
var newOrder = _source.Orders[_source.Orders.Count - 1];
return newOrder.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
var order = _source.ReadDocument(new BsonDocument { { "_id", model.Id } }, "Orders");
var employeeIds = order[8].AsBsonArray;
var materials = order[9].AsBsonArray;
var document = Order.UpdateBSON(model, employeeIds, materials);
if (document == null)
{
return null;
}
_source.ReplaceDocument(document, new BsonDocument { { "_id", model.Id} }, "Orders");
var updatedOrder = _source.Orders.First(x => x.Id == model.Id);
return updatedOrder.GetViewModel;
}
public OrderViewModel? Delete(OrderBindingModel model)
{
var deletedOrder = _source.Orders.First(x => x.Id == model.Id).GetViewModel;
_source.DeleteDocument(new BsonDocument { { "_id", model.Id } }, "Orders");
return deletedOrder;
}
}
}

View File

@ -1,106 +0,0 @@
using Amazon.Auth.AccessControlPolicy;
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyMongoDBImplement.Models;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyMongoDBImplement.Implements
{
public class PositionStorage : IPositionStorage
{
private readonly ConstructionCompanyDatabase _source;
public PositionStorage()
{
_source = ConstructionCompanyDatabase.GetInstance();
}
public List<PositionViewModel> GetFullList()
{
List<PositionViewModel> result = new List<PositionViewModel>();
foreach (var material in _source.Positions)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<PositionViewModel> GetFilteredList(PositionSearchModel model)
{
if (model == null || !model.Id.HasValue && string.IsNullOrEmpty(model.PositionName))
{
return new();
}
List<PositionViewModel> result = new List<PositionViewModel>();
if (!string.IsNullOrEmpty(model.PositionName))
{
foreach (var material in _source.Positions)
{
if (material.PositionName.Equals(model.PositionName)) result.Add(material.GetViewModel);
}
return result;
}
else
{
foreach (var material in _source.Positions)
{
if (material.Id == model.Id) result.Add(material.GetViewModel);
}
return result;
}
}
public PositionViewModel? GetElement(PositionSearchModel model)
{
if (model == null || !model.Id.HasValue)
{
return new();
}
return _source.Positions.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
public PositionViewModel? Insert(PositionBindingModel model)
{
model.Id = _source.Positions.Count > 0 ? _source.Positions.Max(x => x.Id) + 1 : 0;
var document = Position.CreateBSON(model);
if (document == null)
{
return null;
}
_source.InsertDocument(document, "Positions");
var newPosition = _source.Positions[_source.Positions.Count - 1];
return newPosition.GetViewModel;
}
public PositionViewModel? Update(PositionBindingModel model)
{
var document = Position.UpdateBSON(model);
if (document == null)
{
return null;
}
_source.ReplaceDocument(document, new BsonDocument { {"_id" , model.Id} }, "Positions");
var updatedPosition = _source.Positions.First(x => x.Id == model.Id);
return updatedPosition.GetViewModel;
}
public PositionViewModel? Delete(PositionBindingModel model)
{
var deletedPosition = _source.Positions.First(x => x.Id == model.Id).GetViewModel;
_source.DeleteDocument(new BsonDocument { { "_id", model.Id } }, "Positions");
return deletedPosition;
}
public List<BrigadeReportViewModel> GetPositionsAverage(DateTime dateFrom, DateTime dateTo)
{
//_source.flushDb();
List<BrigadeReportViewModel> positionsAverages = _source.reportPositionsAverage(dateFrom, dateTo);
return positionsAverages;
}
}
}

View File

@ -1,71 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Models;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyMongoDBImplement.Models
{
public class Employee : IEmployeeModel
{
public string EmployeeName { get; private set; } = string.Empty;
public int Id { get; private set; }
public int PositionID { get; private set; }
public Position Position { get; set; } = new();
public static Employee? Create(EmployeeBindingModel? model, List<Position> positions)
{
if (model == null)
{
return null;
}
return new Employee()
{
Id = model.Id,
EmployeeName = model.EmployeeName,
PositionID = model.PositionID,
Position = positions.First(x => x.Id == model.PositionID)
};
}
public static BsonDocument? CreateBSON(EmployeeBindingModel? model)
{
if (model == null)
{
return null;
}
return new BsonDocument
{
{"_id", model.Id},
{"EmployeeName", $"{model.EmployeeName}"},
{"positionId", model.PositionID}
};
}
public static BsonDocument? UpdateBSON(EmployeeBindingModel? model)
{
if (model == null)
{
return null;
}
return new BsonDocument
{
{"_id", model.Id},
{"EmployeeName", $"{model.EmployeeName}"},
{"positionId", model.PositionID}
};
}
public EmployeeViewModel GetViewModel => new()
{
Id = Id,
EmployeeName = EmployeeName,
PositionID = PositionID,
PositionName = Position.PositionName
};
}
}

View File

@ -1,40 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyMongoDBImplement.Models
{
public class EmployeeOrder : IEmployeeOrderModel
{
public int EmployeeId { get; set; }
public int OrderId { get; set; }
public Employee Employee { get; set; } = new();
public Order Order { get; set; } = new();
public static EmployeeOrder? Create(EmployeeOrderBindingModel? model, List<Employee> employees, List<Order> orders)
{
if (model == null)
{
return null;
}
return new EmployeeOrder()
{
EmployeeId = model.EmployeeId,
OrderId = model.OrderId,
Employee = employees.First(x => x.Id == model.EmployeeId),
Order = orders.First(x => x.Id == model.OrderId),
};
}
public EmployeeOrderViewModel GetViewModel => new()
{
OrderId = OrderId,
EmployeeId = EmployeeId,
OrderAdress = Order.Adress,
EmployeeName = Employee.EmployeeName
};
}
}

View File

@ -1,69 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Models;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyMongoDBImplement.Models
{
public class Material : IMaterialModel
{
public string MaterialName { get; private set; } = string.Empty;
public int Quantity { get; set; }
public int Id { get; private set; }
public static Material? Create(MaterialBindingModel? model)
{
if (model == null)
{
return null;
}
return new Material()
{
Id = model.Id,
MaterialName = model.MaterialName,
Quantity = model.Quantity,
};
}
public static BsonDocument? CreateBSON(MaterialBindingModel? model)
{
if (model == null)
{
return null;
}
return new BsonDocument
{
{"_id", model.Id},
{"materialName", $"{model.MaterialName}"},
{"quantity", $"{model.Quantity}" }
};
}
public static BsonDocument? UpdateBSON(MaterialBindingModel? model)
{
if (model == null)
{
return null;
}
return new BsonDocument
{
{"_id", model.Id},
{"materialName", $"{model.MaterialName}"},
{"quantity", $"{model.Quantity}" }
};
}
public MaterialViewModel GetViewModel => new()
{
Id = Id,
MaterialName = MaterialName,
Quantity = Quantity
};
}
}

View File

@ -1,43 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyMongoDBImplement.Models
{
public class MaterialOrder : IMaterialOrderModel
{
public int MaterialId { get; set; }
public int OrderId { get; set; }
public int Quantity { get; set; }
public Material Material { get; set; } = new();
public Order Order { get; set; } = new();
public static MaterialOrder? Create(MaterialOrderBindingModel? model, List<Material> materials, List<Order> orders)
{
if (model == null)
{
return null;
}
return new MaterialOrder()
{
MaterialId = model.MaterialId,
OrderId = model.OrderId,
Quantity = model.Quantity,
Material = materials.First(x => x.Id == model.MaterialId),
Order = orders.First(x => x.Id == model.OrderId),
};
}
public MaterialOrderViewModel GetViewModel => new()
{
OrderId = OrderId,
MaterialId = MaterialId,
Quantity = Quantity,
OrderAdress = Order.Adress,
MaterialName = Material.MaterialName
};
}
}

View File

@ -1,101 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Enums;
using MongoDB.Bson;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyMongoDBImplement.Models
{
public class Order
{
public int Id { get; private set; }
public string Description { get; private set; } = string.Empty;
public string Adress { get; private set; } = string.Empty;
public string CustomerNumber { get; private set; } = string.Empty;
public double Price { get; private set; }
public OrderStatus Status { get; private set; }
public DateTime DateBegin { get; private set; }
public DateTime? DateEnd { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
Description = model.Description,
Adress = model.Adress,
CustomerNumber = model.CustomerNumber,
Price = model.Price,
Status = model.Status,
DateBegin = model.DateBegin,
DateEnd = model.DateEnd
};
}
public static BsonDocument? CreateBSON(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
BsonArray bsonArray = new BsonArray();
return new BsonDocument
{
{"_id", model.Id},
{"description", $"{model.Description}"},
{"adress", $"{model.Adress}"},
{"price", model.Price},
{"status", $"{model.Status}"},
{"customerNumber", $"{model.CustomerNumber}"},
{"dateBegin", new BsonDateTime(model.DateBegin)},
{"dateEnd", model.DateEnd.HasValue ? new BsonDateTime(model.DateEnd.Value) : ""},
{"employeesId", new BsonArray() },
{"materials", new BsonArray()}
};
}
public static BsonDocument? UpdateBSON(OrderBindingModel? model, BsonArray employeesId, BsonArray materials)
{
if (model == null)
{
return null;
}
return new BsonDocument
{
{"_id", model.Id},
{"description", $"{model.Description}"},
{"adress", $"{model.Adress}"},
{"price", model.Price},
{"status", $"{model.Status}"},
{"customerNumber", $"{model.CustomerNumber}"},
{"dateBegin", new BsonDateTime(model.DateBegin)},
{"dateEnd", model.DateEnd.HasValue ? new BsonDateTime(model.DateEnd.Value) : ""},
{"employeesId", employeesId },
{"materials", materials}
};
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
Description = Description,
Adress = Adress,
CustomerNumber = CustomerNumber,
Price = Price,
Status = Status,
DateBegin = DateBegin,
DateEnd = DateEnd
};
}
}

View File

@ -1,70 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Models;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyMongoDBImplement.Models
{
public class Position : IPositionModel
{
public string PositionName { get; private set; } = string.Empty;
public double Salary { get; set; }
public int Id { get; private set; }
public List<int> Employees { get; private set; } = new List<int>();
public static Position? Create(PositionBindingModel? model)
{
if (model == null)
{
return null;
}
return new Position()
{
Id = model.Id,
PositionName = model.PositionName,
Salary = model.Salary
};
}
public static BsonDocument? CreateBSON(PositionBindingModel? model)
{
if (model == null)
{
return null;
}
return new BsonDocument
{
{"_id", model.Id},
{"PositionName", $"{model.PositionName}"},
{"Salary", $"{model.Salary}" }
};
}
public static BsonDocument? UpdateBSON(PositionBindingModel? model)
{
if (model == null)
{
return null;
}
return new BsonDocument
{
{"_id", model.Id},
{"PositionName", $"{model.PositionName}"},
{"Salary", $"{model.Salary}" }
};
}
public PositionViewModel GetViewModel => new()
{
Id = Id,
PositionName = PositionName,
Salary = Salary
};
}
}

View File

@ -1,261 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConstructionCompanyPsqlImplement.Models;
using ConstructionCompanyContracts.BindingModels;
using Microsoft.EntityFrameworkCore;
using Npgsql;
using ConstructionCompanyDataModels.Enums;
using System.Diagnostics;
using Microsoft.Extensions.Logging;
namespace ConstructionCompanyPsqlImplement
{
public class ConstructionCompanyDatabase
{
static string connectionString = "Server=192.168.1.35;Port=5432;Database=ConstructionCompanyForwardEngineerd;User Id=postgres;Password=postgres;";
private static ConstructionCompanyDatabase? _instance;
private List<Material> _materials = new List<Material>();
private List<Employee> _employees = new List<Employee>();
private List<Position> _positions = new List<Position>();
private List<Order> _orders = new List<Order>();
private List<EmployeeOrder> _employeeOrders = new List<EmployeeOrder>();
private List<MaterialOrder> _materialOrders = new List<MaterialOrder>();
public List<Material> Materials
{
get
{
refreshDb();
return _materials;
}
}
public List<Employee> Employees
{
get
{
refreshDb();
return _employees;
}
}
public List<Position> Positions
{
get
{
refreshDb();
return _positions;
}
}
public List<Order> Orders
{
get
{
refreshDb();
return _orders;
}
}
public List<EmployeeOrder> EmployeeOrders
{
get
{
refreshDb();
return _employeeOrders;
}
}
public List<MaterialOrder> MaterialOrders
{
get
{
refreshDb();
return _materialOrders;
}
}
public static ConstructionCompanyDatabase GetInstance()
{
if (_instance == null)
{
_instance = new ConstructionCompanyDatabase();
}
return _instance;
}
public void ExecuteSql(string commandString)
{
using var connection = new NpgsqlConnection(connectionString);
connection.Open();
using var command = connection.CreateCommand();
command.CommandText = commandString;
command.ExecuteNonQuery();
refreshDb();
connection.Close();
}
public List<List<string>> ExecuteReader(string commandString, int numOfFields)
{
using var connection = new NpgsqlConnection(connectionString);
connection.Open();
using var commandMaterials = connection.CreateCommand();
commandMaterials.CommandText = commandString;
using var reader = commandMaterials.ExecuteReader();
List<List<string>> res = new List<List<string>>();
while (reader.Read())
{
List<string> item = new List<string>();
for (int i =0; i < numOfFields; i++)
{
item.Add(reader.GetValue(i).ToString());
}
res.Add(item);
}
return res;
}
private void refreshDb()
{
_materials.Clear();
_positions.Clear();
_employees.Clear();
_orders.Clear();
_employeeOrders.Clear();
_materialOrders.Clear();
using var connection = new NpgsqlConnection(connectionString);
connection.Open();
using var commandMaterials = connection.CreateCommand();
commandMaterials.CommandText = "SELECT * FROM material;";
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using var readerMaterials = commandMaterials.ExecuteReader();
stopwatch.Stop();
long materialsTime = stopwatch.ElapsedMilliseconds;
while (readerMaterials.Read())
{
int id = readerMaterials.GetInt32(0);
string name = readerMaterials.GetString(1);
int quantity = readerMaterials.GetInt32(2);
Material? mat = Material.Create(new MaterialBindingModel { Id = id, MaterialName = name, Quantity = quantity });
if (mat != null) _materials.Add(mat);
}
readerMaterials.Close();
using var commandPositions = connection.CreateCommand();
commandPositions.CommandText = "SELECT * FROM position;";
stopwatch.Restart();
using var readerPositions = commandPositions.ExecuteReader();
stopwatch.Stop();
long positionsTime = stopwatch.ElapsedMilliseconds;
while (readerPositions.Read())
{
int id = readerPositions.GetInt32(0);
string name = readerPositions.GetString(1);
double salary = readerPositions.GetDouble(2);
Position? position = Position.Create(new PositionBindingModel { Id = id, PositionName = name, Salary = salary });
if (position != null) _positions.Add(position);
}
readerPositions.Close();
using var commandEmployees = connection.CreateCommand();
commandEmployees.CommandText = "SELECT * FROM employee;";
stopwatch.Restart();
using var readerEmployees = commandEmployees.ExecuteReader();
stopwatch.Stop();
long employeesTime = stopwatch.ElapsedMilliseconds;
while (readerEmployees.Read())
{
int id = readerEmployees.GetInt32(0);
string name = readerEmployees.GetString(1);
int positionId = readerEmployees.GetInt32(2);
Employee? employee = Employee.Create(new EmployeeBindingModel { Id = id, EmployeeName = name, PositionID = positionId }, _positions);
if (employee != null) _employees.Add(employee);
}
readerEmployees.Close();
using var commandOrders = connection.CreateCommand();
commandOrders.CommandText = "SELECT * FROM \"order\";";
stopwatch.Restart();
using var readerOrders = commandOrders.ExecuteReader();
stopwatch.Stop();
long ordersTime = stopwatch.ElapsedMilliseconds;
while (readerOrders.Read())
{
int id = readerOrders.GetInt32(0);
string description = readerOrders.GetString(1);
string adress = readerOrders.GetString(2);
double price = readerOrders.GetDouble(3);
string statusString = readerOrders.GetString(4);
OrderStatus status;
switch (statusString)
{
case "Принят":
status = OrderStatus.Принят;
break;
case "Выполняется":
status = OrderStatus.Выполняется;
break;
case "Завершён":
status = OrderStatus.Завершён;
break;
default:
status = OrderStatus.Неизвестен;
break;
}
string customerNumber = readerOrders.GetString(5);
DateTime dateBegin = readerOrders.GetDateTime(6);
Order? order;
if (status == OrderStatus.Завершён)
{
DateTime? dateEnd = readerOrders.GetDateTime(7);
order = Order.Create(new OrderBindingModel { Id = id, Description = description, Adress = adress, Price = price, Status = status, CustomerNumber = customerNumber, DateBegin = dateBegin, DateEnd = dateEnd });
}
else
{
order = Order.Create(new OrderBindingModel { Id = id, Description = description, Adress = adress, Price = price, Status = status, CustomerNumber = customerNumber, DateBegin = dateBegin});
}
if (order != null) _orders.Add(order);
}
readerOrders.Close();
using var commandEmployeeOrders = connection.CreateCommand();
commandEmployeeOrders.CommandText = "SELECT * FROM employee_order;";
stopwatch.Restart();
using var readerEmployeeOrders = commandEmployeeOrders.ExecuteReader();
stopwatch.Stop();
long employeeOrderTime = stopwatch.ElapsedMilliseconds;
while (readerEmployeeOrders.Read())
{
int employeeId = readerEmployeeOrders.GetInt32(0);
int orderId = readerEmployeeOrders.GetInt32(1);
EmployeeOrder? employeeOrder = EmployeeOrder.Create(new EmployeeOrderBindingModel { EmployeeId = employeeId, OrderId = orderId}, _employees, _orders);
if (employeeOrder != null) _employeeOrders.Add(employeeOrder);
}
readerEmployeeOrders.Close();
using var commandMaterialOrders = connection.CreateCommand();
commandMaterialOrders.CommandText = "SELECT * FROM material_order;";
stopwatch.Restart();
using var readerMaterialOrders = commandMaterialOrders.ExecuteReader();
stopwatch.Stop();
long materialOrderTime = stopwatch.ElapsedMilliseconds;
while (readerMaterialOrders.Read())
{
int materialId = readerMaterialOrders.GetInt32(0);
int orderId = readerMaterialOrders.GetInt32(1);
int quantity = readerMaterialOrders.GetInt32(2);
MaterialOrder? materialOrder = MaterialOrder.Create(new MaterialOrderBindingModel { MaterialId = materialId, OrderId = orderId, Quantity = quantity}, _materials, _orders);
if (materialOrder != null) _materialOrders.Add(materialOrder);
}
readerMaterialOrders.Close();
connection.Close();
}
}
}

View File

@ -1,27 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>9152d6ad-e687-4e3f-836c-fd7263918b1d</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MongoDB.Bson" Version="2.19.1" />
<PackageReference Include="Npgsql" Version="7.0.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="7.0.3" />
<PackageReference Include="Npgsql.NodaTime" Version="7.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ConstructionCompanyContracts\ConstructionCompanyContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -1,78 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyPsqlImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Implements
{
public class EmployeeOrderStorage : IEmployeeOrderStorage
{
private readonly ConstructionCompanyDatabase _source;
public EmployeeOrderStorage()
{
_source = ConstructionCompanyDatabase.GetInstance();
}
public List<EmployeeOrderViewModel> GetFullList()
{
List<EmployeeOrderViewModel> result = new List<EmployeeOrderViewModel>();
foreach (var material in _source.EmployeeOrders)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<EmployeeOrderViewModel> GetFilteredList(EmployeeOrderSearchModel model)
{
if (model == null || !model.OrderId.HasValue || !model.EmployeeId.HasValue)
{
return new();
}
List<EmployeeOrderViewModel> result = new List<EmployeeOrderViewModel>();
foreach (var material in _source.EmployeeOrders)
{
if (material.EmployeeId == model.EmployeeId && material.OrderId == model.OrderId) result.Add(material.GetViewModel);
}
return result;
}
public EmployeeOrderViewModel? GetElement(EmployeeOrderSearchModel model)
{
if (model == null || !model.OrderId.HasValue || !model.EmployeeId.HasValue)
{
return new();
}
return _source.EmployeeOrders.FirstOrDefault(x => x.EmployeeId == model.EmployeeId && x.OrderId == model.OrderId)?.GetViewModel;
}
public EmployeeOrderViewModel? Insert(EmployeeOrderBindingModel model)
{
var command = EmployeeOrder.CreateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var newEmployeeOrder = _source.EmployeeOrders[_source.EmployeeOrders.Count - 1];
return newEmployeeOrder.GetViewModel;
}
public EmployeeOrderViewModel? Delete(EmployeeOrderBindingModel model)
{
var command = EmployeeOrder.DeleteCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
var deletedEmployeeOrder = _source.EmployeeOrders.First(x => x.EmployeeId == model.EmployeeId && x.OrderId == model.OrderId).GetViewModel;
_source.ExecuteSql(command);
return deletedEmployeeOrder;
}
}
}

View File

@ -1,101 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyPsqlImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Implements
{
public class EmployeeStorage : IEmployeeStorage
{
private readonly ConstructionCompanyDatabase _source;
public EmployeeStorage()
{
_source = ConstructionCompanyDatabase.GetInstance();
}
public List<EmployeeViewModel> GetFullList()
{
List<EmployeeViewModel> result = new List<EmployeeViewModel>();
foreach (var material in _source.Employees)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model)
{
if (model == null || !model.Id.HasValue && string.IsNullOrEmpty(model.EmployeeName))
{
return new();
}
List<EmployeeViewModel> result = new List<EmployeeViewModel>();
if (!string.IsNullOrEmpty(model.EmployeeName))
{
foreach (var material in _source.Employees)
{
if (material.EmployeeName.Equals(model.EmployeeName)) result.Add(material.GetViewModel);
}
return result;
}
else
{
foreach (var material in _source.Employees)
{
if (material.Id == model.Id) result.Add(material.GetViewModel);
}
return result;
}
}
public EmployeeViewModel? GetElement(EmployeeSearchModel model)
{
if (model == null || !model.Id.HasValue)
{
return new();
}
return _source.Employees.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
public EmployeeViewModel? Insert(EmployeeBindingModel model)
{
var command = Employee.CreateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var newEmployee = _source.Employees[_source.Employees.Count - 1];
return newEmployee.GetViewModel;
}
public EmployeeViewModel? Update(EmployeeBindingModel model)
{
var command = Employee.UpdateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var updatedEmployee = _source.Employees.First(x => x.Id == model.Id);
return updatedEmployee.GetViewModel;
}
public EmployeeViewModel? Delete(EmployeeBindingModel model)
{
var command = Employee.DeleteCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
var deletedEmployee = _source.Employees.First(x => x.Id == model.Id).GetViewModel;
_source.ExecuteSql(command);
return deletedEmployee;
}
}
}

View File

@ -1,79 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyPsqlImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Implements
{
public class MaterialOrderStorage : IMaterialOrderStorage
{
private readonly ConstructionCompanyDatabase _source;
public MaterialOrderStorage()
{
_source = ConstructionCompanyDatabase.GetInstance();
}
public List<MaterialOrderViewModel> GetFullList()
{
List<MaterialOrderViewModel> result = new List<MaterialOrderViewModel>();
foreach (var material in _source.MaterialOrders)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<MaterialOrderViewModel> GetFilteredList(MaterialOrderSearchModel model)
{
if (model == null || !model.OrderId.HasValue || !model.MaterialId.HasValue)
{
return new();
}
List<MaterialOrderViewModel> result = new List<MaterialOrderViewModel>();
foreach (var material in _source.MaterialOrders)
{
if (material.MaterialId == model.MaterialId && material.OrderId == model.OrderId) result.Add(material.GetViewModel);
}
return result;
}
public MaterialOrderViewModel? GetElement(MaterialOrderSearchModel model)
{
if (model == null || !model.OrderId.HasValue || !model.MaterialId.HasValue)
{
return new();
}
return _source.MaterialOrders.FirstOrDefault(x => x.MaterialId == model.MaterialId && x.OrderId == model.OrderId)?.GetViewModel;
}
public MaterialOrderViewModel? Insert(MaterialOrderBindingModel model)
{
var command = MaterialOrder.CreateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var newMaterialOrder = _source.MaterialOrders[_source.MaterialOrders.Count - 1];
return newMaterialOrder.GetViewModel;
}
public MaterialOrderViewModel? Delete(MaterialOrderBindingModel model)
{
var command = MaterialOrder.DeleteCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
var deletedMaterialOrder = _source.MaterialOrders.First(x => x.MaterialId == model.MaterialId && x.OrderId == model.OrderId).GetViewModel;
_source.ExecuteSql(command);
return deletedMaterialOrder;
}
}
}

View File

@ -1,116 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyPsqlImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Implements
{
public class MaterialStorage : IMaterialStorage
{
private readonly ConstructionCompanyDatabase _source;
public MaterialStorage()
{
_source = ConstructionCompanyDatabase.GetInstance();
}
public List<MaterialViewModel> GetFullList()
{
List<MaterialViewModel> result = new List<MaterialViewModel>();
foreach (var material in _source.Materials)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<MaterialViewModel> GetFilteredList(MaterialSearchModel model)
{
if (model == null || !model.Id.HasValue || string.IsNullOrEmpty(model.MaterialName))
{
return new();
}
List<MaterialViewModel> result = new List<MaterialViewModel>();
if (!string.IsNullOrEmpty(model.MaterialName))
{
foreach (var material in _source.Materials)
{
if (material.MaterialName.Equals(model.MaterialName)) result.Add(material.GetViewModel);
}
return result;
}
else
{
foreach (var material in _source.Materials)
{
if (material.Id == model.Id) result.Add(material.GetViewModel);
}
return result;
}
}
public MaterialViewModel? GetElement(MaterialSearchModel model)
{
if (model == null || !model.Id.HasValue)
{
return new();
}
return _source.Materials.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
public MaterialViewModel? Insert(MaterialBindingModel model)
{
var command = Material.CreateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var newMaterial = _source.Materials[_source.Materials.Count - 1];
return newMaterial.GetViewModel;
}
public MaterialViewModel? Update(MaterialBindingModel model)
{
var command = Material.UpdateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var updatedMaterial = _source.Materials.First(x => x.Id == model.Id);
return updatedMaterial.GetViewModel;
}
public MaterialViewModel? Delete(MaterialBindingModel model)
{
var command = Material.DeleteCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
var deletedMaterial = _source.Materials.First(x => x.Id == model.Id).GetViewModel;
_source.ExecuteSql(command);
return deletedMaterial;
}
public List<EmployeeViewModel>? GetEmployeesUsingMaterial(MaterialBindingModel model)
{
var command = Material.GetEmployeeCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
var employeesId = _source.ExecuteReader(command, 1);
List<EmployeeViewModel> employees = new List<EmployeeViewModel>();
foreach (var id in employeesId)
{
employees.Add(_source.Employees.First(x => x.Id == Convert.ToInt32(id[0])).GetViewModel);
}
return employees;
}
}
}

View File

@ -1,90 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyPsqlImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Implements
{
public class OrderStorage : IOrderStorage
{
private readonly ConstructionCompanyDatabase _source;
public OrderStorage()
{
_source = ConstructionCompanyDatabase.GetInstance();
}
public List<OrderViewModel> GetFullList()
{
List<OrderViewModel> result = new List<OrderViewModel>();
foreach (var material in _source.Orders)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (model == null || !model.Id.HasValue)
{
return new();
}
List<OrderViewModel> result = new List<OrderViewModel>();
foreach (var material in _source.Orders)
{
if (material.Id == model.Id) result.Add(material.GetViewModel);
}
return result;
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (model == null || !model.Id.HasValue)
{
return new();
}
return _source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)
{
var command = Order.CreateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var newOrder = _source.Orders[_source.Orders.Count - 1];
return newOrder.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
var command = Order.UpdateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var updatedOrder = _source.Orders.First(x => x.Id == model.Id);
return updatedOrder.GetViewModel;
}
public OrderViewModel? Delete(OrderBindingModel model)
{
var command = Order.DeleteCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
var deletedOrder = _source.Orders.First(x => x.Id == model.Id).GetViewModel;
_source.ExecuteSql(command);
return deletedOrder;
}
}
}

View File

@ -1,114 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.StorageContracts;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyPsqlImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Implements
{
public class PositionStorage : IPositionStorage
{
private readonly ConstructionCompanyDatabase _source;
public PositionStorage()
{
_source = ConstructionCompanyDatabase.GetInstance();
}
public List<PositionViewModel> GetFullList()
{
List<PositionViewModel> result = new List<PositionViewModel>();
foreach (var material in _source.Positions)
{
result.Add(material.GetViewModel);
}
return result;
}
public List<PositionViewModel> GetFilteredList(PositionSearchModel model)
{
if (model == null || !model.Id.HasValue && string.IsNullOrEmpty(model.PositionName))
{
return new();
}
List<PositionViewModel> result = new List<PositionViewModel>();
if (!string.IsNullOrEmpty(model.PositionName))
{
foreach (var material in _source.Positions)
{
if (material.PositionName.Equals(model.PositionName)) result.Add(material.GetViewModel);
}
return result;
}
else
{
foreach (var material in _source.Positions)
{
if (material.Id == model.Id) result.Add(material.GetViewModel);
}
return result;
}
}
public PositionViewModel? GetElement(PositionSearchModel model)
{
if (model == null || !model.Id.HasValue)
{
return new();
}
return _source.Positions.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
public PositionViewModel? Insert(PositionBindingModel model)
{
var command = Position.CreateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var newPosition = _source.Positions[_source.Positions.Count - 1];
return newPosition.GetViewModel;
}
public PositionViewModel? Update(PositionBindingModel model)
{
var command = Position.UpdateCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
_source.ExecuteSql(command);
var updatedPosition = _source.Positions.First(x => x.Id == model.Id);
return updatedPosition.GetViewModel;
}
public PositionViewModel? Delete(PositionBindingModel model)
{
var command = Position.DeleteCommand(model);
if (string.IsNullOrEmpty(command))
{
return null;
}
var deletedPosition = _source.Positions.First(x => x.Id == model.Id).GetViewModel;
_source.ExecuteSql(command);
return deletedPosition;
}
public List<BrigadeReportViewModel> GetPositionsAverage(DateTime dateFrom, DateTime dateTo)
{
var command = Position.PositionsAVGCommnad(dateFrom, dateTo);
var result = _source.ExecuteReader(command, 2);
List<BrigadeReportViewModel> positionsAverages = new List<BrigadeReportViewModel>();
foreach (var posAvgPair in result)
{
string positionName = _source.Positions.First(x => x.Id == Convert.ToInt32(posAvgPair[0])).PositionName;
positionsAverages.Add(new BrigadeReportViewModel { PositionId = Convert.ToInt32(posAvgPair[0]), PositionName = positionName, materialAvg = Convert.ToDouble(posAvgPair[1]) });
}
return positionsAverages;
}
}
}

View File

@ -1,96 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Models;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Models
{
public class Employee : IEmployeeModel
{
public string EmployeeName { get; private set; } = string.Empty;
public int Id { get; private set; }
public int PositionID { get; private set; }
public Position Position { get; set; } = new();
public static Employee? Create(EmployeeBindingModel? model, List<Position> positions)
{
if (model == null)
{
return null;
}
return new Employee()
{
Id = model.Id,
EmployeeName = model.EmployeeName,
PositionID = model.PositionID,
Position = positions.First(x => x.Id == model.PositionID)
};
}
public void Update(EmployeeBindingModel? model)
{
if (model == null)
{
return;
}
EmployeeName = model.EmployeeName;
PositionID = model.PositionID;
}
public static string CreateCommand(EmployeeBindingModel? model)
{
if (model == null)
{
return "";
}
return $"INSERT INTO employee(name, position_id) VALUES(\'{model.EmployeeName}\', {model.PositionID});";
}
public static string UpdateCommand(EmployeeBindingModel? model)
{
if (model == null)
{
return "";
}
return $"UPDATE employee SET \"name\" = \'{model.EmployeeName}\', position_id = {model.PositionID} WHERE id = {model.Id}";
}
public static string DeleteCommand(EmployeeBindingModel? model)
{
if (model == null)
{
return "";
}
return $"DELETE FROM employee WHERE id = {model.Id}";
}
public EmployeeViewModel GetViewModel => new()
{
Id = Id,
EmployeeName = EmployeeName,
PositionID = PositionID,
PositionName = Position.PositionName
};
public BsonDocument CreateBSON =>
new BsonDocument
{
{"_id", Id - 1},
{"EmployeeName", $"{EmployeeName}"},
{"positionId", PositionID - 1}
};
public BsonDocument UpdateBSON =>
new BsonDocument
{
{"_id", Id - 1},
{"EmployeeName", $"{EmployeeName}"},
{"positionId", PositionID - 1}
};
}
}

View File

@ -1,56 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Models
{
public class EmployeeOrder : IEmployeeOrderModel
{
public int EmployeeId { get; set; }
public int OrderId { get; set; }
public Employee Employee { get; set; } = new();
public Order Order { get; set; } = new();
public static EmployeeOrder? Create(EmployeeOrderBindingModel? model, List<Employee> employees, List<Order> orders)
{
if (model == null)
{
return null;
}
return new EmployeeOrder()
{
EmployeeId = model.EmployeeId,
OrderId = model.OrderId,
Employee = employees.First(x => x.Id == model.EmployeeId),
Order = orders.First(x => x.Id == model.OrderId),
};
}
public static string CreateCommand(EmployeeOrderBindingModel? model)
{
if (model == null)
{
return "";
}
return $"INSERT INTO employee_order(employee_id, order_id) VALUES({model.EmployeeId}, {model.OrderId});";
}
public static string DeleteCommand(EmployeeOrderBindingModel? model)
{
if (model == null)
{
return "";
}
return $"DELETE FROM material WHERE employee_id = {model.EmployeeId} AND order_id = {model.OrderId}";
}
public EmployeeOrderViewModel GetViewModel => new()
{
OrderId = OrderId,
EmployeeId = EmployeeId,
OrderAdress = Order.Adress,
EmployeeName = Employee.EmployeeName
};
}
}

View File

@ -1,101 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Models;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Models
{
public class Material : IMaterialModel
{
public string MaterialName {get; private set;} = string.Empty;
public int Quantity { get; set; }
public int Id { get; private set; }
public static Material? Create(MaterialBindingModel? model)
{
if (model == null)
{
return null;
}
return new Material()
{
Id = model.Id,
MaterialName = model.MaterialName,
Quantity = model.Quantity
};
}
public static string CreateCommand(MaterialBindingModel? model)
{
if (model == null)
{
return "";
}
return $"INSERT INTO material(name, quantity) VALUES(\'{model.MaterialName}\', {model.Quantity});";
}
public static string UpdateCommand(MaterialBindingModel? model)
{
if (model == null)
{
return "";
}
return $"UPDATE material SET \"name\" = \'{model.MaterialName}\', quantity = {model.Quantity} WHERE id = {model.Id}";
}
public static string DeleteCommand(MaterialBindingModel? model)
{
if (model == null)
{
return "";
}
return $"DELETE FROM material WHERE id = {model.Id}";
}
public static string GetEmployeeCommand(MaterialBindingModel? model)
{
if (model == null)
{
return "";
}
return $"SELECT e.id FROM employee e JOIN employee_order ON employee_order.employee_id = e.id JOIN \"order\" ON \"order\".id = employee_order.order_id JOIN material_order ON material_order.order_id = \"order\".id JOIN material mat ON mat.id = material_order.material_id WHERE mat.id = {model.Id};";
}
public void Update(MaterialBindingModel? model)
{
if (model == null)
{
return;
}
MaterialName = model.MaterialName;
Quantity = model.Quantity;
}
public BsonDocument CreateBSON =>
new BsonDocument
{
{"_id", Id - 1},
{"materialName", $"{MaterialName}"},
{"quantity", $"{Quantity}" }
};
public BsonDocument UpdateBSON =>
new BsonDocument
{
{"_id", Id - 1},
{"materialName", $"{MaterialName}"},
{"quantity", $"{Quantity}" }
};
public MaterialViewModel GetViewModel => new()
{
Id = Id,
MaterialName = MaterialName,
Quantity = Quantity
};
}
}

View File

@ -1,67 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Models;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Models
{
public class MaterialOrder : IMaterialOrderModel
{
public int MaterialId { get; set; }
public int OrderId { get; set; }
public int Quantity { get; set; }
public Material Material { get; set; } = new();
public Order Order { get; set; } = new();
public static MaterialOrder? Create(MaterialOrderBindingModel? model, List<Material> materials, List<Order> orders)
{
if (model == null)
{
return null;
}
return new MaterialOrder()
{
MaterialId = model.MaterialId,
OrderId = model.OrderId,
Quantity = model.Quantity,
Material = materials.First(x => x.Id == model.MaterialId),
Order = orders.First(x => x.Id == model.OrderId),
};
}
public static string CreateCommand(MaterialOrderBindingModel? model)
{
if (model == null)
{
return "";
}
return $"INSERT INTO material_order(material_id, order_id, quantiny) VALUES({model.MaterialId}, {model.OrderId}, {model.Quantity});";
}
public static string DeleteCommand(MaterialOrderBindingModel? model)
{
if (model == null)
{
return "";
}
return $"DELETE FROM material WHERE material_id = {model.MaterialId} AND order_id = {model.OrderId}";
}
public BsonDocument CreateBSON =>
new BsonDocument
{
{"materialId", MaterialId - 1 },
{"quantity", Quantity }
};
public MaterialOrderViewModel GetViewModel => new()
{
OrderId = OrderId,
MaterialId = MaterialId,
Quantity = Quantity,
OrderAdress = Order.Adress,
MaterialName = Material.MaterialName
};
}
}

View File

@ -1,128 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Enums;
using ConstructionCompanyDataModels.Models;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
public string Description { get; private set; } = string.Empty;
public string Adress { get; private set; } = string.Empty;
public string CustomerNumber { get; private set; } = string.Empty;
public double Price { get; private set; }
public OrderStatus Status { get; private set; }
public DateTime DateBegin { get; private set; }
public DateTime? DateEnd { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
Description = model.Description,
Adress = model.Adress,
CustomerNumber = model.CustomerNumber,
Price = model.Price,
Status = model.Status,
DateBegin = model.DateBegin,
DateEnd = model.DateEnd,
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
if (model.DateEnd.HasValue) DateEnd = model.DateEnd;
}
public static string CreateCommand(OrderBindingModel? model)
{
if (model == null)
{
return "";
}
return $"INSERT INTO \"order\"(description, adress, price, status, " +
$"customer_number, date_begin, date_end) VALUES(\'{model.Description}\', \'{model.Adress}\', {model.Price}, " +
$"\'{model.Status}\', \'{model.CustomerNumber}\', \'{model.DateBegin}\', " +
$"{(model.DateEnd.HasValue ? $"\'{model.DateEnd}\'" : "null")});";
}
public static string UpdateCommand(OrderBindingModel? model)
{
if (model == null)
{
return "";
}
return $"UPDATE \"order\" SET status = \'{model.Status}\', date_end = {(model.DateEnd.HasValue ? $"\'{model.DateEnd}\'" : "null")} " +
$"WHERE id = {model.Id}";
}
public static string DeleteCommand(OrderBindingModel? model)
{
if (model == null)
{
return "";
}
return $"DELETE FROM \"order\" WHERE id = {model.Id}";
}
public BsonDocument CreateBSON =>
new BsonDocument
{
{"_id", Id},
{"description", $"{Description}"},
{"adress", $"{Adress}"},
{"price", Price},
{"status", $"{Status}"},
{"customerNumber", $"{CustomerNumber}"},
{"dateBegin", new BsonDateTime(DateBegin)},
{"dateEnd", DateEnd.HasValue ? new BsonDateTime(DateEnd.Value) : ""},
{"employeesId", new BsonArray() },
{"materials", new BsonArray()}
};
public BsonDocument UpdateBSON(BsonArray employeesId, BsonArray materials) =>
new BsonDocument
{
{"_id", Id - 1},
{"description", $"{Description}"},
{"adress", $"{Adress}"},
{"price", Price},
{"status", $"{Status}"},
{"customerNumber", $"{CustomerNumber}"},
{"dateBegin", new BsonDateTime(DateBegin)},
{"dateEnd", DateEnd.HasValue ? new BsonDateTime(DateEnd.Value) : ""},
{"employeesId", employeesId },
{"materials", materials}
};
public OrderViewModel GetViewModel => new()
{
Id = Id,
Description = Description,
Adress = Adress,
CustomerNumber = CustomerNumber,
Price = Price,
Status = Status,
DateBegin = DateBegin,
DateEnd = DateEnd
};
}
}

View File

@ -1,96 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyDataModels.Models;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyPsqlImplement.Models
{
public class Position : IPositionModel
{
public string PositionName { get; private set; } = string.Empty;
public double Salary { get; set; }
public int Id { get; private set; }
public static Position? Create(PositionBindingModel? model)
{
if (model == null)
{
return null;
}
return new Position()
{
Id = model.Id,
PositionName = model.PositionName,
Salary = model.Salary
};
}
public void Update(PositionBindingModel? model)
{
if (model == null)
{
return;
}
PositionName = model.PositionName;
Salary = model.Salary;
}
public static string CreateCommand(PositionBindingModel? model)
{
if (model == null)
{
return "";
}
return $"INSERT INTO position(name, salary) VALUES(\'{model.PositionName}\', {model.Salary});";
}
public static string UpdateCommand(PositionBindingModel? model)
{
if (model == null)
{
return "";
}
return $"UPDATE position SET \"name\" = \'{model.PositionName}\', salary = {model.Salary} WHERE id = {model.Id}";
}
public static string DeleteCommand(PositionBindingModel? model)
{
if (model == null)
{
return "";
}
return $"DELETE FROM postition WHERE id = {model.Id}";
}
public static string PositionsAVGCommnad(DateTime dateFrom, DateTime dateTo)
{
return $"SELECT \"position\".id, AVG(material_order.quantiny) FROM \"position\"\r\nJOIN employee ON employee.position_id = \"position\".id\r\nJOIN employee_order ON employee_order.employee_id = employee.id\r\nJOIN \"order\" ON \"order\".id = employee_order.order_id\r\nJOIN material_order ON material_order.order_id = \"order\".id\r\nJOIN material ON material.id = material_order.material_id\r\nWHERE \"order\".date_begin >= '{dateFrom}' AND \"order\".date_begin <= '{dateTo}'\r\nGROUP BY \"position\".id";
}
public BsonDocument CreateBSON =>
new BsonDocument
{
{"_id", Id - 1},
{"PositionName", $"{PositionName}"},
{"Salary", $"{Salary}" }
};
public BsonDocument UpdateBSON =>
new BsonDocument
{
{"_id", Id - 1},
{"PositionName", $"{PositionName}"},
{"Salary", $"{Salary}" }
};
public PositionViewModel GetViewModel => new()
{
Id = Id,
PositionName = PositionName,
Salary = Salary
};
}
}

View File

@ -1,21 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ConstructionCompanyView.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="ConstructionCompanyView.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<ConstructionCompanyView.Properties.Settings>
<setting name="bdType" serializeAs="String">
<value>postgres</value>
</setting>
</ConstructionCompanyView.Properties.Settings>
<ConstructionCompanyView.Settings>
<setting name="bdType" serializeAs="String">
<value>postgres</value>
</setting>
</ConstructionCompanyView.Settings>
</userSettings>
</configuration>

View File

@ -8,61 +8,4 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<None Remove="Logos\warehouseLogo.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="NLog" Version="5.1.3" />
<PackageReference Include="NLog.Config" Version="4.7.15" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.3" />
<PackageReference Include="NLog.Schema" Version="5.1.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ConstructionCompanyBusiness\ConstructionCompanyBusinessLogic.csproj" />
<ProjectReference Include="..\ConstructionCompanyContracts\ConstructionCompanyContracts.csproj" />
<ProjectReference Include="..\ConstructionCompanyMongoDBImplement\ConstructionCompanyMongoDBImplement.csproj" />
<ProjectReference Include="..\ConstructionCompanyPsqlImplement\ConstructionCompanyPsqlImplement.csproj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Logos\warehouseLogo.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="nlogConstruction.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,39 @@
namespace ConstructionCompanyView
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -0,0 +1,10 @@
namespace ConstructionCompanyView
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -117,11 +117,4 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="cash-register-solid" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\cash-register-solid.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="users-viewfinder-solid" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\users-viewfinder-solid.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root> </root>

View File

@ -1,108 +0,0 @@
namespace ConstructionCompanyView
{
partial class FormBrigadeMenu
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.сотрудникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.должностиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.назначитьНаЗаказToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.отчётПоДолжностямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.сотрудникиToolStripMenuItem,
this.должностиToolStripMenuItem,
this.назначитьНаЗаказToolStripMenuItem,
this.отчётПоДолжностямToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(645, 28);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// сотрудникиToolStripMenuItem
//
this.сотрудникиToolStripMenuItem.Name = "сотрудникиToolStripMenuItem";
this.сотрудникиToolStripMenuItem.Size = new System.Drawing.Size(105, 24);
this.сотрудникиToolStripMenuItem.Text = "Сотрудники";
this.сотрудникиToolStripMenuItem.Click += new System.EventHandler(this.сотрудникиToolStripMenuItem_Click);
//
// должностиToolStripMenuItem
//
this.должностиToolStripMenuItem.Name = олжностиToolStripMenuItem";
this.должностиToolStripMenuItem.Size = new System.Drawing.Size(101, 24);
this.должностиToolStripMenuItem.Text = "Должности";
this.должностиToolStripMenuItem.Click += new System.EventHandler(this.должностиToolStripMenuItem_Click);
//
// назначитьНаЗаказToolStripMenuItem
//
this.назначитьНаЗаказToolStripMenuItem.Name = азначитьНаЗаказToolStripMenuItem";
this.назначитьНаЗаказToolStripMenuItem.Size = new System.Drawing.Size(159, 24);
this.назначитьНаЗаказToolStripMenuItem.Text = "Назначить на заказ";
this.назначитьНаЗаказToolStripMenuItem.Click += new System.EventHandler(this.назначитьНаЗаказToolStripMenuItem_Click);
//
// отчётПоДолжностямToolStripMenuItem
//
this.отчётПоДолжностямToolStripMenuItem.Name = "отчётПоДолжностямToolStripMenuItem";
this.отчётПоДолжностямToolStripMenuItem.Size = new System.Drawing.Size(174, 24);
this.отчётПоДолжностямToolStripMenuItem.Text = "Отчёт по должностям";
this.отчётПоДолжностямToolStripMenuItem.Click += new System.EventHandler(this.отчётПоДолжностямToolStripMenuItem_Click);
//
// FormBrigadeMenu
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackgroundImage = global::ConstructionCompanyView.Properties.Resources.users_viewfinder_solid;
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.ClientSize = new System.Drawing.Size(645, 352);
this.Controls.Add(this.menuStrip1);
this.DoubleBuffered = true;
this.MainMenuStrip = this.menuStrip1;
this.Name = "FormBrigadeMenu";
this.Text = "Бригадир";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private MenuStrip menuStrip1;
private ToolStripMenuItem сотрудникиToolStripMenuItem;
private ToolStripMenuItem должностиToolStripMenuItem;
private ToolStripMenuItem назначитьНаЗаказToolStripMenuItem;
private ToolStripMenuItem отчётПоДолжностямToolStripMenuItem;
}
}

View File

@ -1,56 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ConstructionCompanyView
{
public partial class FormBrigadeMenu : Form
{
public FormBrigadeMenu()
{
InitializeComponent();
}
private void сотрудникиToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormEmployees));
if (service is FormEmployees form)
{
form.ShowDialog();
}
}
private void назначитьНаЗаказToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormEmployeeOrders));
if (service is FormEmployeeOrders form)
{
form.ShowDialog();
}
}
private void должностиToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormPositions));
if (service is FormPositions form)
{
form.ShowDialog();
}
}
private void отчётПоДолжностямToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormBrigadeReport));
if (service is FormBrigadeReport form)
{
form.ShowDialog();
}
}
}
}

View File

@ -1,63 +0,0 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -1,134 +0,0 @@
namespace ConstructionCompanyView
{
partial class FormBrigadeReport
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.buttonShow = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.dateTimePickerFrom = new System.Windows.Forms.DateTimePicker();
this.dateTimePickerTo = new System.Windows.Forms.DateTimePicker();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(0, 20);
this.label1.TabIndex = 19;
//
// buttonShow
//
this.buttonShow.Location = new System.Drawing.Point(12, 72);
this.buttonShow.Name = "buttonShow";
this.buttonShow.Size = new System.Drawing.Size(134, 29);
this.buttonShow.TabIndex = 18;
this.buttonShow.Text = "Посчитать";
this.buttonShow.UseVisualStyleBackColor = true;
this.buttonShow.Click += new System.EventHandler(this.buttonShow_Click);
//
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.Color.White;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 107);
this.dataGridView.MultiSelect = false;
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersVisible = false;
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dataGridView.Size = new System.Drawing.Size(680, 366);
this.dataGridView.TabIndex = 20;
//
// dateTimePickerFrom
//
this.dateTimePickerFrom.Location = new System.Drawing.Point(12, 39);
this.dateTimePickerFrom.Name = "dateTimePickerFrom";
this.dateTimePickerFrom.Size = new System.Drawing.Size(218, 27);
this.dateTimePickerFrom.TabIndex = 21;
//
// dateTimePickerTo
//
this.dateTimePickerTo.Location = new System.Drawing.Point(263, 39);
this.dateTimePickerTo.Name = "dateTimePickerTo";
this.dateTimePickerTo.Size = new System.Drawing.Size(222, 27);
this.dateTimePickerTo.TabIndex = 22;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 9);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(18, 20);
this.label2.TabIndex = 23;
this.label2.Text = "C";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(263, 9);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(29, 20);
this.label3.TabIndex = 24;
this.label3.Text = "По";
//
// FormBrigadeReport
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(704, 485);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.dateTimePickerTo);
this.Controls.Add(this.dateTimePickerFrom);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.label1);
this.Controls.Add(this.buttonShow);
this.Name = "FormBrigadeReport";
this.Text = "Отчёт по использованию материалов должностями с датой";
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label label1;
private Button buttonShow;
private DataGridView dataGridView;
private DateTimePicker dateTimePickerFrom;
private DateTimePicker dateTimePickerTo;
private Label label2;
private Label label3;
}
}

View File

@ -1,51 +0,0 @@
using ConstructionCompanyContracts.BusinessLogicContracts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ConstructionCompanyView
{
public partial class FormBrigadeReport : Form
{
public IPositionLogic _logic;
public FormBrigadeReport(IPositionLogic logic)
{
InitializeComponent();
_logic = logic;
}
private void buttonShow_Click(object sender, EventArgs e)
{
if (dateTimePickerFrom.Value.Date > dateTimePickerTo.Value.Date)
{
MessageBox.Show("Неверно выбраны даты!");
return;
}
try
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
var list = _logic.ReadPositionsAverage(dateTimePickerFrom.Value.Date, dateTimePickerTo.Value.Date).OrderBy(x => x.PositionId).ToList();
stopwatch.Stop();
MessageBox.Show(stopwatch.ElapsedMilliseconds.ToString(), "Результат среднего по должностям. Время:");
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["PositionId"].Visible = false;
dataGridView.Columns["PositionName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -1,60 +0,0 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,120 +0,0 @@
namespace ConstructionCompanyView
{
partial class FormEmployee
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonCreate = new System.Windows.Forms.Button();
this.textBoxName = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.comboBoxPosition = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(307, 117);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.TabIndex = 9;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// buttonCreate
//
this.buttonCreate.Location = new System.Drawing.Point(202, 117);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
this.buttonCreate.TabIndex = 8;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(135, 6);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(276, 27);
this.textBoxName.TabIndex = 7;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(42, 20);
this.label1.TabIndex = 6;
this.label1.Text = "ФИО";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 43);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(86, 20);
this.label2.TabIndex = 10;
this.label2.Text = "Должность";
//
// comboBoxPosition
//
this.comboBoxPosition.FormattingEnabled = true;
this.comboBoxPosition.Location = new System.Drawing.Point(135, 40);
this.comboBoxPosition.Name = "comboBoxPosition";
this.comboBoxPosition.Size = new System.Drawing.Size(276, 28);
this.comboBoxPosition.TabIndex = 11;
//
// FormEmployee
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(423, 165);
this.Controls.Add(this.comboBoxPosition);
this.Controls.Add(this.label2);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.label1);
this.Name = "FormEmployee";
this.Text = "Сотрудник";
this.Load += new System.EventHandler(this.FormEmployee_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button buttonCancel;
private Button buttonCreate;
private TextBox textBoxName;
private Label label1;
private Label label2;
private ComboBox comboBoxPosition;
}
}

View File

@ -1,110 +0,0 @@
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyContracts.SearchModels;
using ConstructionCompanyContracts.ViewModels;
using ConstructionCompanyPsqlImplement.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ConstructionCompanyView
{
public partial class FormEmployee : Form
{
private readonly ILogger _logger;
private readonly IPositionLogic _position;
private readonly IEmployeeLogic _employee;
private List<PositionViewModel>? _list;
private int? _id;
public int Id { set { _id = value; } }
public FormEmployee(ILogger<FormEmployee> logger, IPositionLogic position, IEmployeeLogic employee)
{
InitializeComponent();
_logger = logger;
_position = position;
_employee = employee;
}
private void FormEmployee_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка материалов для заказа");
_list = _position.ReadList(null);
if (_list != null)
{
comboBoxPosition.DisplayMember = "PositionName";
comboBoxPosition.ValueMember = "Id";
comboBoxPosition.DataSource = _list;
comboBoxPosition.SelectedItem = null;
}
if (_id.HasValue)
{
try
{
_logger.LogInformation("Получение материала");
var view = _employee.ReadElement(new EmployeeSearchModel { Id = _id.Value });
if (view != null)
{
textBoxName.Text = view.EmployeeName;
comboBoxPosition.SelectedValue = view.PositionID;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения материала");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxPosition.SelectedValue == null)
{
MessageBox.Show("Выбирете должность", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение материала");
try
{
var model = new EmployeeBindingModel
{
Id = _id ?? 0,
EmployeeName = textBoxName.Text,
PositionID = Convert.ToInt32(comboBoxPosition.SelectedValue)
};
var operationResult = _id.HasValue ? _employee.Update(model) : _employee.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -1,60 +0,0 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,121 +0,0 @@
namespace ConstructionCompanyView
{
partial class FormEmployeeOrder
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonCreate = new System.Windows.Forms.Button();
this.comboBoxOrder = new System.Windows.Forms.ComboBox();
this.comboBoxEmployee = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(296, 115);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.TabIndex = 13;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// buttonCreate
//
this.buttonCreate.Location = new System.Drawing.Point(142, 115);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
this.buttonCreate.TabIndex = 12;
this.buttonCreate.Text = "Отправить";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// comboBoxOrder
//
this.comboBoxOrder.FormattingEnabled = true;
this.comboBoxOrder.Location = new System.Drawing.Point(142, 9);
this.comboBoxOrder.Name = "comboBoxOrder";
this.comboBoxOrder.Size = new System.Drawing.Size(248, 28);
this.comboBoxOrder.TabIndex = 11;
//
// comboBoxEmployee
//
this.comboBoxEmployee.FormattingEnabled = true;
this.comboBoxEmployee.Location = new System.Drawing.Point(142, 55);
this.comboBoxEmployee.Name = "comboBoxEmployee";
this.comboBoxEmployee.Size = new System.Drawing.Size(248, 28);
this.comboBoxEmployee.TabIndex = 10;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 55);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(85, 20);
this.label2.TabIndex = 9;
this.label2.Text = "Сотрудник:";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(50, 20);
this.label1.TabIndex = 8;
this.label1.Text = "Заказ:";
//
// FormEmployeeOrder
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(436, 159);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.comboBoxOrder);
this.Controls.Add(this.comboBoxEmployee);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "FormEmployeeOrder";
this.Text = "Отправка на заказ";
this.Load += new System.EventHandler(this.FormEmployeeOrder_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button buttonCancel;
private Button buttonCreate;
private ComboBox comboBoxOrder;
private ComboBox comboBoxEmployee;
private Label label2;
private Label label1;
}
}

Some files were not shown because too many files have changed in this diff Show More