public ViewResult Index(string sortOrder, string currentFilter, string searchString, int? page)
{
ViewBag.CurrentSort = sortOrder;
ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "Name_desc" : "";
ViewBag.DateSortParm = sortOrder == "Date" ? "Date_desc" : "Date";
if (searchString != null)
{
page = 1;
}
else
{
searchString = currentFilter;
}
ViewBag.CurrentFilter = searchString;
var DbMail = from s in db.tbMessages
select s;
if (!String.IsNullOrEmpty(searchString))
{
DbMail = DbMail.Where(s => s.FromUserID.ToUpper().Contains(searchString.ToUpper())
|| s.ToUserID.ToUpper().Contains(searchString.ToUpper())
|| s.Message.ToUpper().Contains(searchString.ToUpper()));
}
switch (sortOrder)
{
case "Name_desc":
DbMail = DbMail.OrderByDescending(s => s.FromUserID);
break;
case "Date":
DbMail = DbMail.OrderBy(s => s.SentDate);
break;
case "Date_desc":
DbMail = DbMail.OrderByDescending(s => s.SentDate);
break;
default:
DbMail = DbMail.OrderBy(s => s.SentDate);
break;
}
int pageSize = 10;
int pageNumber = (page ?? 1);
return View(DbMail.ToPagedList(pageNumber, pageSize));
}
@model PagedList.IPagedList<Mail.Models.tbMessage>
@using PagedList.Mvc;
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
@*@using (Html.BeginForm())
{
<p>
Find : @Html.TextBox("SearchString")
<input type="submit" value="Search" />
</p>
}*@
@using (Html.BeginForm("Index", "mail", FormMethod.Get))
{
<p>
Find : @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
<input type="submit" value="Search"/>
</p>
}
<table class="table">
<tr>
@*<th>
@Html.DisplayNameFor(model => model.Code)
</th>*@
<th>
@Html.ActionLink("From Name", "Index", new { sortOrder = ViewBag.NameSortParm })
@*@Html.DisplayNameFor(model => model.FromUserID)*@
</th>
<th>
@*@Html.DisplayNameFor(model => model.ToUserID)*@
</th>
<th>
@Html.ActionLink("SentDate", "Index", new { sortOrder = ViewBag.NameSortParm })
@* @Html.DisplayNameFor(model => model.SentDate)*@
</th>
<th>
<text>Subject</text>
@*@Html.DisplayNameFor(model => model.SubjectLine)*@
</th>
<th>
<text>Message</text>
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
@*<td>
@Html.DisplayFor(modelItem => item.Code)
</td>*@
<td>
@Html.DisplayFor(modelItem => item.FromUserID)
</td>
<td>
@Html.DisplayFor(modelItem => item.ToUserID)
</td>
<td>
@Html.DisplayFor(modelItem => item.SentDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.SubjectLine)
</td>
<td>
@Html.DisplayFor(modelItem => item.Message)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
</td>
</tr>
}
</table>
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("Index", new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))
{
ViewBag.CurrentSort = sortOrder;
ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "Name_desc" : "";
ViewBag.DateSortParm = sortOrder == "Date" ? "Date_desc" : "Date";
if (searchString != null)
{
page = 1;
}
else
{
searchString = currentFilter;
}
ViewBag.CurrentFilter = searchString;
var DbMail = from s in db.tbMessages
select s;
if (!String.IsNullOrEmpty(searchString))
{
DbMail = DbMail.Where(s => s.FromUserID.ToUpper().Contains(searchString.ToUpper())
|| s.ToUserID.ToUpper().Contains(searchString.ToUpper())
|| s.Message.ToUpper().Contains(searchString.ToUpper()));
}
switch (sortOrder)
{
case "Name_desc":
DbMail = DbMail.OrderByDescending(s => s.FromUserID);
break;
case "Date":
DbMail = DbMail.OrderBy(s => s.SentDate);
break;
case "Date_desc":
DbMail = DbMail.OrderByDescending(s => s.SentDate);
break;
default:
DbMail = DbMail.OrderBy(s => s.SentDate);
break;
}
int pageSize = 10;
int pageNumber = (page ?? 1);
return View(DbMail.ToPagedList(pageNumber, pageSize));
}
@model PagedList.IPagedList<Mail.Models.tbMessage>
@using PagedList.Mvc;
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
@*@using (Html.BeginForm())
{
<p>
Find : @Html.TextBox("SearchString")
<input type="submit" value="Search" />
</p>
}*@
@using (Html.BeginForm("Index", "mail", FormMethod.Get))
{
<p>
Find : @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
<input type="submit" value="Search"/>
</p>
}
<table class="table">
<tr>
@*<th>
@Html.DisplayNameFor(model => model.Code)
</th>*@
<th>
@Html.ActionLink("From Name", "Index", new { sortOrder = ViewBag.NameSortParm })
@*@Html.DisplayNameFor(model => model.FromUserID)*@
</th>
<th>
@*@Html.DisplayNameFor(model => model.ToUserID)*@
</th>
<th>
@Html.ActionLink("SentDate", "Index", new { sortOrder = ViewBag.NameSortParm })
@* @Html.DisplayNameFor(model => model.SentDate)*@
</th>
<th>
<text>Subject</text>
@*@Html.DisplayNameFor(model => model.SubjectLine)*@
</th>
<th>
<text>Message</text>
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
@*<td>
@Html.DisplayFor(modelItem => item.Code)
</td>*@
<td>
@Html.DisplayFor(modelItem => item.FromUserID)
</td>
<td>
@Html.DisplayFor(modelItem => item.ToUserID)
</td>
<td>
@Html.DisplayFor(modelItem => item.SentDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.SubjectLine)
</td>
<td>
@Html.DisplayFor(modelItem => item.Message)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
</td>
</tr>
}
</table>
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("Index", new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))