2023-04-08 15:29:51 +04:00
|
|
|
|
using CarServiceContracts.BusinessLogicsContracts;
|
|
|
|
|
|
|
|
|
|
namespace CarServiceBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Заглушка для роли клиента
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class CustomerRoleImitationLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly ICustomerLogic _customerLogic;
|
|
|
|
|
private readonly IVehicleLogic _vehicleLogic;
|
|
|
|
|
private readonly IRepairRequestLogic _repairRequestLogic;
|
|
|
|
|
private readonly IWorkInRequestLogic _workInRequestLogic;
|
|
|
|
|
private readonly IWorkLogic _workLogic;
|
2023-04-08 15:38:52 +04:00
|
|
|
|
private readonly IWorkPaymentLogic _workPaymentLogic;
|
|
|
|
|
public CustomerRoleImitationLogic(ICustomerLogic customerLogic, IVehicleLogic vehicleLogic, IRepairRequestLogic repairRequestLogic, IWorkInRequestLogic workInRequestLogic, IWorkLogic workLogic, IWorkPaymentLogic workPaymentLogic)
|
2023-04-08 15:29:51 +04:00
|
|
|
|
{
|
|
|
|
|
_customerLogic = customerLogic;
|
|
|
|
|
_vehicleLogic = vehicleLogic;
|
|
|
|
|
_repairRequestLogic = repairRequestLogic;
|
|
|
|
|
_workInRequestLogic = workInRequestLogic;
|
|
|
|
|
_workLogic = workLogic;
|
2023-04-08 15:38:52 +04:00
|
|
|
|
_workPaymentLogic = workPaymentLogic;
|
2023-04-08 15:29:51 +04:00
|
|
|
|
}
|
|
|
|
|
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;
|
2023-04-08 15:38:52 +04:00
|
|
|
|
}
|
|
|
|
|
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;
|
2023-04-08 15:29:51 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|