Hi,
I have order number and status. One order can have status either 'Pending' or "close".
The dashboard will display the order that have "Pending" and for order that have "close" status, it will be displayed in dashboard for one week. Then after 1 week it will be remove to archive.
So here is my code:
Controller
public ActionResult Index()
{
var updateList = (from od in db.order
join a in db.customer
on od.order_num equals a.order_no
select new DetailModel
{
id = od.id,
order_num = od.order_num,
name = a.name,
invoice = od.invoice,
address = a.address,
completedate = od.completedate,
status = od.status
}
).Take(1000).ToList();
if (updateList.Count() != 0)
{
ViewBag.updateList = updateList;
}
else if (updateList.Count() == 0)
{
ViewBag.updateList = null;
ViewBag.message = "No records found!";
}
return View();
}
View
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<input type="submit" value="Send Email" class="btn btn-success" align="right" />
<br/><br/>
<div class="table" id="table_id">
<table class="table table-striped table-bordered table-hover table-sm display" id="dataTable" style="width:100%" cellspacing="0">
<thead class="thead-dark">
<tr>
<th></th>
<th class="text-center">Order Number</th>
<th class="text-center">Invoice</th>
<th class="text-center">Name</th>
<th class="text-center">Address</th>
<th class="text-center">Status</th>
</tr>
</thead>
<tbody>
@if (ViewBag.updateList != null)
{
foreach (var item in (List<ShopWithMe.Models.DetailModel>)ViewBag.updateList)
{
<tr>
<td>@item.order_num</td>
<td>@item.invoice</td>
<td>@item.name</td>
<td>@item.address</td>
<td>@item.status</td>
</tr>
}
}
</tbody>
</table>
</div>
}
Model
public class DetailModel
{
public int id { get; set; }
public Nullable<int> order_num { get; set; }
public Nullable<System.DateTime> completedate { get; set; }
public string name { get; set; }
public string address { get; set; }
public string invoice { get; set; }
public string status { get; set; }
}