prima bozza gestione sorting (però si scontra con altri filtraggi...)

This commit is contained in:
Samuele E. Locatelli (WEB DEV)
2016-10-20 23:22:22 +02:00
parent cd721e31b3
commit 1ce90e9ee5
3 changed files with 27 additions and 6 deletions
+23 -4
View File
@@ -15,10 +15,11 @@ namespace StockManMVC.Controllers
private StockManEntities db = new StockManEntities();
// GET: Locations/LocTypeID
public ActionResult Index(string LocTypeID, string SearchVal)
public ActionResult Index(string LocTypeID, string SearchVal, string SortOrd)
{
if (LocTypeID == null) LocTypeID = "";
if (SearchVal == null) SearchVal = "";
if (SortOrd == null) SortOrd = "";
ViewBag.LocTypeID = new SelectList(db.LocType, "ID", "Descr", LocTypeID);
ViewBag.LocTypeSel = LocTypeID;
ViewBag.SearchString = SearchVal;
@@ -28,10 +29,13 @@ namespace StockManMVC.Controllers
// GET: Location/ListByType/LocTypeID
public ActionResult ListByType(string LocTypeID, string SearchVal)
public ActionResult ListByType(string LocTypeID, string SearchVal, string SortOrd)
{
if (LocTypeID == null) LocTypeID = "";
if (SearchVal == null) SearchVal = "";
if (SortOrd == null) SortOrd = "";
ViewBag.DescrSortParm = String.IsNullOrEmpty(SortOrd) ? "Descr_desc" : "";
ViewBag.LocTypeSortParm = SortOrd == "LocType" ? "LocType_desc" : "LocType";
var CurrLocations = db.Location.Where(s => s.ID != "");
if (LocTypeID.ToString() != "")
{
@@ -39,9 +43,24 @@ namespace StockManMVC.Controllers
}
if(SearchVal != "")
{
CurrLocations = CurrLocations.Where(s => s.Descr.Contains(SearchVal));
CurrLocations = CurrLocations.Where(s => s.Descr.Contains(SearchVal)); // || s.LocType.Descr.Contains(SearchVal)
}
// ora verifico ordinamento...
switch (SortOrd)
{
case "Descr_desc":
CurrLocations = CurrLocations.OrderByDescending(s => s.Descr);
break;
case "LocType":
CurrLocations = CurrLocations.OrderBy(s => s.LocType.Descr);
break;
case "LocType_desc":
CurrLocations = CurrLocations.OrderByDescending(s => s.LocType.Descr);
break;
default:
CurrLocations = CurrLocations.OrderBy(s => s.Descr);
break;
}
ViewBag.LocTypeID = LocTypeID;
return PartialView("_ListByType", CurrLocations.ToList());
}
@@ -3,10 +3,12 @@
<table class="table table-condensed table-responsive table-striped table-hover table-bordered">
<tr>
<th>
@Html.DisplayNameFor(model => model.Descr)
@*@Html.DisplayNameFor(model => model.Descr)*@
@Html.ActionLink(Html.DisplayNameFor(model => model.Descr).ToString(), "Index", new { SortOrd = ViewBag.DescrSortParm })
</th>
<th>
@Html.DisplayNameFor(model => model.LocType.Descr)
@*@Html.DisplayNameFor(model => model.LocType.Descr)*@
@Html.ActionLink(Html.DisplayNameFor(model => model.LocType.Descr).ToString(), "Index", new { SortOrd = ViewBag.LocTypeSortParm })
</th>
<th></th>
</tr>
Binary file not shown.