diff --git a/CarService/CarServiceBusinessLogic/BusinessLogics/CustomerRoleImitationLogic.cs b/CarService/CarServiceBusinessLogic/BusinessLogics/CustomerRoleImitationLogic.cs index bf666d0..d4b0437 100644 --- a/CarService/CarServiceBusinessLogic/BusinessLogics/CustomerRoleImitationLogic.cs +++ b/CarService/CarServiceBusinessLogic/BusinessLogics/CustomerRoleImitationLogic.cs @@ -12,13 +12,15 @@ namespace CarServiceBusinessLogic.BusinessLogics private readonly IRepairRequestLogic _repairRequestLogic; private readonly IWorkInRequestLogic _workInRequestLogic; private readonly IWorkLogic _workLogic; - public CustomerRoleImitationLogic(ICustomerLogic customerLogic, IVehicleLogic vehicleLogic, IRepairRequestLogic repairRequestLogic, IWorkInRequestLogic workInRequestLogic, 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() { @@ -134,7 +136,31 @@ namespace CarServiceBusinessLogic.BusinessLogics }); } 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 paidWorkId = r.Next(0, WorksInRequestList.Count);//определяем, какую работу оплачиваем + bool payFullPrice = Convert.ToBoolean(r.Next(0, 1));//определяем, оплачиваем заявку полностью или наполовину + _workPaymentLogic.Create(new() + { + DatePayment = DateTime.Now, + Sum = payFullPrice ? WorksInRequestList[paidWorkId].Cost : WorksInRequestList[paidWorkId].Cost / 2, + WorkInRequestId = paidWorkId + }); + } + return true; } } }