Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 6159 was 6159, checked in by gschwarz, 12 years ago

#1433 Updated Problem Controller fixed bug in saveProblem.

File size: 3.3 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        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        }
40        /// <summary>
41        /// Controller for Detail View
42        /// </summary>
43        /// <param name="p"></param>
44        /// <returns></returns>
45    public ActionResult Detail(long? id)
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();
51            if(id == null)
52                pm.Problem = new Problem();
53            else
54                pm.Problem = (Problem)pm.Problems.Where(x => x.Id.Equals((long)id)).FirstOrDefault();
55      return View(pm);
56    }
57
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
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"));
76            long platformId = long.Parse(collection.Get("PlatformId"));
77
78            // Later, we will get the runs from the session ...
79            ProblemModel pm = new ProblemModel();
80            if( problemId != 0 )
81                pm.Problem = (Problem)pm.Problems.Where(x => x.Id.Equals(problemId)).FirstOrDefault();
82
83            pm.Problem.Name = problemName;
84            pm.Problem.Description = problemDescription;
85            pm.Problem.DataTypeName = problemDataTypeName;
86            pm.Problem.ProblemClassId = problemClassId;
87            pm.Problem.PlatformId = platformId;
88
89            pm.SaveProblem(pm.Problem);
90
91            return View("Index",pm);
92        }
93  }
94}
Note: See TracBrowser for help on using the repository browser.