Files
hamkadr/src/JobsMedical.Web/Pages/Facilities/Index.cshtml.cs
T
soroush.asadi 845d0c9013
CI/CD / CI · dotnet build (push) Successful in 1m55s
CI/CD / Deploy · hamkadr (push) Successful in 1m18s
Show job counts, not shifts-only, on public pages
The platform has ~1600 open استخدام but only ~4 dated شیفت (the VPN-free sources are hiring
boards, not shift channels), so the shifts-only counters read misleadingly low:
- Homepage stat pill «۴ شیفت باز» -> «موقعیت استخدام» (open job count).
- Facility cards «۰ شیفت باز» -> «N آگهی فعال» = open shifts + open (fresh) jobs, so a facility
  that is hiring no longer reads zero.
Also hide the «نامشخص / ثبت نشده» placeholder from the facilities list and sort active
facilities (then verified, then name) first, so real hiring centers surface.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 16:21:50 +03:30

46 lines
2.0 KiB
C#

using JobsMedical.Web.Data;
using JobsMedical.Web.Models;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
namespace JobsMedical.Web.Pages.Facilities;
public class IndexModel : PageModel
{
private readonly AppDbContext _db;
public IndexModel(AppDbContext db) => _db = db;
public record FacilityRow(Facility Facility, int OpenListings);
public List<FacilityRow> Rows { get; private set; } = new();
// The shared placeholder for unnamed aggregated ads is not a real, browseable facility.
private const string PlaceholderName = "نامشخص / ثبت نشده";
public async Task OnGetAsync()
{
var today = DateOnly.FromDateTime(DateTime.UtcNow);
var jobCutoff = JobsMedical.Web.Services.Scraping.ListingPolicy.JobCutoffUtc;
var facilities = await _db.Facilities.Include(f => f.City)
.Where(f => f.Name != PlaceholderName).ToListAsync();
// "Active listings" = open shifts + open (fresh) job openings — a facility that is hiring
// shouldn't read «۰ شیفت باز» just because it posted a job rather than a dated shift.
var shiftCounts = await _db.Shifts
.Where(s => s.Status == ShiftStatus.Open && s.Date >= today)
.GroupBy(s => s.FacilityId).Select(g => new { g.Key, C = g.Count() })
.ToDictionaryAsync(x => x.Key, x => x.C);
var jobCounts = await _db.JobOpenings
.Where(j => j.Status == ShiftStatus.Open && j.CreatedAt >= jobCutoff)
.GroupBy(j => j.FacilityId).Select(g => new { g.Key, C = g.Count() })
.ToDictionaryAsync(x => x.Key, x => x.C);
Rows = facilities
.Select(f => new FacilityRow(f, shiftCounts.GetValueOrDefault(f.Id) + jobCounts.GetValueOrDefault(f.Id)))
.OrderByDescending(r => r.OpenListings) // active facilities first
.ThenByDescending(r => r.Facility.IsVerified)
.ThenBy(r => r.Facility.Name)
.ToList();
}
}