Skip to content

Commit

Permalink
Section 11 - Demo - Filters in Order List
Browse files Browse the repository at this point in the history
  • Loading branch information
bhrugen committed Sep 26, 2021
1 parent fe454f6 commit 3b563ac
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
25 changes: 24 additions & 1 deletion BulkyBookWeb/Areas/Admin/Controllers/OrderController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using BulkyBook.DataAccess.Repository.IRepository;
using BulkyBook.Models;
using BulkyBook.Utility;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;

namespace BulkyBookWeb.Areas.Admin.Controllers
{
Expand All @@ -21,10 +23,31 @@ public IActionResult Index()

#region API CALLS
[HttpGet]
public IActionResult GetAll()
public IActionResult GetAll(string status)
{
IEnumerable<OrderHeader> orderHeaders;
orderHeaders = _unitOfWork.OrderHeader.GetAll(includeProperties: "ApplicationUser");


switch (status)
{
case "pending":
orderHeaders = orderHeaders.Where(u => u.PaymentStatus == SD.PaymentStatusDelayedPayment);
break;
case "inprocess":
orderHeaders = orderHeaders.Where(u => u.OrderStatus == SD.StatusInProcess);
break;
case "completed":
orderHeaders = orderHeaders.Where(u => u.OrderStatus == SD.StatusShipped);
break;
case "approved":
orderHeaders = orderHeaders.Where(u => u.OrderStatus == SD.StatusApproved);
break;
default:
break;
}


return Json(new { data = orderHeaders });
}
#endregion
Expand Down
10 changes: 9 additions & 1 deletion BulkyBookWeb/Areas/Admin/Views/Order/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var pending="text-primary";
var inprocess="text-primary";
var completed="text-primary";
var approved="text-primary";
var all="text-primary";

switch (status)
Expand All @@ -16,7 +17,10 @@
case "completed":
completed = "active text-white";
break;
default :
case "approved":
approved = "active text-white";
break;
default:
all = "active text-white";
break;
}
Expand All @@ -41,6 +45,10 @@
<a style="text-decoration:none;" asp-controller="Order"
asp-action="Index" asp-route-status="completed">
<li class="list-group-item @completed">Completed</li>
</a>
<a style="text-decoration:none;" asp-controller="Order"
asp-action="Index" asp-route-status="approved">
<li class="list-group-item @approved">Approved</li>
</a>
<a style="text-decoration:none;" asp-controller="Order"
asp-action="Index" asp-route-status="all">
Expand Down
27 changes: 24 additions & 3 deletions BulkyBookWeb/wwwroot/js/order.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
var dataTable;

$(document).ready(function () {
loadDataTable();
var url = window.location.search;
if (url.includes("inprocess")) {
loadDataTable("inprocess");
}
else {
if (url.includes("completed")) {
loadDataTable("completed");
}
else {
if (url.includes("pending")) {
loadDataTable("pending");
}
else {
if (url.includes("approved")) {
loadDataTable("approved");
}
else {
loadDataTable("all");
}
}
}
}
});

function loadDataTable() {
function loadDataTable(status) {
dataTable = $('#tblData').DataTable({
"ajax": {
"url":"/Admin/Order/GetAll"
"url": "/Admin/Order/GetAll?status=" + status
},
"columns": [
{ "data": "id", "width": "5%" },
Expand Down

0 comments on commit 3b563ac

Please sign in to comment.