Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Controllers/ProblemClassController.cs @ 11813

Last change on this file since 11813 was 6317, checked in by jwolfing, 14 years ago

#1433 code formatted

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
9
10namespace HLWebOKBAdminPlugin.Controllers {
11  // <summary>
12  // Controller for ProblemClass Submenu
13  // </summary>
14  public class ProblemClassController : Controller {
15    //
16    // GET: /ProblemClass/
17
18    public ActionResult Index() {
19      Session["SelectedSubMenu"] = "ProblemClass";
20      ProblemClassModel pcm = new ProblemClassModel();
21      return View(pcm);
22    }//Index
23
24    public ActionResult Detail(long? id) {
25      Session["SelectedSubMenu"] = "ProblemClass";
26      ProblemClassModel pcm = new ProblemClassModel();
27
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
34
35    /// <summary>
36    /// Controller for Index View
37    /// </summary>
38    /// <returns></returns>
39    public ActionResult Delete(long? id) {
40      Session["SelectedSubMenu"] = "ProblemClass";
41
42      ProblemClassModel pcm = new ProblemClassModel();
43      if (id != 0) {
44        pcm.DeleteProblemClass((long)id);
45      }
46      return View("Index", pcm);
47    }//Delete
48
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");
57
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();
62
63      pcm.ProblemClass.Name = problemClassName;
64      pcm.ProblemClass.Description = problemClassDescription;
65
66      pcm.SaveProblemClass(pcm.ProblemClass);
67
68      return View("Index", pcm);
69    }//SaveChanges
70
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    }
81
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();
89
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;
96
97      // this should be the right code
98      //pm.Problems = pm.Problems.OrderByDescending(x => x.Name).ToArray<Problem>();
99      return View("Index", pcm);
100    }
101
102  }
103}
Note: See TracBrowser for help on using the repository browser.