[Profile] Editable profile (avatar + resume) + role-based profile dropdown menu
CI/CD / CI · dotnet build (push) Successful in 44s
CI/CD / Deploy · hamkadr (push) Successful in 57s

Every user gets a full editable profile at /Me/Profile: name, role, city, specialty/title, license, years, bio + avatar image upload + resume upload (PDF/image). Avatar/resume stored in-DB on User (migration, 5 nullable columns). Endpoints: /avatar/{id} (public) and /resume/{id} (owner, admin, or an employer who received that user's application). Nav: replaced the scattered action links with an avatar button + dropdown listing all of the user's pages by role (profile, کارجو panel, alerts, preferences, notifications; employer panel; admin panel + settings; logout) — shows the avatar image or initials; collapses into the burger menu on mobile; closes on outside-click.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
soroush.asadi
2026-06-04 21:49:40 +03:30
parent 167d263560
commit e633463906
9 changed files with 1689 additions and 15 deletions
@@ -0,0 +1,123 @@
using System.Security.Claims;
using JobsMedical.Web.Data;
using JobsMedical.Web.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
namespace JobsMedical.Web.Pages.Me;
[Authorize]
public class ProfileModel : PageModel
{
private readonly AppDbContext _db;
public ProfileModel(AppDbContext db) => _db = db;
public List<Role> Roles { get; private set; } = new();
public List<City> Cities { get; private set; } = new();
public bool HasAvatar { get; private set; }
public string? ResumeName { get; private set; }
public string Phone { get; private set; } = "";
[TempData] public string? Msg { get; set; }
[BindProperty] public string? FullName { get; set; }
[BindProperty] public int? RoleId { get; set; }
[BindProperty] public int? CityId { get; set; }
[BindProperty] public string? Specialty { get; set; }
[BindProperty] public string? LicenseNo { get; set; }
[BindProperty] public int YearsExperience { get; set; }
[BindProperty] public string? Bio { get; set; }
private int Uid => int.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)!);
private static readonly string[] ImgTypes = { "image/jpeg", "image/png", "image/webp" };
private static readonly string[] DocTypes = { "image/jpeg", "image/png", "image/webp", "application/pdf" };
private const long MaxImg = 2 * 1024 * 1024; // 2 MB
private const long MaxDoc = 5 * 1024 * 1024; // 5 MB
public async Task OnGetAsync()
{
await LoadListsAsync();
var u = await _db.Users.Include(x => x.DoctorProfile).FirstAsync(x => x.Id == Uid);
Phone = u.Phone;
FullName = u.FullName;
HasAvatar = u.Avatar != null;
ResumeName = u.ResumeFileName;
var p = u.DoctorProfile;
RoleId = p?.RoleId;
CityId = p?.CityId;
Specialty = p?.Specialty;
LicenseNo = p?.LicenseNo;
YearsExperience = p?.YearsExperience ?? 0;
Bio = p?.Bio;
}
public async Task<IActionResult> OnPostAsync(IFormFile? avatar, IFormFile? resume)
{
var u = await _db.Users.Include(x => x.DoctorProfile).FirstAsync(x => x.Id == Uid);
u.FullName = string.IsNullOrWhiteSpace(FullName) ? null : FullName.Trim();
var p = u.DoctorProfile ??= new DoctorProfile { UserId = Uid };
p.RoleId = RoleId;
p.CityId = CityId;
p.Specialty = string.IsNullOrWhiteSpace(Specialty) ? "پزشک عمومی" : Specialty.Trim();
p.LicenseNo = LicenseNo?.Trim();
p.YearsExperience = Math.Clamp(YearsExperience, 0, 70);
p.Bio = Bio?.Trim();
string? warn = null;
if (avatar is { Length: > 0 })
{
if (avatar.Length > MaxImg || !ImgTypes.Contains((avatar.ContentType ?? "").ToLowerInvariant()))
warn = "تصویر باید JPG/PNG/WebP و کمتر از ۲ مگابایت باشد.";
else
{
using var ms = new MemoryStream();
await avatar.CopyToAsync(ms);
u.Avatar = ms.ToArray();
u.AvatarContentType = avatar.ContentType!.ToLowerInvariant();
}
}
if (resume is { Length: > 0 })
{
if (resume.Length > MaxDoc || !DocTypes.Contains((resume.ContentType ?? "").ToLowerInvariant()))
warn = (warn is null ? "" : warn + " ") + "رزومه باید PDF یا تصویر و کمتر از ۵ مگابایت باشد.";
else
{
using var ms = new MemoryStream();
await resume.CopyToAsync(ms);
u.Resume = ms.ToArray();
u.ResumeContentType = resume.ContentType!.ToLowerInvariant();
u.ResumeFileName = Path.GetFileName(resume.FileName);
}
}
await _db.SaveChangesAsync();
Msg = warn ?? "پروفایل ذخیره شد.";
return RedirectToPage();
}
public async Task<IActionResult> OnPostDeleteResumeAsync()
{
var u = await _db.Users.FirstAsync(x => x.Id == Uid);
u.Resume = null; u.ResumeFileName = null; u.ResumeContentType = null;
await _db.SaveChangesAsync();
Msg = "رزومه حذف شد.";
return RedirectToPage();
}
public async Task<IActionResult> OnPostDeleteAvatarAsync()
{
var u = await _db.Users.FirstAsync(x => x.Id == Uid);
u.Avatar = null; u.AvatarContentType = null;
await _db.SaveChangesAsync();
Msg = "تصویر حذف شد.";
return RedirectToPage();
}
private async Task LoadListsAsync()
{
Roles = await _db.Roles.Where(r => r.IsActive).OrderBy(r => r.SortOrder).ToListAsync();
Cities = await _db.Cities.Where(c => c.IsActive).OrderBy(c => c.Name).ToListAsync();
}
}