diff --git a/StockManMVC/Controllers/LocationsController.cs b/StockManMVC/Controllers/LocationsController.cs index 0ef908f..ec0affd 100644 --- a/StockManMVC/Controllers/LocationsController.cs +++ b/StockManMVC/Controllers/LocationsController.cs @@ -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()); } diff --git a/StockManMVC/Views/Locations/_ListByType.cshtml b/StockManMVC/Views/Locations/_ListByType.cshtml index 8767ce1..92e228f 100644 --- a/StockManMVC/Views/Locations/_ListByType.cshtml +++ b/StockManMVC/Views/Locations/_ListByType.cshtml @@ -3,10 +3,12 @@ diff --git a/StockManMVC/bin/StockManMVC.dll b/StockManMVC/bin/StockManMVC.dll index e015265..74825f1 100644 Binary files a/StockManMVC/bin/StockManMVC.dll and b/StockManMVC/bin/StockManMVC.dll differ
- @Html.DisplayNameFor(model => model.Descr) + @*@Html.DisplayNameFor(model => model.Descr)*@ + @Html.ActionLink(Html.DisplayNameFor(model => model.Descr).ToString(), "Index", new { SortOrd = ViewBag.DescrSortParm }) - @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 })