[6246] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Web;
|
---|
| 5 | using System.Web.Mvc;
|
---|
| 6 | using HLWebOKBAdminPlugin.Models;
|
---|
| 7 | using HLWebOKBAdminPlugin.OKBAdministrationService;
|
---|
| 8 |
|
---|
| 9 |
|
---|
[6317] | 10 | namespace HLWebOKBAdminPlugin.Controllers {
|
---|
| 11 | // <summary>
|
---|
| 12 | // Controller for ProblemClass Submenu
|
---|
| 13 | // </summary>
|
---|
| 14 | public class ProblemClassController : Controller {
|
---|
| 15 | //
|
---|
| 16 | // GET: /ProblemClass/
|
---|
[6246] | 17 |
|
---|
[6317] | 18 | public ActionResult Index() {
|
---|
| 19 | Session["SelectedSubMenu"] = "ProblemClass";
|
---|
| 20 | ProblemClassModel pcm = new ProblemClassModel();
|
---|
| 21 | return View(pcm);
|
---|
| 22 | }//Index
|
---|
[6246] | 23 |
|
---|
[6317] | 24 | public ActionResult Detail(long? id) {
|
---|
| 25 | Session["SelectedSubMenu"] = "ProblemClass";
|
---|
| 26 | ProblemClassModel pcm = new ProblemClassModel();
|
---|
[6246] | 27 |
|
---|
[6317] | 28 | if (id == null)
|
---|
| 29 | pcm.ProblemClass = new ProblemClass();
|
---|
| 30 | else
|
---|
| 31 | pcm.ProblemClass = (ProblemClass)pcm.ProblemClasses.Where(x => x.Id.Equals((long)id)).FirstOrDefault();
|
---|
| 32 | return View(pcm);
|
---|
| 33 | }//Detail
|
---|
[6246] | 34 |
|
---|
[6317] | 35 | /// <summary>
|
---|
| 36 | /// Controller for Index View
|
---|
| 37 | /// </summary>
|
---|
| 38 | /// <returns></returns>
|
---|
| 39 | public ActionResult Delete(long? id) {
|
---|
| 40 | Session["SelectedSubMenu"] = "ProblemClass";
|
---|
[6246] | 41 |
|
---|
[6317] | 42 | ProblemClassModel pcm = new ProblemClassModel();
|
---|
| 43 | if (id != 0) {
|
---|
| 44 | pcm.DeleteProblemClass((long)id);
|
---|
| 45 | }
|
---|
| 46 | return View("Index", pcm);
|
---|
| 47 | }//Delete
|
---|
[6246] | 48 |
|
---|
[6317] | 49 | /// <summary>
|
---|
| 50 | /// Controller for Detail View
|
---|
| 51 | /// </summary>
|
---|
| 52 | /// <returns></returns>
|
---|
| 53 | public ActionResult SaveChanges(FormCollection collection) {
|
---|
| 54 | long problemClassId = long.Parse(collection.Get("ProblemClassId"));
|
---|
| 55 | String problemClassName = collection.Get("ProblemClassName");
|
---|
| 56 | String problemClassDescription = collection.Get("ProblemClassDescription");
|
---|
[6246] | 57 |
|
---|
[6317] | 58 | // Later, we will get the runs from the session ...
|
---|
| 59 | ProblemClassModel pcm = new ProblemClassModel();
|
---|
| 60 | if (problemClassId != 0)
|
---|
| 61 | pcm.ProblemClass = (ProblemClass)pcm.ProblemClasses.Where(x => x.Id.Equals(problemClassId)).FirstOrDefault();
|
---|
[6246] | 62 |
|
---|
[6317] | 63 | pcm.ProblemClass.Name = problemClassName;
|
---|
| 64 | pcm.ProblemClass.Description = problemClassDescription;
|
---|
[6246] | 65 |
|
---|
[6317] | 66 | pcm.SaveProblemClass(pcm.ProblemClass);
|
---|
[6246] | 67 |
|
---|
[6317] | 68 | return View("Index", pcm);
|
---|
| 69 | }//SaveChanges
|
---|
[6246] | 70 |
|
---|
[6317] | 71 | /// <summary>
|
---|
| 72 | /// Controller for Index View
|
---|
| 73 | /// </summary>
|
---|
| 74 | /// <returns></returns>
|
---|
| 75 | public ActionResult SortAsc() {
|
---|
| 76 | Session["SelectedSubMenu"] = "ProblemClass";
|
---|
| 77 | ProblemClassModel pcm = new ProblemClassModel();
|
---|
| 78 | pcm.ProblemClasses = pcm.ProblemClasses.OrderBy(x => x.Name).ToList<ProblemClass>();
|
---|
| 79 | return View("Index", pcm);
|
---|
| 80 | }
|
---|
[6246] | 81 |
|
---|
[6317] | 82 | /// <summary>
|
---|
| 83 | /// Controller for Index View
|
---|
| 84 | /// </summary>
|
---|
| 85 | /// <returns></returns>
|
---|
| 86 | public ActionResult SortDesc() {
|
---|
| 87 | Session["SelectedSubMenu"] = "ProblemClass";
|
---|
| 88 | ProblemClassModel pcm = new ProblemClassModel();
|
---|
[6246] | 89 |
|
---|
[6317] | 90 | IOrderedEnumerable<ProblemClass> pcmOrderedList = pcm.ProblemClasses.OrderByDescending(x => x.Name);
|
---|
| 91 | IList<ProblemClass> pcmList = new List<ProblemClass>();
|
---|
| 92 | foreach (var item in pcmOrderedList) {
|
---|
| 93 | pcmList.Add(item);
|
---|
| 94 | }
|
---|
| 95 | pcm.ProblemClasses = pcmList;
|
---|
[6246] | 96 |
|
---|
[6317] | 97 | // this should be the right code
|
---|
| 98 | //pm.Problems = pm.Problems.OrderByDescending(x => x.Name).ToArray<Problem>();
|
---|
| 99 | return View("Index", pcm);
|
---|
| 100 | }
|
---|
[6246] | 101 |
|
---|
[6317] | 102 | }
|
---|
[6246] | 103 | }
|
---|