using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using HLWebOKBAdminPlugin.Models; using HLWebOKBAdminPlugin.OKBAdministrationService; namespace HLWebOKBAdminPlugin.Controllers { public class PlatformController : Controller { // // GET: /Platform/ public ActionResult Index() { Session["SelectedSubMenu"] = "Platform"; PlatformModel plm = new PlatformModel(); return View(plm); }//Index public ActionResult Detail(long? id) { Session["SelectedSubMenu"] = "Platform"; PlatformModel plm = new PlatformModel(); if (id == null) plm.Platform = new Platform(); else plm.Platform = (Platform)plm.Platforms.Where(x => x.Id.Equals((long)id)).FirstOrDefault(); return View(plm); }//Detail public ActionResult Delete(long? id) { Session["SelectedSubMenu"] = "Platform"; PlatformModel plm = new PlatformModel(); if (id != 0) { plm.DeletePlatform((long)id); } return View("Index", plm); }//Delete public ActionResult SaveChanges(FormCollection collection) { long platformId = long.Parse(collection.Get("PlatformId")); String platformName = collection.Get("PlatformName"); String platformDescription = collection.Get("PlatformDescription"); // Later, we will get the runs from the session ... PlatformModel plm = new PlatformModel(); if (platformId != 0) plm.Platform = (Platform)plm.Platforms.Where(x => x.Id.Equals(platformId)).FirstOrDefault(); plm.Platform.Name = platformName; plm.Platform.Description = platformDescription; plm.SavePlatform(plm.Platform); return View("Index", plm); }//SaveChanges public ActionResult SortAsc() { Session["SelectedSubMenu"] = "Platform"; PlatformModel plm = new PlatformModel(); plm.Platforms = plm.Platforms.OrderBy(x => x.Name).ToList(); return View("Index", plm); } /// /// Controller for Index View /// /// public ActionResult SortDesc() { Session["SelectedSubMenu"] = "Platform"; PlatformModel plm = new PlatformModel(); IOrderedEnumerable plmOrderedList = plm.Platforms.OrderByDescending(x => x.Name); IList plmList = new List(); foreach (var item in plmOrderedList) { plmList.Add(item); } plm.Platforms = plmList; // this should be the right code //pm.Problems = pm.Problems.OrderByDescending(x => x.Name).ToArray(); return View("Index", plm); } } }