69 lines
2.8 KiB
C#
69 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Faker;
|
|
using Renis.Repositories;
|
|
namespace renis_backend.Services.Users
|
|
{
|
|
public class UserService : IUserService
|
|
{
|
|
private readonly ILogger<UserService> _logger;
|
|
private readonly IUserRepository _userRepository;
|
|
public async Task<string> GenerateUser()
|
|
{
|
|
try
|
|
{
|
|
|
|
string firstName = russianFirstNames[random.Next(0, russianFirstNames.Length)];
|
|
string lastName = russianLastNames[random.Next(0, russianLastNames.Length)];
|
|
string patronymic = russianPatronymics[random.Next(0, russianPatronymics.Length)];
|
|
string name = $"{lastName} {firstName} {patronymic}";
|
|
string phone = GenerateRussianPhoneNumber();
|
|
string password = new string(Enumerable.Repeat("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 10).Select(c => c[random.Next(c.Length)]).ToArray());
|
|
|
|
|
|
var user = new User
|
|
{
|
|
Name = name,
|
|
Phone = GenerateRussianPhoneNumber(),
|
|
Password = password
|
|
};
|
|
await _userRepository.AddUser(user);
|
|
return user.Phone;
|
|
}
|
|
}
|
|
|
|
private static Random random = new Random();
|
|
private static string[] russianFirstNames = new string[]
|
|
{
|
|
"Иван", "Петр", "Алексей", "Дмитрий", "Николай", "Сергей", "Александр", "Михаил", "Андрей", "Владимир"
|
|
};
|
|
|
|
private static string[] russianLastNames = new string[]
|
|
{
|
|
"Иванов", "Петров", "Сидоров", "Кузнецов", "Попов", "Смирнов", "Николаев", "Зайцев", "Павлов", "Михайлов"
|
|
};
|
|
|
|
private static string[] russianPatronymics = new string[]
|
|
{
|
|
"Иванович", "Петрович", "Алексеевич", "Дмитриевич", "Николаевич", "Сергеевич", "Александрович", "Михайлович", "Андреевич", "Владимирович"
|
|
};
|
|
|
|
private static string[] russianPhonePrefixes = new string[]
|
|
{
|
|
"+7", "+375", "+380", "+7"
|
|
};
|
|
|
|
private static string GenerateRussianPhoneNumber()
|
|
{
|
|
string prefix = russianPhonePrefixes[random.Next(0, russianPhonePrefixes.Length)];
|
|
string number = new string(Enumerable.Repeat("0123456789", 10).Select(c => c[random.Next(c.Length)]).ToArray());
|
|
return $"{prefix}{number}";
|
|
}
|
|
|
|
|
|
}
|
|
}
|