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>
58 lines
2.1 KiB
C#
58 lines
2.1 KiB
C#
using AsadiTools.Data;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
|
namespace AsadiTools.Pages.Admin.Blog;
|
|
|
|
[Authorize(AuthenticationSchemes = "AdminCookie")]
|
|
public class AdminBlogEditModel(AppDbContext db) : PageModel
|
|
{
|
|
[BindProperty] public BlogPostInput Input { get; set; } = new();
|
|
public int PostId { get; private set; }
|
|
|
|
public async Task<IActionResult> OnGetAsync(int id)
|
|
{
|
|
var post = await db.BlogPosts.FindAsync(id);
|
|
if (post is null) return NotFound();
|
|
PostId = id;
|
|
Input = new BlogPostInput
|
|
{
|
|
Title = post.Title,
|
|
Slug = post.Slug,
|
|
Content = post.Content,
|
|
Excerpt = post.Excerpt,
|
|
MetaDescription = post.MetaDescription,
|
|
FeaturedImage = post.FeaturedImage,
|
|
Tags = post.Tags,
|
|
IsPublished = post.IsPublished,
|
|
};
|
|
ViewData["Title"] = "ویرایش: " + post.Title;
|
|
return Page();
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostAsync(int id)
|
|
{
|
|
if (!ModelState.IsValid) { PostId = id; return Page(); }
|
|
|
|
var post = await db.BlogPosts.FindAsync(id);
|
|
if (post is null) return NotFound();
|
|
|
|
var wasUnpublished = !post.IsPublished;
|
|
post.Title = Input.Title;
|
|
post.Slug = string.IsNullOrWhiteSpace(Input.Slug) ? post.Slug : Input.Slug.Trim();
|
|
post.Content = Input.Content;
|
|
post.Excerpt = Input.Excerpt;
|
|
post.MetaDescription = Input.MetaDescription;
|
|
post.FeaturedImage = string.IsNullOrWhiteSpace(Input.FeaturedImage) ? null : Input.FeaturedImage;
|
|
post.Tags = Input.Tags;
|
|
post.IsPublished = Input.IsPublished;
|
|
post.UpdatedAt = DateTime.Now;
|
|
if (Input.IsPublished && wasUnpublished)
|
|
post.PublishedAt = DateTime.Now;
|
|
|
|
await db.SaveChangesAsync();
|
|
return RedirectToPage("/Admin/Blog/Index");
|
|
}
|
|
}
|