using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.EntityFrameworkCore; using DrSousan.Api.Data; using DrSousan.Api.Models; namespace DrSousan.Api.Pages; public class IndexModel : PageModel { private readonly AppDbContext _db; public IndexModel(AppDbContext db) => _db = db; // Hero public Dictionary Hero { get; private set; } = new(); public Dictionary About { get; private set; } = new(); public Dictionary Contact { get; private set; } = new(); // Collections public List Services { get; private set; } = new(); public List Gallery { get; private set; } = new(); public int GalleryTotal { get; private set; } = 0; public List Testimonials { get; private set; } = new(); public List RecentPosts { get; private set; } = new(); public List Faqs { get; private set; } = new(); public async Task OnGetAsync() { var settings = await _db.SiteSettings.ToListAsync(); Hero = settings.Where(s => s.Section == "hero") .ToDictionary(s => s.Key, s => s.Value); About = settings.Where(s => s.Section == "about") .ToDictionary(s => s.Key, s => s.Value); Contact = settings.Where(s => s.Section == "contact") .ToDictionary(s => s.Key, s => s.Value); Services = await _db.Services .Where(s => s.IsActive) .OrderBy(s => s.Order) .ToListAsync(); // Homepage shows only a teaser of 3; full set lives on /gallery var galleryQuery = _db.GalleryItems.Where(g => g.IsActive); GalleryTotal = await galleryQuery.CountAsync(); Gallery = await galleryQuery .OrderBy(g => g.Order) .Take(3) .ToListAsync(); Testimonials = await _db.Testimonials .Where(t => t.IsActive) .OrderByDescending(t => t.CreatedAt) .ToListAsync(); RecentPosts = await _db.BlogPosts .Include(p => p.Category) .Where(p => p.IsPublished) .OrderByDescending(p => p.PublishedAt) .Take(3) .ToListAsync(); Faqs = await _db.Faqs .Where(f => f.IsActive) .OrderBy(f => f.Order) .ToListAsync(); // Expose site name for layout var siteName = Hero.GetValueOrDefault("name", "دکتر سوسن آل‌طه"); ViewData["SiteName"] = siteName; ViewData["Title"] = $"{siteName} | متخصص زیبایی پوست تهران"; } // ── Helpers for the view ───────────────────────────────────────────────── public static string Stars(int count) { var s = string.Concat(Enumerable.Repeat("⭐", count)); return string.IsNullOrEmpty(s) ? "⭐⭐⭐⭐⭐" : s; } public static string ServiceIcon(string title) => title switch { var t when t.Contains("لیزر") => "✨", var t when t.Contains("بوتاکس") || t.Contains("فیلر") => "💉", var t when t.Contains("مزو") => "💊", var t when t.Contains("پاکسازی") => "🧴", var t when t.Contains("مشاوره") => "🩺", var t when t.Contains("هایفو") || t.Contains("HIFU") => "🔬", var t when t.Contains("RF") => "⚡", _ => "🌟" }; public static string ServiceIconSvg(string title) => title switch { var t when t.Contains("لیزر") => """""", var t when t.Contains("بوتاکس") || t.Contains("فیلر") => """""", var t when t.Contains("مزو") => """""", var t when t.Contains("پاکسازی") => """""", var t when t.Contains("مشاوره") => """""", _ => """""" }; }