PIbd-21_Anisin_R.S._CourseW.../TravelAgency/TravelAgencyWebApp/SeedingService.cs
2024-05-30 03:40:26 +04:00

110 lines
4.8 KiB
C#

using DocumentFormat.OpenXml.Bibliography;
using System.Drawing;
using TravelAgencyBusinessLogic.BusinessLogics;
using TravelAgencyContracts.BindingModels;
using TravelAgencyContracts.BusinessLogicsContracts;
using TravelAgencyContracts.SearchModels;
using TravelAgencyContracts.ViewModels;
using TravelAgencyDatabaseImplement.Models;
using TravelAgencyDataModels.Models;
namespace TravelAgencyWebApp
{
public class SeedingService
{
private readonly IGuideLogic _guideLogic;
private readonly ITripLogic _tripLogic;
private readonly IPlaceLogic _placeLogic;
public SeedingService(IGuideLogic guideLogic, ITripLogic tripLogic, IPlaceLogic placeLogic)
{
_guideLogic = guideLogic;
_tripLogic = tripLogic;
_placeLogic = placeLogic;
}
public void SeedGuarantor()
{
if (_guideLogic.ReadList(null) == null || _guideLogic.ReadList(null)?.ToList().Count < 1)
{
string[] domains = { "gmail.com", "yahoo.com", "hotmail.com", "outlook.com" };
string[] prefixes = { "ivan", "pavel", "", "anna", "sergei", "vasili" };
string[] firstNames = { "Иван", "Петр", "Алексей" };
string[] lastNames = { "Иванов", "Петров", "Сидоров" };
string[] middleNames = { "Иванович", "Петрович", "Алексеевич" };
Random random = new Random();
for (int i = 0; i < 10; i++)
{
string areaCode = random.Next(100, 1000).ToString();
string firstPart = random.Next(100, 1000).ToString();
string secondPart = random.Next(1000, 10000).ToString();
string randomPrefix = prefixes[random.Next(prefixes.Length)];
string randomDomain = domains[random.Next(domains.Length)];
string firstName = firstNames[random.Next(firstNames.Length)];
string lastName = lastNames[random.Next(lastNames.Length)];
string middleName = middleNames[random.Next(middleNames.Length)];
_guideLogic.Create(new GuideBindingModel
{
GuideFIO = $"{lastName} {firstName} {middleName}",
Email = $"{randomPrefix}{i}@{randomDomain}",
PhoneNumber = $"+7 ({areaCode}) {firstPart}-{secondPart}"
});
}
}
if (_placeLogic.ReadList(null) == null || _placeLogic.ReadList(null)?.ToList().Count < 1)
{
string[] streets = { "Цветной бульвар", "Ленинградский проспект", "Тверская улица", "Пресненская набережная", "Садовая улица" };
string[] cities = { "Москва", "Санкт-Петербург", "Новосибирск", "Екатеринбург" };
Random random = new Random();
for (int i = 0; i < 10; i++)
{
string street = streets[random.Next(streets.Length)];
string city = cities[random.Next(cities.Length)];
int houseNumber = random.Next(1, 100);
_placeLogic.Create(new PlaceBindingModel
{
PlaceName = $"Место {i+1}",
PlaceAddress = $"{city}, {street}, {houseNumber}"
});
}
}
if (_tripLogic.ReadList(null) == null || _tripLogic.ReadList(null)?.ToList().Count < 1)
{
var guides = _guideLogic.ReadList(null);
var places = _placeLogic.ReadList(null);
Random random = new Random();
for (int i = 0; i < 10; i++)
{
int year = random.Next(2024, 2026);
int month = random.Next(1, 13);
int day = random.Next(1, 29);
int guideId = guides[random.Next(0, guides.Count)].Id;
Dictionary<int, IPlaceModel> tripPlaces = new Dictionary<int, IPlaceModel>();
foreach(var place in places)
{
if (random.Next(0, 2) == 1)
{
tripPlaces.Add(place.Id, place);
}
}
_tripLogic.Create(new TripBindingModel
{
TripName = $"Поездка {i}",
TripDate = new DateTime(year, month, day),
GuideId = guideId,
TripPlaces = tripPlaces
});
}
}
}
}
}