Add and view announcements
This commit is contained in:
parent
7f8347d0ad
commit
b4e8b97504
|
|
@ -5,8 +5,10 @@ using Nop.Plugin.Misc.AuctionPlugin.Domains;
|
|||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Hubs;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Services;
|
||||
using Nop.Services.Logging;
|
||||
using Nop.Web.Framework;
|
||||
using Nop.Web.Framework.Controllers;
|
||||
using Nop.Web.Framework.Models.DataTables;
|
||||
using Nop.Web.Framework.Mvc;
|
||||
using Nop.Web.Framework.Mvc.Filters;
|
||||
using System;
|
||||
|
|
@ -24,6 +26,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers
|
|||
|
||||
private readonly IAnnouncementService _announcementService;
|
||||
private IHubContext<AuctionHub> _announcementHubContext;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -31,10 +34,12 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers
|
|||
|
||||
public AnnouncementController(
|
||||
IAnnouncementService announcementService,
|
||||
IHubContext<AuctionHub> announcementHubContext)
|
||||
IHubContext<AuctionHub> announcementHubContext,
|
||||
ILogger logger)
|
||||
{
|
||||
_announcementService = announcementService;
|
||||
_announcementHubContext = announcementHubContext;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -104,21 +109,36 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers
|
|||
}
|
||||
|
||||
|
||||
public IActionResult AnnouncementList()
|
||||
public async Task<IActionResult> AnnouncementList()
|
||||
{
|
||||
await _logger.InformationAsync("AnnouncementList called!");
|
||||
var model = new AnnouncementViewModel();
|
||||
return View("~/Plugins/Misc.AuctionPlugin/Areas/Admin/Views/AnnouncementList.cshtml", model);
|
||||
}
|
||||
|
||||
//[HttpPost]
|
||||
//public IActionResult AnnouncementList()
|
||||
//{
|
||||
[HttpPost]
|
||||
//public async Task<IActionResult> GetAnnouncementList([FromBody] KendoGridRequestModel request)
|
||||
public async Task<IActionResult> GetAnnouncementList()
|
||||
{
|
||||
//await _logger.InformationAsync("GetAnnouncementList called!");
|
||||
//var total = (await _announcementService.GetAnnouncementsAsync()).Count();
|
||||
//var result = await _announcementService.GetAnnouncementsAsync(request.Page, request.PageSize);
|
||||
|
||||
//return Json(new
|
||||
//{
|
||||
// Data = result,
|
||||
// Total = total
|
||||
//});
|
||||
|
||||
|
||||
// return View();
|
||||
|
||||
//}
|
||||
try
|
||||
{
|
||||
return Ok(new DataTablesModel { Data = await _announcementService.GetAnnouncementsAsync() });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Models
|
||||
{
|
||||
public class KendoGridRequestModel
|
||||
{
|
||||
// Page number
|
||||
public int Page { get; set; } = 1;
|
||||
|
||||
// Page size (number of items per page)
|
||||
public int PageSize { get; set; } = 10;
|
||||
|
||||
// Field to sort by
|
||||
public string SortField { get; set; }
|
||||
|
||||
// Sort direction (e.g., "asc" or "desc")
|
||||
public string SortDirection { get; set; }
|
||||
|
||||
// Optional: Filtering parameters, can be customized to fit your needs
|
||||
public string FilterField { get; set; }
|
||||
public string FilterValue { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
@using Nop.Core.Infrastructure
|
||||
@using Nop.Web.Framework
|
||||
|
||||
|
||||
@{
|
||||
var defaultGridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().DefaultGridPageSize;
|
||||
var gridPageSizes = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSizes;
|
||||
|
|
@ -13,7 +14,7 @@
|
|||
|
||||
<div class="content-header clearfix">
|
||||
<div class="pull-right">
|
||||
<a href="../LiveAnnouncement/Announcement" class="btn bg-blue">
|
||||
<a href="../GetAnnouncementViewModel" class="btn bg-blue">
|
||||
<i class="fa fa-floppy-o"></i>
|
||||
Add
|
||||
</a>
|
||||
|
|
@ -25,87 +26,29 @@
|
|||
<div class="panel-group">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<div id="Announcement-grid"></div>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$("#Announcement-grid").kendoGrid({
|
||||
dataSource: {
|
||||
type: "json",
|
||||
transport: {
|
||||
read: {
|
||||
url: "@Html.Raw(Url.Action("AnnouncementList", "LiveAnnouncement"))",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: addAntiForgeryToken
|
||||
},
|
||||
destroy: {
|
||||
url: "@Html.Raw(Url.Action("Delete", "LiveAnnouncement"))",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: addAntiForgeryToken
|
||||
}
|
||||
},
|
||||
schema: {
|
||||
data: "Data",
|
||||
total: "Total",
|
||||
errors: "Errors",
|
||||
model: {
|
||||
id: "Id"
|
||||
}
|
||||
},
|
||||
|
||||
error: function (e) {
|
||||
display_kendoui_grid_error(e);
|
||||
// Cancel the changes
|
||||
this.cancelChanges();
|
||||
},
|
||||
@await Html.PartialAsync("Table", new DataTablesModel
|
||||
{
|
||||
Name = "announcement-grid",
|
||||
UrlRead = new DataUrl("GetAnnouncementList", "Announcement"),
|
||||
Paging = false,
|
||||
ColumnCollection = new List<ColumnProperty>
|
||||
{
|
||||
new ColumnProperty(nameof(Announcement.Name))
|
||||
{
|
||||
Title = "Name",
|
||||
Width = "300"
|
||||
},
|
||||
new ColumnProperty(nameof(Announcement.Body))
|
||||
{
|
||||
Title = "Body",
|
||||
Width = "400"
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
pageSize: @(defaultGridPageSize),
|
||||
serverPaging: true,
|
||||
serverFiltering: true,
|
||||
serverSorting: true
|
||||
},
|
||||
pageable: {
|
||||
refresh: true,
|
||||
pageSizes: [@(gridPageSizes)]
|
||||
},
|
||||
editable: {
|
||||
confirmation: false,
|
||||
mode: "inline"
|
||||
},
|
||||
scrollable: false,
|
||||
columns: [{
|
||||
field: "Name",
|
||||
title: "Name",
|
||||
width: 100
|
||||
}, {
|
||||
field: "Body",
|
||||
title: "Body",
|
||||
width: 100,
|
||||
headerAttributes: { style: "text-align:center" },
|
||||
attributes: { style: "text-align:center" }
|
||||
},
|
||||
{
|
||||
field: "IsActive",
|
||||
title: "IsActive",
|
||||
width: 100,
|
||||
headerAttributes: { style: "text-align:center" },
|
||||
attributes: { style: "text-align:center" }
|
||||
},
|
||||
{
|
||||
title: "Edite",
|
||||
width: 100,
|
||||
template: '<a href="Edit/#=Id#">@T("Admin.Common.Edit")</a>'
|
||||
}, {
|
||||
command: { name: "destroy", text: "@T("Admin.Common.Delete")" },
|
||||
title: "@T("Admin.Common.Delete")",
|
||||
width: 100,
|
||||
headerAttributes: { style: "text-align:center" },
|
||||
attributes: { style: "text-align:center" }
|
||||
}]
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -12,4 +12,6 @@
|
|||
@using Nop.Web.Framework.Events
|
||||
@using Nop.Core.Infrastructure
|
||||
@using Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Models;
|
||||
@using Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers;
|
||||
@using Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers;
|
||||
@using Nop.Web.Framework.Models.DataTables
|
||||
@using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities
|
||||
Loading…
Reference in New Issue