using JobsMedical.Web.Data; using JobsMedical.Web.Models; using JobsMedical.Web.Services; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.EntityFrameworkCore; namespace JobsMedical.Web.Pages; public class IndexModel : PageModel { private readonly AppDbContext _db; private readonly RecommendationService _recs; private readonly InterestService _interest; public IndexModel(AppDbContext db, RecommendationService recs, InterestService interest) { _db = db; _recs = recs; _interest = interest; } public List Recommendations { get; private set; } = new(); public bool HasPersonalization { get; private set; } public List LatestShifts { get; private set; } = new(); public List LatestJobs { get; private set; } = new(); public List Cities { get; private set; } = new(); public List Roles { get; private set; } = new(); public int OpenShiftCount { get; private set; } public int FacilityCount { get; private set; } public int CityCount { get; private set; } public async Task OnGetAsync() { var today = DateOnly.FromDateTime(DateTime.UtcNow); Recommendations = await _recs.GetForVisitorAsync(6); // "Personalized" = we actually used a signal (prefs or behavior), not just cold-start freshness. HasPersonalization = (await _interest.GetPreferencesAsync())?.HasAny == true || (await _interest.RecentEventsAsync(1)).Count > 0; LatestShifts = await _db.Shifts .Include(s => s.Facility).ThenInclude(f => f.City) .Include(s => s.Role) .Where(s => s.Status == ShiftStatus.Open && s.Date >= today) .OrderBy(s => s.Date).ThenBy(s => s.StartTime) .Take(6) .ToListAsync(); LatestJobs = await _db.JobOpenings .Include(j => j.Facility).ThenInclude(f => f.City) .Include(j => j.Facility).ThenInclude(f => f.District) .Include(j => j.Role) .Where(j => j.Status == ShiftStatus.Open && j.CreatedAt >= JobsMedical.Web.Services.Scraping.ListingPolicy.JobCutoffUtc) .OrderByDescending(j => j.CreatedAt) .Take(3) .ToListAsync(); Cities = await _db.Cities.Where(c => c.IsActive).OrderBy(c => c.Name).ToListAsync(); Roles = await _db.Roles.Where(r => r.IsActive).OrderBy(r => r.SortOrder).ToListAsync(); OpenShiftCount = await _db.Shifts.CountAsync(s => s.Status == ShiftStatus.Open && s.Date >= today); FacilityCount = await _db.Facilities.CountAsync(); CityCount = await _db.Cities.CountAsync(c => c.IsActive); } }