131 lines
4.3 KiB
C#
Raw Normal View History

using ZooContracts.BusinessLogicsContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZooContracts.BusinessLogicsContracts;
namespace ZooBusinessLogic.BusinessLogics
{
/// <summary>
/// Замена сотрудника
/// </summary>
public class EmployeeRoleImitationaLogic
{
private readonly IEmployeeLogic _employeeLogic;
private readonly IReserveLogic _ReserveLogic;
private readonly ICostLogic _CostLogic;
private readonly IRouteLogic _RouteLogic;
private readonly IRouteCostLogic _RouteCostLogic;
public EmployeeRoleImitationaLogic(IEmployeeLogic employeeLogic,
IReserveLogic ReserveLogic, ICostLogic CostLogic,
IRouteLogic RouteLogic, IRouteCostLogic RouteCostLogic)
{
_employeeLogic = employeeLogic;
_ReserveLogic = ReserveLogic;
_CostLogic = CostLogic;
_RouteLogic = RouteLogic;
_RouteCostLogic = RouteCostLogic;
}
private bool GenerateEmployeeData()
{
if (_employeeLogic.ReadList(null)?.Count != 0)
{
return false;
}
using (StreamReader sr = new("employees.txt"))
{
string? currentString;
while ((currentString = sr.ReadLine()) != null)
{
var employeeRecData = currentString.Split(',');
_employeeLogic.Create(new()
{
EmployeeEmail = employeeRecData[0],
EmployeePassword = employeeRecData[1],
EmployeeName = employeeRecData[2],
EmployeePhone = employeeRecData[3]
});
}
}
return true;
}
private bool GenerateReserveData()
{
if (_ReserveLogic.ReadList(null)?.Count != 0)
{
return false;
}
using (StreamReader sr = new("Reserves.txt"))
{
string? currentString;
while ((currentString = sr.ReadLine()) != null)
{
var ReserveRecData = currentString.Split(',');
_ReserveLogic.Create(new()
{
ReserveName = Convert.ToString(ReserveRecData[0]),
ReservePrice = Convert.ToDouble(ReserveRecData[1])
});
}
}
return true;
}
public bool GenerateCost()
{
if (_CostLogic.ReadList(null)?.Count != 0)
{
return false;
}
using (StreamReader sr = new("Costs.txt"))
{
string? currentString;
while ((currentString = sr.ReadLine()) != null)
{
var CostRecData = currentString.Split(',');
_CostLogic.Create(new()
{
CostName = Convert.ToString(CostRecData[0]),
Sum = Convert.ToDouble(CostRecData[1]),
Count = Convert.ToInt32(CostRecData[2]),
EmployeeId = Convert.ToInt32(CostRecData[3])
});
}
}
return true;
}
public bool GenerateRouteCost()
{
var CostList = _CostLogic.ReadList(null);
if (CostList == null)
{
return false;
}
if (CostList.Count == 0)
{
return false;
}
var RouteList = _RouteLogic.ReadList(null);
if (RouteList == null)
{
return false;
}
if (RouteList.Count == 0)
{
return false;
}
Random rnd = new Random();
for (int i = 0; i < 2; i++)
{
_RouteCostLogic.Create(new()
{
CostId = rnd.Next(0, CostList.Count),
RouteId = rnd.Next(0, RouteList.Count)
});
}
return true;
}
}
}