using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using ITRA.Models;
using PagedList;
using PagedList.Mvc;
namespace ITRA.Controllers
{
public class SSP_ControlController : Controller
{
private RiskAssessmentEntities2 db = new RiskAssessmentEntities2();
// GET: SSP_Control
public ViewResult Index(string sortOrder, string currentFilter, string searchString, int? page)
{
ViewBag.CurrentSort = sortOrder;
ViewBag.NISTIDSortParm = String.IsNullOrEmpty(sortOrder) ? "NISTID_asc" : "";
ViewBag.TitleSortParm = String.IsNullOrEmpty(sortOrder) ? "Title_asc" : "";
ViewBag.WorksheetStatementSortParm = String.IsNullOrEmpty(sortOrder) ? "WorksheetStatement_asc" : "";
if (searchString != null)
{
page = 1;
}
else
{
searchString = currentFilter;
}
ViewBag.CurrentFilter = searchString;
var NISTID = from NID in db.SSP_Control
select NID;
var Title = from t in db.SSP_Control
select t;
var WorksheetStatement = from ws in db.SSP_Control
select ws;
if (!String.IsNullOrEmpty(searchString))
{
NISTID = NISTID.Where(NID => NID.NISTID.Contains(searchString));
}
switch (sortOrder)
{
case "NISTID_asc":
NISTID = NISTID.OrderBy(NID => NID.NISTID);
break;
case "Title_asc":
Title = Title.OrderBy(t => t.Title);
break;
case "WorksheetStatement_asc":
WorksheetStatement = WorksheetStatement.OrderBy(ws => ws.WorksheetStatement);
break;
default:
NISTID = NISTID.OrderBy(NID => NID.NISTID);
break;
}
int pageSize = 10;
int pageNumber = (page ?? 1);
return View(NISTID.ToPagedList(pageNumber, pageSize));
@model PagedList.IPagedList<ITRA.Models.SSP_Control>
@using PagedList.Mvc;
@using PagedList;
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
@{
ViewBag.Title = "SSP Controls";
}
<h2>SSP Controls</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
@using (Html.BeginForm("Index", "SSP_Control", FormMethod.Get))
{
<p>
Search: @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
<input type="submit" value="Search" />
</p>
}
<table class="table">
<tr>
<th>
@Html.ActionLink("NIST ID", "Index", new { sortOrder = ViewBag.NISTIDSortParm, currentFilter = ViewBag.CurrentFilter })
</th>
<th>
@Html.ActionLink("Title", "Index", new { sortOrder = ViewBag.TitleSortParm, currentFilter = ViewBag.CurrentFilter })
</th>
<th>
@Html.ActionLink("Worksheet Statement", "Index", new { sortOrder = ViewBag.WorksheetStatementSortParm, currentFilter = ViewBag.CurrentFilter })
</th>
<th>
@Html.ActionLink("Control Requirement", "Index")
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.NISTID)
</td>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.WorksheetStatement)
</td>
<td>
@Html.DisplayFor(modelItem => item.ControlRequirement)
</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>
<br />
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 }))
The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications
TRUSTED BY
ASKER