using CarServiceContracts.BusinessLogicsContracts; namespace CarServiceBusinessLogic.BusinessLogics { /// /// Заглушка для роли клиента /// public class CustomerRoleImitationLogic : ICustomerRoleImitationLogic { private readonly ICustomerLogic _customerLogic; private readonly IVehicleLogic _vehicleLogic; private readonly IRepairRequestLogic _repairRequestLogic; private readonly IWorkInRequestLogic _workInRequestLogic; private readonly IWorkLogic _workLogic; private readonly IWorkPaymentLogic _workPaymentLogic; public CustomerRoleImitationLogic(ICustomerLogic customerLogic, IVehicleLogic vehicleLogic, IRepairRequestLogic repairRequestLogic, IWorkInRequestLogic workInRequestLogic, IWorkLogic workLogic, IWorkPaymentLogic workPaymentLogic) { _customerLogic = customerLogic; _vehicleLogic = vehicleLogic; _repairRequestLogic = repairRequestLogic; _workInRequestLogic = workInRequestLogic; _workLogic = workLogic; _workPaymentLogic = workPaymentLogic; } 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[3]) }); } } 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++) { int RRId = RequestList[r.Next(RequestList.Count)].Id; int WId = WorksList[r.Next(WorksList.Count)].Id; _workInRequestLogic.Create(new() { RepairRequestId = RRId, WorkId = WId, Count = 1 }); } return true; } public bool GeneratePayments() { var WorksInRequestList = _workInRequestLogic.ReadList(null); if (WorksInRequestList == null) { return false; } if (WorksInRequestList.Count == 0) { return false; } Random r = new(); for (int i = 0; i < 2; i++) { int work = r.Next(0, WorksInRequestList.Count); int paidWorkId = WorksInRequestList[work].Id;//определяем, какую работу оплачиваем bool payFullPrice = Convert.ToBoolean(r.Next(0, 1));//определяем, оплачиваем заявку полностью или наполовину _workPaymentLogic.Create(new() { DatePayment = DateTime.Now, Sum = payFullPrice ? WorksInRequestList[work].Cost : WorksInRequestList[work].Cost / 2, WorkInRequestId = paidWorkId }); } return true; } } }