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 AlgorithmClassController : Controller {
//
// GET: /AlgorithmClass/
public ActionResult Index() {
Session["SelectedSubMenu"] = "AlgorithmClass";
AlgorithmClassModel acm = new AlgorithmClassModel();
return View(acm);
}//Index
public ActionResult Detail(long? id) {
Session["SelectedSubMenu"] = "AlgorithmClass";
AlgorithmClassModel acm = new AlgorithmClassModel();
if (id == null)
acm.AlgorithmClass = new AlgorithmClass();
else
acm.AlgorithmClass = (AlgorithmClass)acm.AlgorithmClasses.Where(x => x.Id.Equals((long)id)).FirstOrDefault();
return View(acm);
}//Detail
///
/// Controller for Index View
///
///
public ActionResult Delete(long? id) {
Session["SelectedSubMenu"] = "AlgorithmClass";
AlgorithmClassModel acm = new AlgorithmClassModel();
if (id != 0) {
acm.DeleteAlgorithmClass((long)id);
}
return View("Index", acm);
}//Delete
///
/// Controller for Detail View
///
///
public ActionResult SaveChanges(FormCollection collection) {
long algorithmClassId = long.Parse(collection.Get("AlgorithmClassId"));
String algorithmClassName = collection.Get("AlgorithmClassName");
String algorithmClassDescription = collection.Get("AlgorithmClassDescription");
// Later, we will get the runs from the session ...
AlgorithmClassModel acm = new AlgorithmClassModel();
if (algorithmClassId != 0)
acm.AlgorithmClass = (AlgorithmClass)acm.AlgorithmClasses.Where(x => x.Id.Equals(algorithmClassId)).FirstOrDefault();
acm.AlgorithmClass.Name = algorithmClassName;
acm.AlgorithmClass.Description = algorithmClassDescription;
acm.SaveAlgorithmClass(acm.AlgorithmClass);
return View("Index", acm);
}//SaveChanges
///
/// Controller for Index View
///
///
public ActionResult SortAsc() {
Session["SelectedSubMenu"] = "AlgorithmClass";
AlgorithmClassModel acm = new AlgorithmClassModel();
acm.AlgorithmClasses = acm.AlgorithmClasses.OrderBy(x => x.Name).ToList();
return View("Index", acm);
}
///
/// Controller for Index View
///
///
public ActionResult SortDesc() {
Session["SelectedSubMenu"] = "AlgorithmClass";
AlgorithmClassModel acm = new AlgorithmClassModel();
IOrderedEnumerable acmOrderedList = acm.AlgorithmClasses.OrderByDescending(x => x.Name);
IList acmList = new List();
foreach (var item in acmOrderedList) {
acmList.Add(item);
}
acm.AlgorithmClasses = acmList;
// this should be the right code
//pm.Problems = pm.Problems.OrderByDescending(x => x.Name).ToArray();
return View("Index", acm);
}
}
}