82 lines
3.9 KiB
C#
82 lines
3.9 KiB
C#
using Indotalent.ConfigBackEnd.Extensions;
|
|
using Indotalent.Data.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Indotalent.Infrastructure.Database.Demo;
|
|
|
|
public static class VendorSeeder
|
|
{
|
|
public static async Task GenerateDataAsync(AppDbContext context)
|
|
{
|
|
if (await context.Vendor.AnyAsync()) return;
|
|
|
|
var groups = await context.VendorGroup.Select(x => x.Id).ToArrayAsync();
|
|
var categories = await context.VendorCategory.Select(x => x.Id).ToArrayAsync();
|
|
|
|
var cities = new string[] { "New York", "Los Angeles", "Chicago", "Houston", "Phoenix", "Philadelphia", "Miami", "San Francisco", "Seattle", "Austin" };
|
|
var streets = new string[] { "Broadway", "Main Street", "Sunset Blvd", "Fifth Avenue", "Market Street", "Peachtree Street", "Washington Blvd", "Wall Street", "Cedar Road", "Oak Street" };
|
|
var states = new string[] { "NY", "CA", "IL", "TX", "AZ", "PA", "FL", "GA", "WA", "MA" };
|
|
var zipCodes = new string[] { "10001", "90210", "60601", "77001", "85001", "19101", "33101", "94102", "98101", "73301" };
|
|
var phoneNumbers = new string[] { "212-555-0199", "310-555-0188", "312-555-0177", "713-555-0166", "602-555-0155", "305-555-0144" };
|
|
var emails = new string[] { "sales@wellness-us.com", "info@fitness-pro.net", "contact@spa-direct.com", "support@organic-supplies.us", "wholesale@gym-factory.com" };
|
|
|
|
var random = new Random();
|
|
var entityName = nameof(Vendor);
|
|
|
|
var vendors = new List<Vendor>
|
|
{
|
|
new Vendor { Name = "Pacific Coast Skincare" },
|
|
new Vendor { Name = "Midwest Gym Equipment" },
|
|
new Vendor { Name = "Evergreen Holistic Labs" },
|
|
new Vendor { Name = "Atlantic Spa & Beauty" },
|
|
new Vendor { Name = "Sunshine State Nutriments" },
|
|
new Vendor { Name = "Mountain Peak Fitness" },
|
|
new Vendor { Name = "Empire State Linen" },
|
|
new Vendor { Name = "Silicon Valley Wellness Tech" },
|
|
new Vendor { Name = "Lone Star Spa Supplies" },
|
|
new Vendor { Name = "Golden Gate Aromatherapy" },
|
|
new Vendor { Name = "Liberty Fitness Machines" },
|
|
new Vendor { Name = "Canyon Creek Supplements" },
|
|
new Vendor { Name = "Gulf Coast Wellness Group" },
|
|
new Vendor { Name = "Great Lakes Spa Textiles" },
|
|
new Vendor { Name = "Blue Ridge Herbal Remedies" },
|
|
new Vendor { Name = "Windy City Gym Solutions" },
|
|
new Vendor { Name = "Desert Oasis Wellness" },
|
|
new Vendor { Name = "Big Apple Fitness Distribution" },
|
|
new Vendor { Name = "Cascade Organic Oils" },
|
|
new Vendor { Name = "National Wellness Marketing" }
|
|
};
|
|
|
|
foreach (var vendor in vendors)
|
|
{
|
|
var autoNo = await context.GenerateAutoNumberAsync(
|
|
entityName: entityName,
|
|
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/"
|
|
);
|
|
|
|
vendor.AutoNumber = autoNo;
|
|
vendor.VendorGroupId = GetRandomValue(groups, random);
|
|
vendor.VendorCategoryId = GetRandomValue(categories, random);
|
|
vendor.City = GetRandomString(cities, random);
|
|
vendor.Street = GetRandomString(streets, random);
|
|
vendor.State = GetRandomString(states, random);
|
|
vendor.ZipCode = GetRandomString(zipCodes, random);
|
|
vendor.PhoneNumber = GetRandomString(phoneNumbers, random);
|
|
vendor.EmailAddress = GetRandomString(emails, random);
|
|
|
|
await context.Vendor.AddAsync(vendor);
|
|
}
|
|
|
|
await context.SaveChangesAsync();
|
|
}
|
|
|
|
private static T GetRandomValue<T>(T[] array, Random random)
|
|
{
|
|
return array[random.Next(array.Length)];
|
|
}
|
|
|
|
private static string GetRandomString(string[] array, Random random)
|
|
{
|
|
return array[random.Next(array.Length)];
|
|
}
|
|
} |