PIbd-23_Abazov_A.A._Constru.../ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/RandomGeneratorLogic.cs

88 lines
3.2 KiB
C#
Raw Normal View History

2023-04-10 14:24:22 +04:00
using ConstructionCompanyContracts.BindingModels;
using ConstructionCompanyContracts.BusinessLogicContracts;
using ConstructionCompanyDataModels.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConstructionCompanyBusinessLogic.BusinessLogics
{
public class RandomGeneratorLogic : IRandomGeneratorLogic
{
private readonly IMaterialLogic _material;
private readonly IEmployeeLogic _employee;
private readonly IPositionLogic _position;
private readonly IOrderLogic _order;
private readonly IMaterialOrderLogic _materialOrder;
private readonly IEmployeeOrderLogic _employeeOrder;
public RandomGeneratorLogic(IMaterialLogic material, IEmployeeLogic employee, IPositionLogic position, IOrderLogic order, IMaterialOrderLogic materialOrder, IEmployeeOrderLogic employeeOrder)
{
_material = material;
_employee = employee;
_position = position;
_order = order;
_materialOrder = materialOrder;
_employeeOrder = employeeOrder;
}
public void GenerateEmployees()
{
2023-04-21 19:48:18 +04:00
for (int i = 0; i < 400; i++)
2023-04-10 14:24:22 +04:00
{
_employee.Create(new EmployeeBindingModel { EmployeeName = "testEmp", PositionID = 1 });
}
}
public void GenerateEmployeesOrders()
{
2023-04-21 19:48:18 +04:00
for (int i = 0; i < 2000; i++)
2023-04-10 14:24:22 +04:00
{
2023-04-21 19:48:18 +04:00
Random rand = new Random();
int emp = rand.Next(1, 600);
int ord = rand.Next(1, 2000);
if (_employeeOrder.ReadList(null)?.FirstOrDefault(x => x.OrderId == ord && x.EmployeeId == emp) != null) continue;
_employeeOrder.Create(new EmployeeOrderBindingModel { EmployeeId = emp, OrderId = ord});
2023-04-10 14:24:22 +04:00
}
}
public void GenerateMaterialOrders()
{
2023-04-21 19:48:18 +04:00
for (int i = 0; i < 50; i++)
2023-04-10 14:24:22 +04:00
{
2023-04-21 19:48:18 +04:00
Random rand = new Random();
int mat = rand.Next(1, 10);
int ord = rand.Next(1, 200);
if (_materialOrder.ReadList(null)?.FirstOrDefault(x => x.OrderId == ord && x.MaterialId == mat) != null) continue;
_materialOrder.Create(new MaterialOrderBindingModel { MaterialId = mat, OrderId = ord, Quantity = 1});
2023-04-10 14:24:22 +04:00
}
}
public void GenerateMaterials()
{
2023-04-21 19:48:18 +04:00
for (int i = 0; i < 1000; i++)
2023-04-10 14:24:22 +04:00
{
_material.Create(new MaterialBindingModel { MaterialName = "testMat", Quantity = 2000 });
}
}
public void GenerateOrders()
{
for (int i = 0; i < 2000; i++)
{
_order.CreateOrder(new OrderBindingModel { Description = "snfjknfjksfns", Adress = "dsdsdssd", Price=20000, Status=OrderStatus.Неизвестен, CustomerNumber="+7838347475"});
}
}
public void GeneratePositions()
{
for (int i = 0; i < 15; i++)
{
_position.Create(new PositionBindingModel { PositionName = "testPos", Salary = 20000 });
}
}
}
}