From c75ec10d8a632893e52921ff6dae270877028eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Sat, 8 Apr 2023 15:29:51 +0400 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D0=BB=D1=83=D1=88=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=BE=D0=BB=D0=B8=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomerRoleImitationLogic.cs | 140 ++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 CarService/CarServiceBusinessLogic/BusinessLogics/CustomerRoleImitationLogic.cs diff --git a/CarService/CarServiceBusinessLogic/BusinessLogics/CustomerRoleImitationLogic.cs b/CarService/CarServiceBusinessLogic/BusinessLogics/CustomerRoleImitationLogic.cs new file mode 100644 index 0000000..bf666d0 --- /dev/null +++ b/CarService/CarServiceBusinessLogic/BusinessLogics/CustomerRoleImitationLogic.cs @@ -0,0 +1,140 @@ +using CarServiceContracts.BusinessLogicsContracts; + +namespace CarServiceBusinessLogic.BusinessLogics +{ + /// + /// Заглушка для роли клиента + /// + public class CustomerRoleImitationLogic + { + private readonly ICustomerLogic _customerLogic; + private readonly IVehicleLogic _vehicleLogic; + private readonly IRepairRequestLogic _repairRequestLogic; + private readonly IWorkInRequestLogic _workInRequestLogic; + private readonly IWorkLogic _workLogic; + public CustomerRoleImitationLogic(ICustomerLogic customerLogic, IVehicleLogic vehicleLogic, IRepairRequestLogic repairRequestLogic, IWorkInRequestLogic workInRequestLogic, IWorkLogic workLogic) + { + _customerLogic = customerLogic; + _vehicleLogic = vehicleLogic; + _repairRequestLogic = repairRequestLogic; + _workInRequestLogic = workInRequestLogic; + _workLogic = workLogic; + } + private bool GenerateCustomerData() + { + if (_customerLogic.ReadList(null)?.Count != 0) + { + return false; + } + using (StreamReader sr = new("customers.txt")) + { + string? currentString; + while ((currentString = sr.ReadLine()) != null) + { + var customerRecData = currentString.Split(','); + _customerLogic.Create(new() + { + Login = customerRecData[0], + Password = customerRecData[1], + Name = customerRecData[2], + Surname = customerRecData[3] + }); + } + } + return true; + } + private bool GenerateVehicleData() + { + if (_vehicleLogic.ReadList(null)?.Count != 0) + { + return false; + } + using (StreamReader sr = new("vehicles.txt")) + { + string? currentString; + while ((currentString = sr.ReadLine()) != null) + { + var vehicleRecData = currentString.Split(','); + _vehicleLogic.Create(new() + { + Name = vehicleRecData[0], + Plate = vehicleRecData[1], + VIN = vehicleRecData[2], + CustomerId = Convert.ToInt32(vehicleRecData[4]) + }); + } + } + return true; + } + private bool GenerateRepairRequestData() + { + if (_repairRequestLogic.ReadList(null)?.Count != 0) + { + return false; + } + using (StreamReader sr = new("requests.txt")) + { + string? currentString; + while ((currentString = sr.ReadLine()) != null) + { + var repairRequestRecData = currentString.Split(','); + _repairRequestLogic.Create(new() + { + DateCreated = Convert.ToDateTime(repairRequestRecData[0]), + VehicleId = Convert.ToInt32(repairRequestRecData[1]) + }); + } + } + return true; + } + public bool GenerateRequestData() + { + if (!GenerateCustomerData()) + { + return false; + } + if (!GenerateVehicleData()) + { + return false; + } + if (!GenerateRepairRequestData()) + { + return false; + } + return true; + } + public bool GenerateWorksInRequest() + { + var WorksList = _workLogic.ReadList(null); + if (WorksList == null) + { + return false; + } + if (WorksList.Count == 0) + { + return false; + } + var RequestList = _repairRequestLogic.ReadList(null); + if (RequestList == null) + { + return false; + } + if (RequestList.Count == 0) + { + return false; + } + Random r = new(); + for (int i = 0; i < 2; i++) + { + _workInRequestLogic.Create(new() + { + RepairRequestId = r.Next(0, RequestList.Count), + WorkId = r.Next(0, WorksList.Count), + Count = r.Next(1, 2) + }); + } + return true; + + } + } +}