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 { // // Controller for ProblemClass Submenu // public class ProblemClassController : Controller { // // GET: /ProblemClass/ public ActionResult Index() { Session["SelectedSubMenu"] = "ProblemClass"; ProblemClassModel pcm = new ProblemClassModel(); return View(pcm); }//Index public ActionResult Detail(long? id) { Session["SelectedSubMenu"] = "ProblemClass"; ProblemClassModel pcm = new ProblemClassModel(); if (id == null) pcm.ProblemClass = new ProblemClass(); else pcm.ProblemClass = (ProblemClass)pcm.ProblemClasses.Where(x => x.Id.Equals((long)id)).FirstOrDefault(); return View(pcm); }//Detail /// /// Controller for Index View /// /// public ActionResult Delete(long? id) { Session["SelectedSubMenu"] = "ProblemClass"; ProblemClassModel pcm = new ProblemClassModel(); if (id != 0) { pcm.DeleteProblemClass((long)id); } return View("Index", pcm); }//Delete /// /// Controller for Detail View /// /// public ActionResult SaveChanges(FormCollection collection) { long problemClassId = long.Parse(collection.Get("ProblemClassId")); String problemClassName = collection.Get("ProblemClassName"); String problemClassDescription = collection.Get("ProblemClassDescription"); // Later, we will get the runs from the session ... ProblemClassModel pcm = new ProblemClassModel(); if (problemClassId != 0) pcm.ProblemClass = (ProblemClass)pcm.ProblemClasses.Where(x => x.Id.Equals(problemClassId)).FirstOrDefault(); pcm.ProblemClass.Name = problemClassName; pcm.ProblemClass.Description = problemClassDescription; pcm.SaveProblemClass(pcm.ProblemClass); return View("Index", pcm); }//SaveChanges /// /// Controller for Index View /// /// public ActionResult SortAsc() { Session["SelectedSubMenu"] = "ProblemClass"; ProblemClassModel pcm = new ProblemClassModel(); pcm.ProblemClasses = pcm.ProblemClasses.OrderBy(x => x.Name).ToList(); return View("Index", pcm); } /// /// Controller for Index View /// /// public ActionResult SortDesc() { Session["SelectedSubMenu"] = "ProblemClass"; ProblemClassModel pcm = new ProblemClassModel(); IOrderedEnumerable pcmOrderedList = pcm.ProblemClasses.OrderByDescending(x => x.Name); IList pcmList = new List(); foreach (var item in pcmOrderedList) { pcmList.Add(item); } pcm.ProblemClasses = pcmList; // this should be the right code //pm.Problems = pm.Problems.OrderByDescending(x => x.Name).ToArray(); return View("Index", pcm); } } }