You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

70 lines
3.1 KiB

using BlazorFluentUI.Models;
namespace BlazorFluentUI.Services
{
public class EmployeeService
{
private List<Employee> _fixedSample;
Random _random = new Random();
string[] _firstNames = new[] { "John", "Jane", "Michael", "Emily", "Robert", "Linda", "William", "Jessica", "David", "Sarah" };
string[] _lastNames = new[] { "Smith", "Johnson", "Brown", "Williams", "Jones", "Garcia", "Miller", "Davis", "Martinez", "Hernandez" };
string[] _jobs = new[] { "Developer", "Designer", "Manager", "Analyst", "Consultant", "Administrator", "Engineer", "Specialist", "Technician", "Coordinator" };
string[] _titles = new[] { "Junior", "Mid", "Senior", "Lead", "Chief" };
string[] _cities = new[] { "New York", "Los Angeles", "Chicago", "Houston", "Phoenix", "Philadelphia", "San Antonio", "San Diego", "Dallas", "San Jose" };
string[] _regions = new[] { "NY", "CA", "IL", "TX", "AZ", "PA", "TX", "CA", "TX", "CA" };
string[] _counties = new[] { "USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA" };
public EmployeeService()
{
_fixedSample = GenerateEmployData(100);
}
public List<Employee> GetEmployeeData(int count)
{
return GenerateEmployData(count).ToList();
}
public async Task<List<Employee>> GetEmployeeDataAsync(int count)
{
await Task.Delay(count * 10);
return GenerateEmployData(count).ToList();
}
public List<Employee> GetFixedEmployeeData()
{
return _fixedSample;
}
private List<Employee> GenerateEmployData(int count)
{
var employees = new List<Employee>();
for (int i = 0; i < count; i++)
{
var employee = new Employee
{
ID = i + 1,
Photo = $"https://randomuser.me/api/portraits/med/{(i % 2 == 0 ? "men" : "women")}/{i}.jpg",
FirstName = _firstNames[_random.Next(_firstNames.Length)],
LastName = _lastNames[_random.Next(_lastNames.Length)],
Job = _jobs[_random.Next(_jobs.Length)],
Title = _titles[_random.Next(_titles.Length)],
BirthDate = new DateTime(_random.Next(1950, 2000), _random.Next(1, 13), _random.Next(1, 29)),
HireDate = DateTime.Today.AddDays(-_random.Next(1, 3650)),
Address = $"{_random.Next(1, 9999)} Main St",
City = _cities[_random.Next(_cities.Length)],
Region = _regions[_random.Next(_regions.Length)],
PostalCode = $"{_random.Next(10000, 99999)}",
Country = _counties[_random.Next(_counties.Length)],
Phone = $"{_random.Next(100, 999)}-555-{_random.Next(1000, 9999)}",
Extension = $"{_random.Next(100, 9999)}",
Notes = "Generated demo data"
};
employees.Add(employee);
}
return employees;
}
}
}