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 Problem Submenu
///
public class ProblemController : Controller
{
///
/// Controller for Index View
///
///
public ActionResult Index()
{
Session["SelectedSubMenu"] = "Problem";
ProblemModel pm = new ProblemModel();
return View(pm);
}
///
/// Controller for Index View
///
///
public ActionResult SortAsc() {
Session["SelectedSubMenu"] = "Problem";
ProblemModel pm = new ProblemModel();
pm.Problems = pm.Problems.OrderBy(x => x.Name).ToList();
return View("Index",pm);
}
///
/// Controller for Index View
///
///
public ActionResult SortDesc() {
Session["SelectedSubMenu"] = "Problem";
ProblemModel pm = new ProblemModel();
pm.Problems = pm.Problems.OrderByDescending(x => x.Name).ToArray();
return View("Index",pm);
}
///
/// Controller for Detail View
///
///
///
public ActionResult Detail(long? id)
{
Session["SelectedSubMenu"] = "Problem";
// We use here the ProblemMode, but I think
// we can also use the Problem class. (?)
ProblemModel pm = new ProblemModel();
if(id == null)
pm.Problem = new Problem();
else
pm.Problem = (Problem)pm.Problems.Where(x => x.Id.Equals((long)id)).FirstOrDefault();
return View(pm);
}
///
/// Controller for Index View
///
///
public ActionResult Delete(long id) {
Session["SelectedSubMenu"] = "Problem";
// We use here the ProblemMode, but I think
// we can also use the Problem class. (?)
ProblemModel pm = new ProblemModel();
if(id != 0) {
pm.DeleteProblem(id);
}
return View("Index", pm);
}
///
/// Controller for Detail View
///
///
public ActionResult SaveChanges(FormCollection collection) {
long problemId = long.Parse(collection.Get("ProblemId"));
String problemName = collection.Get("ProblemName");
String problemDescription = collection.Get("ProblemDescription");
String problemDataTypeName = collection.Get("ProblemDataTypeName");
long problemClassId = long.Parse(collection.Get("ProblemClassId"));
long platformId = long.Parse(collection.Get("PlatformId"));
// Later, we will get the runs from the session ...
ProblemModel pm = new ProblemModel();
if(problemId != 0)
pm.Problem = (Problem)pm.Problems.Where(x => x.Id.Equals(problemId)).FirstOrDefault();
pm.Problem.Name = problemName;
pm.Problem.Description = problemDescription;
pm.Problem.DataTypeName = problemDataTypeName;
pm.Problem.DataTypeTypeName = "";
pm.Problem.ProblemClassId = problemClassId;
pm.Problem.PlatformId = platformId;
pm.SaveProblem(pm.Problem);
return View("Index",pm);
}
}
}