[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 |
|
---|
[6153] | 27 | public ActionResult SortAsc() {
|
---|
| 28 | Session["SelectedSubMenu"] = "Problem";
|
---|
| 29 | ProblemModel pm = new ProblemModel();
|
---|
| 30 | pm.Problems.OrderBy(x => x.Name);
|
---|
| 31 | return View("Index",pm);
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | public ActionResult SortDesc() {
|
---|
| 35 | Session["SelectedSubMenu"] = "Problem";
|
---|
| 36 | ProblemModel pm = new ProblemModel();
|
---|
| 37 | pm.Problems.OrderByDescending(x => x.Name);
|
---|
| 38 | return View("Index",pm);
|
---|
| 39 | }
|
---|
[6130] | 40 | /// <summary>
|
---|
| 41 | /// Controller for Detail View
|
---|
| 42 | /// </summary>
|
---|
| 43 | /// <param name="p"></param>
|
---|
| 44 | /// <returns></returns>
|
---|
[6153] | 45 | public ActionResult Detail(long? id)
|
---|
[6130] | 46 | {
|
---|
| 47 | Session["SelectedSubMenu"] = "Problem";
|
---|
| 48 | // We use here the ProblemMode, but I think
|
---|
| 49 | // we can also use the Problem class. (?)
|
---|
| 50 | ProblemModel pm = new ProblemModel();
|
---|
[6153] | 51 | if(id == null)
|
---|
[6142] | 52 | pm.Problem = new Problem();
|
---|
| 53 | else
|
---|
[6153] | 54 | pm.Problem = (Problem)pm.Problems.Where(x => x.Id.Equals((long)id)).FirstOrDefault();
|
---|
[6130] | 55 | return View(pm);
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[6153] | 58 | public ActionResult Delete(long id) {
|
---|
| 59 | Session["SelectedSubMenu"] = "Problem";
|
---|
| 60 | // We use here the ProblemMode, but I think
|
---|
| 61 | // we can also use the Problem class. (?)
|
---|
| 62 | ProblemModel pm = new ProblemModel();
|
---|
| 63 | if(id != 0) {
|
---|
| 64 | pm.Problem = (Problem)pm.Problems.Where(x => x.Id.Equals(id)).FirstOrDefault();
|
---|
| 65 | // pm.DeleteProblem();
|
---|
| 66 | }
|
---|
| 67 | return View(pm);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[6142] | 70 | public ActionResult SaveChanges(FormCollection collection) {
|
---|
| 71 | long problemId = long.Parse(collection.Get("ProblemId"));
|
---|
| 72 | String problemName = collection.Get("ProblemName");
|
---|
| 73 | String problemDescription = collection.Get("ProblemDescription");
|
---|
| 74 | String problemDataTypeName = collection.Get("ProblemDataTypeName");
|
---|
| 75 | long problemClassId = long.Parse(collection.Get("ProblemClassId"));
|
---|
[6159] | 76 | long platformId = long.Parse(collection.Get("PlatformId"));
|
---|
[6142] | 77 |
|
---|
| 78 | // Later, we will get the runs from the session ...
|
---|
| 79 | ProblemModel pm = new ProblemModel();
|
---|
[6159] | 80 | if( problemId != 0 )
|
---|
| 81 | pm.Problem = (Problem)pm.Problems.Where(x => x.Id.Equals(problemId)).FirstOrDefault();
|
---|
[6142] | 82 |
|
---|
| 83 | pm.Problem.Name = problemName;
|
---|
| 84 | pm.Problem.Description = problemDescription;
|
---|
| 85 | pm.Problem.DataTypeName = problemDataTypeName;
|
---|
| 86 | pm.Problem.ProblemClassId = problemClassId;
|
---|
[6159] | 87 | pm.Problem.PlatformId = platformId;
|
---|
[6142] | 88 |
|
---|
| 89 | pm.SaveProblem(pm.Problem);
|
---|
| 90 |
|
---|
| 91 | return View("Index",pm);
|
---|
| 92 | }
|
---|
[6130] | 93 | }
|
---|
| 94 | }
|
---|