initial commit
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Data.Entities;
|
||||
using Indotalent.Data.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Infrastructure.Database.Demo;
|
||||
|
||||
public static class BookingSeeder
|
||||
{
|
||||
public static async Task GenerateDataAsync(AppDbContext context)
|
||||
{
|
||||
if (await context.Booking.AnyAsync()) return;
|
||||
|
||||
var random = new Random();
|
||||
var bookingStatusValues = Enum.GetValues(typeof(BookingStatus)).Cast<BookingStatus>().ToList();
|
||||
var entityName = nameof(Booking);
|
||||
|
||||
var dateEnd = DateTime.Now;
|
||||
var dateStart = dateEnd.AddMonths(-12);
|
||||
|
||||
var bookingResources = await context.BookingResource
|
||||
.Select(x => x.Id)
|
||||
.ToListAsync();
|
||||
|
||||
var locations = await context.Warehouse
|
||||
.Where(x => x.SystemWarehouse == false)
|
||||
.Select(x => x.Name)
|
||||
.ToListAsync();
|
||||
|
||||
if (!bookingResources.Any() || !locations.Any()) return;
|
||||
|
||||
var subjects = new string[]
|
||||
{
|
||||
"General Medical Checkup",
|
||||
"Specialist Follow-up",
|
||||
"Routine Dental Cleaning",
|
||||
"Blood Extraction & Lab Test",
|
||||
"X-Ray / Diagnostic Imaging",
|
||||
"Physical Therapy Session",
|
||||
"Annual Vaccination",
|
||||
"Pediatric Well-Baby Visit",
|
||||
"Obstetric Ultrasound",
|
||||
"Cardiology ECG Check",
|
||||
"Dermatology Consultation",
|
||||
"Orthopedic Assessment",
|
||||
"Minor Surgical Procedure",
|
||||
"Telemedicine Consultation",
|
||||
"Pre-Employment Medical Exam"
|
||||
};
|
||||
|
||||
for (DateTime date = dateStart; date < dateEnd; date = date.AddMonths(1))
|
||||
{
|
||||
DateTime[] transactionDates = GenerateRandomDays(date.Year, date.Month, 25);
|
||||
foreach (DateTime transDate in transactionDates)
|
||||
{
|
||||
int hourStart = random.Next(8, 18);
|
||||
DateTime startTime = transDate.Date.AddHours(hourStart);
|
||||
|
||||
var autoNo = await context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/"
|
||||
);
|
||||
|
||||
var booking = new Booking
|
||||
{
|
||||
Subject = $"{subjects[random.Next(subjects.Length)]} - {autoNo}",
|
||||
AutoNumber = autoNo,
|
||||
StartTime = startTime,
|
||||
EndTime = startTime.AddHours(random.Next(1, 3)),
|
||||
BookingResourceId = GetRandomValue(bookingResources, random),
|
||||
Status = bookingStatusValues[random.Next(bookingStatusValues.Count)],
|
||||
Location = GetRandomValue(locations, random)
|
||||
};
|
||||
|
||||
await context.Booking.AddAsync(booking);
|
||||
}
|
||||
}
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private static DateTime[] GenerateRandomDays(int year, int month, int count)
|
||||
{
|
||||
var random = new Random();
|
||||
int daysInMonthCount = DateTime.DaysInMonth(year, month);
|
||||
return Enumerable.Range(1, count)
|
||||
.Select(_ => new DateTime(year, month, random.Next(1, daysInMonthCount + 1)))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private static T GetRandomValue<T>(List<T> list, Random random)
|
||||
{
|
||||
return list[random.Next(list.Count)];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user