Files
Dashboard_Exercise/Views/Panel/NewsList.cshtml
2025-08-23 16:13:20 +03:30

78 lines
3.3 KiB
Plaintext

@model IEnumerable<boilerplate.Models.News>
@{
ViewBag.Title = "لیست اخبار";
Layout = "~/Views/_PanelSideBar.cshtml";
}
<div class="card card-custom">
<div class="card-header">
<div class="card-title">
<h3 class="card-label">@ViewBag.Title</h3>
</div>
<div class="card-toolbar">
<a href="@Url.Action("AddNews", "Panel")" class="btn btn-primary font-weight-bolder">
<i class="fa fa-plus"></i>
افزودن خبر جدید
</a>
</div>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th>تصویر</th>
<th>عنوان خبر</th>
<th>خلاصه</th>
<th>تاریخ ایجاد</th>
<th>عملیات</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr id="news-row-@item.News_ID">
<td>
<img src="~/Media/News/@item.News_IMG" alt="News Image" style="width: 100px; height: auto; border-radius: 8px;"
onerror="this.onerror=null;this.src='/Media/default-image.png';" />
</td>
<td>@item.News_Title</td>
<td>@item.News_Summary</td>
<td>
@(item.News_CreateDate > DateTime.MinValue ? new boilerplate.Models.Functions().ConvertToPersianDate(item.News_CreateDate) : "")
</td>
<td>
<a href="@Url.Action("AddNews", "Panel", new { id = item.News_ID })" class="btn btn-sm btn-clean btn-icon" title="ویرایش">
<i class="fa fa-edit text-primary"></i>
</a>
<button class="btn btn-sm btn-clean btn-icon" title="حذف" onclick="deleteNews(@item.News_ID)">
<i class="fa fa-trash text-danger"></i>
</button>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>
@section Script {
<script>
function deleteNews(id) {
if (confirm("آیا از حذف این خبر مطمئن هستید؟ این عملیات قابل بازگشت نیست.")) {
$.post("@Url.Action("DeleteNews", "Panel")", { id: id }, function(data) {
if (data.success) {
$("#news-row-" + id).fadeOut(500, function() { $(this).remove(); });
toastr.success("خبر با موفقیت حذف شد.");
} else {
toastr.error("خطا در حذف خبر. " + (data.message || ""));
}
}).fail(function() {
toastr.error("خطا در برقراری ارتباط با سرور.");
});
}
}
</script>
}