[6130] | 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 | namespace HLWebOKBAdminPlugin.Controllers
|
---|
| 10 | {
|
---|
| 11 | /// <summary>
|
---|
| 12 | /// Controller for Problem Submenu
|
---|
| 13 | /// </summary>
|
---|
| 14 | public class ProblemController : Controller
|
---|
| 15 | {
|
---|
| 16 | /// <summary>
|
---|
| 17 | /// Controller for Index View
|
---|
| 18 | /// </summary>
|
---|
| 19 | /// <returns></returns>
|
---|
| 20 | public ActionResult Index()
|
---|
| 21 | {
|
---|
| 22 | Session["SelectedSubMenu"] = "Problem";
|
---|
| 23 | ProblemModel pm = new ProblemModel();
|
---|
| 24 | return View(pm);
|
---|
| 25 | }
|
---|
| 26 |
|
---|
[6162] | 27 | /// <summary>
|
---|
| 28 | /// Controller for Index View
|
---|
| 29 | /// </summary>
|
---|
| 30 | /// <returns></returns>
|
---|
[6153] | 31 | public ActionResult SortAsc() {
|
---|
| 32 | Session["SelectedSubMenu"] = "Problem";
|
---|
| 33 | ProblemModel pm = new ProblemModel();
|
---|
[6162] | 34 | pm.Problems = pm.Problems.OrderBy(x => x.Name).ToList<Problem>();
|
---|
[6153] | 35 | return View("Index",pm);
|
---|
| 36 | }
|
---|
| 37 |
|
---|
[6162] | 38 | /// <summary>
|
---|
| 39 | /// Controller for Index View
|
---|
| 40 | /// </summary>
|
---|
| 41 | /// <returns></returns>
|
---|
[6153] | 42 | public ActionResult SortDesc() {
|
---|
| 43 | Session["SelectedSubMenu"] = "Problem";
|
---|
| 44 | ProblemModel pm = new ProblemModel();
|
---|
[6162] | 45 | pm.Problems = pm.Problems.OrderByDescending(x => x.Name).ToArray<Problem>();
|
---|
[6153] | 46 | return View("Index",pm);
|
---|
| 47 | }
|
---|
[6130] | 48 | /// <summary>
|
---|
| 49 | /// Controller for Detail View
|
---|
| 50 | /// </summary>
|
---|
| 51 | /// <param name="p"></param>
|
---|
| 52 | /// <returns></returns>
|
---|
[6153] | 53 | public ActionResult Detail(long? id)
|
---|
[6130] | 54 | {
|
---|
| 55 | Session["SelectedSubMenu"] = "Problem";
|
---|
| 56 | // We use here the ProblemMode, but I think
|
---|
| 57 | // we can also use the Problem class. (?)
|
---|
| 58 | ProblemModel pm = new ProblemModel();
|
---|
[6153] | 59 | if(id == null)
|
---|
[6142] | 60 | pm.Problem = new Problem();
|
---|
| 61 | else
|
---|
[6153] | 62 | pm.Problem = (Problem)pm.Problems.Where(x => x.Id.Equals((long)id)).FirstOrDefault();
|
---|
[6130] | 63 | return View(pm);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[6162] | 66 | /// <summary>
|
---|
| 67 | /// Controller for Index View
|
---|
| 68 | /// </summary>
|
---|
| 69 | /// <returns></returns>
|
---|
[6153] | 70 | public ActionResult Delete(long id) {
|
---|
| 71 | Session["SelectedSubMenu"] = "Problem";
|
---|
| 72 | // We use here the ProblemMode, but I think
|
---|
| 73 | // we can also use the Problem class. (?)
|
---|
| 74 | ProblemModel pm = new ProblemModel();
|
---|
| 75 | if(id != 0) {
|
---|
[6162] | 76 | pm.DeleteProblem(id);
|
---|
[6153] | 77 | }
|
---|
[6162] | 78 | return View("Index", pm);
|
---|
[6153] | 79 | }
|
---|
| 80 |
|
---|
[6162] | 81 | /// <summary>
|
---|
| 82 | /// Controller for Detail View
|
---|
| 83 | /// </summary>
|
---|
| 84 | /// <returns></returns>
|
---|
[6142] | 85 | public ActionResult SaveChanges(FormCollection collection) {
|
---|
| 86 | long problemId = long.Parse(collection.Get("ProblemId"));
|
---|
| 87 | String problemName = collection.Get("ProblemName");
|
---|
| 88 | String problemDescription = collection.Get("ProblemDescription");
|
---|
| 89 | String problemDataTypeName = collection.Get("ProblemDataTypeName");
|
---|
| 90 | long problemClassId = long.Parse(collection.Get("ProblemClassId"));
|
---|
[6159] | 91 | long platformId = long.Parse(collection.Get("PlatformId"));
|
---|
[6142] | 92 |
|
---|
| 93 | // Later, we will get the runs from the session ...
|
---|
| 94 | ProblemModel pm = new ProblemModel();
|
---|
[6162] | 95 | if(problemId != 0)
|
---|
[6159] | 96 | pm.Problem = (Problem)pm.Problems.Where(x => x.Id.Equals(problemId)).FirstOrDefault();
|
---|
[6142] | 97 |
|
---|
| 98 | pm.Problem.Name = problemName;
|
---|
| 99 | pm.Problem.Description = problemDescription;
|
---|
| 100 | pm.Problem.DataTypeName = problemDataTypeName;
|
---|
[6162] | 101 | pm.Problem.DataTypeTypeName = "";
|
---|
[6142] | 102 | pm.Problem.ProblemClassId = problemClassId;
|
---|
[6159] | 103 | pm.Problem.PlatformId = platformId;
|
---|
[6142] | 104 |
|
---|
| 105 | pm.SaveProblem(pm.Problem);
|
---|
| 106 |
|
---|
| 107 | return View("Index",pm);
|
---|
| 108 | }
|
---|
[6130] | 109 | }
|
---|
| 110 | }
|
---|