Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Controllers/ProblemController.cs @ 6162

Last change on this file since 6162 was 6162, checked in by gschwarz, 13 years ago

#1433 Updated Problem Control/View

File size: 3.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.Mvc;
6using HLWebOKBAdminPlugin.Models;
7using HLWebOKBAdminPlugin.OKBAdministrationService;
8
9namespace 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
27        /// <summary>
28        /// Controller for Index View
29        /// </summary>
30        /// <returns></returns>
31        public ActionResult SortAsc() {
32            Session["SelectedSubMenu"] = "Problem";
33            ProblemModel pm = new ProblemModel();
34            pm.Problems = pm.Problems.OrderBy(x => x.Name).ToList<Problem>();
35            return View("Index",pm);
36        }
37
38        /// <summary>
39        /// Controller for Index View
40        /// </summary>
41        /// <returns></returns>
42        public ActionResult SortDesc() {
43            Session["SelectedSubMenu"] = "Problem";
44            ProblemModel pm = new ProblemModel();
45            pm.Problems = pm.Problems.OrderByDescending(x => x.Name).ToArray<Problem>();
46            return View("Index",pm);
47        }
48        /// <summary>
49        /// Controller for Detail View
50        /// </summary>
51        /// <param name="p"></param>
52        /// <returns></returns>
53    public ActionResult Detail(long? id)
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();
59            if(id == null)
60                pm.Problem = new Problem();
61            else
62                pm.Problem = (Problem)pm.Problems.Where(x => x.Id.Equals((long)id)).FirstOrDefault();
63      return View(pm);
64    }
65
66        /// <summary>
67        /// Controller for Index View
68        /// </summary>
69        /// <returns></returns>
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) {
76                pm.DeleteProblem(id);
77            }
78            return View("Index", pm);
79        }
80
81        /// <summary>
82        /// Controller for Detail View
83        /// </summary>
84        /// <returns></returns>
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"));
91            long platformId = long.Parse(collection.Get("PlatformId"));
92
93            // Later, we will get the runs from the session ...
94            ProblemModel pm = new ProblemModel();
95            if(problemId != 0)
96                pm.Problem = (Problem)pm.Problems.Where(x => x.Id.Equals(problemId)).FirstOrDefault();
97
98            pm.Problem.Name = problemName;
99            pm.Problem.Description = problemDescription;
100            pm.Problem.DataTypeName = problemDataTypeName;
101            pm.Problem.DataTypeTypeName = "";
102            pm.Problem.ProblemClassId = problemClassId;
103            pm.Problem.PlatformId = platformId;
104
105            pm.SaveProblem(pm.Problem);
106
107            return View("Index",pm);
108        }
109  }
110}
Note: See TracBrowser for help on using the repository browser.