f97f891d67
Full ASP.NET Core 10 Razor Pages app for آساد ابزار tool repair shop in Karaj, Iran (official DeWalt representative). Features: - Homepage, Services, DeWalt page, Shop (pagination + images) - 10 brand SEO pages (/brands/*) with rich Persian content + FAQ schema - Blog engine with admin management (/blog, /Admin/Blog) - Cart, Checkout, Contact (OpenStreetMap embed) - Admin panel: Products CRUD, Orders, Blog, Change Password - Jalali date formatting, product images, SiteData centralised contact - Docker + docker-compose with healthcheck - Gitea CI/CD via .gitea/workflows/ci-cd.yml (NuGet through Nexus mirror) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using AsadiTools.Data;
|
|
using AsadiTools.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace AsadiTools.Pages.Blog;
|
|
|
|
public class BlogPostModel(AppDbContext db) : PageModel
|
|
{
|
|
public BlogPost? Post { get; private set; }
|
|
public List<BlogPost> RelatedPosts { get; private set; } = [];
|
|
|
|
public async Task<IActionResult> OnGetAsync(string slug)
|
|
{
|
|
Post = await db.BlogPosts
|
|
.Where(p => p.IsPublished && p.Slug == slug)
|
|
.FirstOrDefaultAsync();
|
|
|
|
// Fallback: numeric slug = post ID
|
|
if (Post is null && int.TryParse(slug, out var id))
|
|
Post = await db.BlogPosts.Where(p => p.IsPublished && p.Id == id).FirstOrDefaultAsync();
|
|
|
|
if (Post is null) return NotFound();
|
|
|
|
// Related: same tag(s)
|
|
var tags = Post.TagList;
|
|
if (tags.Length > 0)
|
|
{
|
|
RelatedPosts = await db.BlogPosts
|
|
.Where(p => p.IsPublished && p.Id != Post.Id && p.Tags != null)
|
|
.ToListAsync();
|
|
RelatedPosts = RelatedPosts
|
|
.Where(p => p.TagList.Any(t => tags.Contains(t)))
|
|
.OrderByDescending(p => p.PublishedAt)
|
|
.Take(3)
|
|
.ToList();
|
|
}
|
|
|
|
ViewData["Title"] = Post.Title + " | آساد ابزار";
|
|
ViewData["Description"] = Post.MetaDescription ?? Post.Excerpt ?? Post.Title;
|
|
return Page();
|
|
}
|
|
}
|