Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 6246 was 6246, checked in by wtollsch, 13 years ago

#1433 AlgorithmClass, Algorithm, ProblemClass, Problem create/update appropriate controller/models/views, File upload (Algorithm / Problem)

File size: 3.7 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{
12    // <summary>
13    // Controller for ProblemClass Submenu
14    // </summary>
15    public class ProblemClassController : Controller
16    {
17        //
18        // GET: /ProblemClass/
19
20        public ActionResult Index()
21        {
22            Session["SelectedSubMenu"] = "ProblemClass";
23            ProblemClassModel pcm = new ProblemClassModel();
24            return View(pcm);
25        }//Index
26
27        public ActionResult Detail(long? id) {
28            Session["SelectedSubMenu"] = "ProblemClass";
29            ProblemClassModel pcm = new ProblemClassModel();
30
31            if (id == null)
32                pcm.ProblemClass = new ProblemClass();
33            else
34                pcm.ProblemClass = (ProblemClass)pcm.ProblemClasses.Where(x => x.Id.Equals((long)id)).FirstOrDefault();
35            return View(pcm);
36        }//Detail
37
38        /// <summary>
39        /// Controller for Index View
40        /// </summary>
41        /// <returns></returns>
42        public ActionResult Delete(long? id) {
43            Session["SelectedSubMenu"] = "ProblemClass";
44
45            ProblemClassModel pcm = new ProblemClassModel();
46            if (id != 0) {
47                pcm.DeleteProblemClass((long)id);
48            }
49            return View("Index", pcm);
50        }//Delete
51
52        /// <summary>
53        /// Controller for Detail View
54        /// </summary>
55        /// <returns></returns>
56        public ActionResult SaveChanges(FormCollection collection) {
57            long problemClassId = long.Parse(collection.Get("ProblemClassId"));
58            String problemClassName = collection.Get("ProblemClassName");
59            String problemClassDescription = collection.Get("ProblemClassDescription");
60
61            // Later, we will get the runs from the session ...
62            ProblemClassModel pcm = new ProblemClassModel();
63            if (problemClassId != 0)
64                pcm.ProblemClass = (ProblemClass)pcm.ProblemClasses.Where(x => x.Id.Equals(problemClassId)).FirstOrDefault();
65
66            pcm.ProblemClass.Name = problemClassName;
67            pcm.ProblemClass.Description = problemClassDescription;
68
69            pcm.SaveProblemClass(pcm.ProblemClass);
70
71            return View("Index", pcm);
72        }//SaveChanges
73
74        /// <summary>
75        /// Controller for Index View
76        /// </summary>
77        /// <returns></returns>
78        public ActionResult SortAsc() {
79            Session["SelectedSubMenu"] = "ProblemClass";
80            ProblemClassModel pcm = new ProblemClassModel();
81            pcm.ProblemClasses = pcm.ProblemClasses.OrderBy(x => x.Name).ToList<ProblemClass>();
82            return View("Index", pcm);
83        }
84
85        /// <summary>
86        /// Controller for Index View
87        /// </summary>
88        /// <returns></returns>
89        public ActionResult SortDesc() {
90            Session["SelectedSubMenu"] = "ProblemClass";
91            ProblemClassModel pcm = new ProblemClassModel();
92
93            IOrderedEnumerable<ProblemClass> pcmOrderedList = pcm.ProblemClasses.OrderByDescending(x => x.Name);
94            IList<ProblemClass> pcmList = new List<ProblemClass>();
95            foreach (var item in pcmOrderedList) {
96                pcmList.Add(item);
97            }
98            pcm.ProblemClasses = pcmList;
99
100            // this should be the right code
101            //pm.Problems = pm.Problems.OrderByDescending(x => x.Name).ToArray<Problem>();
102            return View("Index", pcm);
103        }
104
105    }
106}
Note: See TracBrowser for help on using the repository browser.