131 lines
3.2 KiB
C#
131 lines
3.2 KiB
C#
using SchoolContracts.BusinessLogicsContracts;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SchoolBusinessLogic.BusinessLogics
|
|
{
|
|
/// <summary>
|
|
/// Заглушка для роли сотрудника
|
|
/// </summary>
|
|
public class EmployeeRoleImitationaLogic
|
|
{
|
|
private readonly IEmployeeLogic _employeeLogic;
|
|
private readonly ILessonLogic _lessonLogic;
|
|
private readonly IExpenseLogic _ExpenseLogic;
|
|
private readonly ICircleLogic _circleLogic;
|
|
private readonly ICircleExpenseLogic _circleExpenseLogic;
|
|
|
|
public EmployeeRoleImitationaLogic(IEmployeeLogic employeeLogic,
|
|
ILessonLogic lessonLogic, IExpenseLogic ExpenseLogic,
|
|
ICircleLogic circleLogic, ICircleExpenseLogic circleExpenseLogic)
|
|
{
|
|
_employeeLogic = employeeLogic;
|
|
_lessonLogic = lessonLogic;
|
|
_ExpenseLogic = ExpenseLogic;
|
|
_circleLogic = circleLogic;
|
|
_circleExpenseLogic = circleExpenseLogic;
|
|
}
|
|
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 GenerateLessonData()
|
|
{
|
|
if(_lessonLogic.ReadList(null)?.Count != 0)
|
|
{
|
|
return false;
|
|
}
|
|
using (StreamReader sr = new("lessons.txt"))
|
|
{
|
|
string? currentString;
|
|
while ((currentString = sr.ReadLine()) != null)
|
|
{
|
|
var lessonRecData = currentString.Split(',');
|
|
_lessonLogic.Create(new()
|
|
{
|
|
LessonName = Convert.ToString(lessonRecData[0]),
|
|
LessonPrice = Convert.ToDouble(lessonRecData[1])
|
|
});
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
public bool GenerateExpense()
|
|
{
|
|
if (_ExpenseLogic.ReadList(null)?.Count != 0)
|
|
{
|
|
return false;
|
|
}
|
|
using (StreamReader sr = new("expenses.txt"))
|
|
{
|
|
string? currentString;
|
|
while ((currentString = sr.ReadLine()) != null)
|
|
{
|
|
var expenseRecData = currentString.Split(',');
|
|
_ExpenseLogic.Create(new()
|
|
{
|
|
ExpenseName = Convert.ToString(expenseRecData[0]),
|
|
Sum = Convert.ToDouble(expenseRecData[1]),
|
|
Count = Convert.ToInt32(expenseRecData[2]),
|
|
EmployeeId = Convert.ToInt32(expenseRecData[3])
|
|
});
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
public bool GenerateCircleExpense()
|
|
{
|
|
var ExpenseList = _ExpenseLogic.ReadList(null);
|
|
if (ExpenseList == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (ExpenseList.Count == 0)
|
|
{
|
|
return false;
|
|
}
|
|
var CircleList = _circleLogic.ReadList(null);
|
|
if (CircleList == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (CircleList.Count == 0)
|
|
{
|
|
return false;
|
|
}
|
|
Random rnd = new Random();
|
|
for (int i = 0; i < 2; i++)
|
|
{
|
|
_circleExpenseLogic.Create(new()
|
|
{
|
|
ExpenseId = rnd.Next(0, ExpenseList.Count),
|
|
CircleId = rnd.Next(0, CircleList.Count)
|
|
});
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|