2026-06-03 01:43:55 +03:30
|
|
|
using JobsMedical.Web.Data;
|
|
|
|
|
using JobsMedical.Web.Models;
|
|
|
|
|
using JobsMedical.Web.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
namespace JobsMedical.Web.Pages.Jobs;
|
|
|
|
|
|
|
|
|
|
public class IndexModel : PageModel
|
|
|
|
|
{
|
|
|
|
|
private readonly AppDbContext _db;
|
|
|
|
|
public IndexModel(AppDbContext db) => _db = db;
|
|
|
|
|
|
|
|
|
|
[BindProperty(SupportsGet = true)] public int? CityId { get; set; }
|
|
|
|
|
[BindProperty(SupportsGet = true)] public int? DistrictId { get; set; }
|
|
|
|
|
[BindProperty(SupportsGet = true)] public int? RoleId { get; set; }
|
|
|
|
|
[BindProperty(SupportsGet = true)] public EmploymentType? EmploymentType { get; set; }
|
2026-06-04 00:19:32 +03:30
|
|
|
[BindProperty(SupportsGet = true)] public Gender? GenderFilter { get; set; }
|
2026-06-03 01:43:55 +03:30
|
|
|
[BindProperty(SupportsGet = true)] public double? Lat { get; set; }
|
|
|
|
|
[BindProperty(SupportsGet = true)] public double? Lng { get; set; }
|
|
|
|
|
|
2026-06-19 14:03:57 +03:30
|
|
|
// Pretty-URL segments (/استخدام/{roleSlug}/{citySlug?}); resolved to RoleId/CityId below.
|
|
|
|
|
[BindProperty(SupportsGet = true)] public string? RoleSlug { get; set; }
|
|
|
|
|
[BindProperty(SupportsGet = true)] public string? CitySlug { get; set; }
|
|
|
|
|
|
2026-06-03 01:43:55 +03:30
|
|
|
public bool NearMeActive => Lat is not null && Lng is not null;
|
|
|
|
|
|
|
|
|
|
public List<JobOpening> Results { get; private set; } = new();
|
|
|
|
|
public List<City> Cities { get; private set; } = new();
|
|
|
|
|
public List<District> Districts { get; private set; } = new();
|
|
|
|
|
public List<Role> Roles { get; private set; } = new();
|
|
|
|
|
|
2026-06-19 14:03:57 +03:30
|
|
|
/// <summary>Dynamic page heading/H1 + title, set from the active role/city for SEO.</summary>
|
|
|
|
|
public string PageHeading { get; private set; } = "موقعیتهای استخدامی";
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> OnGetAsync()
|
2026-06-03 01:43:55 +03:30
|
|
|
{
|
|
|
|
|
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();
|
2026-06-19 14:03:57 +03:30
|
|
|
|
|
|
|
|
// Pretty-URL landing: resolve slugs → filters. A slug matching nothing is a 404 (don't
|
|
|
|
|
// render a thin page under a junk URL).
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(RoleSlug))
|
|
|
|
|
{
|
|
|
|
|
var role = Roles.FirstOrDefault(r => SeoSlug.Matches(r.Name, RoleSlug));
|
|
|
|
|
if (role is null) return NotFound();
|
|
|
|
|
RoleId = role.Id;
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(CitySlug))
|
|
|
|
|
{
|
|
|
|
|
var city = Cities.FirstOrDefault(c => SeoSlug.Matches(c.Name, CitySlug));
|
|
|
|
|
if (city is null) return NotFound();
|
|
|
|
|
CityId = city.Id;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-03 01:43:55 +03:30
|
|
|
Districts = await _db.Districts
|
|
|
|
|
.Where(d => d.IsActive && (CityId == null || d.CityId == CityId))
|
|
|
|
|
.OrderBy(d => d.Name).ToListAsync();
|
|
|
|
|
|
|
|
|
|
var q = _db.JobOpenings
|
|
|
|
|
.Include(j => j.Facility).ThenInclude(f => f.City)
|
|
|
|
|
.Include(j => j.Facility).ThenInclude(f => f.District)
|
|
|
|
|
.Include(j => j.Role)
|
2026-06-04 09:57:06 +03:30
|
|
|
.Where(j => j.Status == ShiftStatus.Open
|
|
|
|
|
&& j.CreatedAt >= JobsMedical.Web.Services.Scraping.ListingPolicy.JobCutoffUtc);
|
2026-06-03 01:43:55 +03:30
|
|
|
|
|
|
|
|
if (CityId is not null) q = q.Where(j => j.Facility.CityId == CityId);
|
|
|
|
|
if (DistrictId is not null) q = q.Where(j => j.Facility.DistrictId == DistrictId);
|
|
|
|
|
if (RoleId is not null) q = q.Where(j => j.RoleId == RoleId);
|
|
|
|
|
if (EmploymentType is not null) q = q.Where(j => j.EmploymentType == EmploymentType);
|
2026-06-04 00:19:32 +03:30
|
|
|
if (GenderFilter is Gender g && g != Gender.Any)
|
|
|
|
|
q = q.Where(j => j.GenderRequirement == Gender.Any || j.GenderRequirement == g);
|
2026-06-03 01:43:55 +03:30
|
|
|
|
|
|
|
|
var results = await q.ToListAsync();
|
|
|
|
|
|
|
|
|
|
if (NearMeActive)
|
|
|
|
|
{
|
|
|
|
|
foreach (var j in results)
|
|
|
|
|
if (j.Facility.Lat is double flat && j.Facility.Lng is double flng)
|
|
|
|
|
j.DistanceKm = Geo.DistanceKm(Lat!.Value, Lng!.Value, flat, flng);
|
|
|
|
|
Results = results.OrderBy(j => j.DistanceKm ?? double.MaxValue)
|
|
|
|
|
.ThenByDescending(j => j.CreatedAt).ToList();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Results = results.OrderByDescending(j => j.CreatedAt).ToList();
|
|
|
|
|
}
|
2026-06-19 14:03:57 +03:30
|
|
|
|
|
|
|
|
SetSeo(Roles.FirstOrDefault(r => r.Id == RoleId)?.Name, Cities.FirstOrDefault(c => c.Id == CityId)?.Name);
|
|
|
|
|
return Page();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Title/H1/meta from the active role+city so the page targets «استخدام [نقش] [شهر]».</summary>
|
|
|
|
|
private void SetSeo(string? role, string? city)
|
|
|
|
|
{
|
|
|
|
|
PageHeading =
|
|
|
|
|
role is not null && city is not null ? $"استخدام {role} در {city}"
|
|
|
|
|
: role is not null ? $"استخدام {role}"
|
|
|
|
|
: city is not null ? $"استخدام کادر درمان در {city}"
|
|
|
|
|
: "موقعیتهای استخدامی";
|
|
|
|
|
ViewData["Title"] = PageHeading;
|
|
|
|
|
ViewData["Description"] = role is not null || city is not null
|
|
|
|
|
? $"جدیدترین آگهیهای {PageHeading} در همکادر؛ مشاهده فرصتها و تماس مستقیم با مراکز درمانی."
|
|
|
|
|
: "موقعیتهای استخدامی کادر درمان (پزشک، پرستار، ماما، تکنسین) در بیمارستانها و کلینیکهای تهران — همکادر.";
|
2026-06-03 01:43:55 +03:30
|
|
|
}
|
|
|
|
|
}
|