Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/27/11 19:09:49 (13 years ago)
Author:
jwolfing
Message:

#1433 code formatted

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/WebApplication/MVC2/HLWebOKBAdminPlugin/Controllers/ProblemController.cs

    r6283 r6317  
    88using System.IO;
    99
    10 namespace HLWebOKBAdminPlugin.Controllers
    11 {
     10namespace HLWebOKBAdminPlugin.Controllers {
     11  /// <summary>
     12  /// Controller for Problem Submenu
     13  /// </summary>
     14  public class ProblemController : Controller {
    1215    /// <summary>
    13     /// Controller for Problem Submenu
     16    /// Controller for Index View
    1417    /// </summary>
    15   public class ProblemController : Controller
    16   {
    17     /// <summary>
    18     /// Controller for Index View
    19     /// </summary>
    20     /// <returns></returns>
    21     public ActionResult Index()
    22         {
    23             Session["SelectedSubMenu"] = "Problem";
    24             ProblemModel pm = new ProblemModel();
    25       return View(pm);
    26     }
     18    /// <returns></returns>
     19    public ActionResult Index() {
     20      Session["SelectedSubMenu"] = "Problem";
     21      ProblemModel pm = new ProblemModel();
     22      return View(pm);
     23    }
    2724
    28         /// <summary>
    29         /// Controller for Index View
    30         /// </summary>
    31         /// <returns></returns>
    32         public ActionResult SortAsc() {
    33             Session["SelectedSubMenu"] = "Problem";
    34             ProblemModel pm = new ProblemModel();
    35             pm.Problems = pm.Problems.OrderBy(x => x.Name).ToList<Problem>();
    36             return View("Index",pm);
     25    /// <summary>
     26    /// Controller for Index View
     27    /// </summary>
     28    /// <returns></returns>
     29    public ActionResult SortAsc() {
     30      Session["SelectedSubMenu"] = "Problem";
     31      ProblemModel pm = new ProblemModel();
     32      pm.Problems = pm.Problems.OrderBy(x => x.Name).ToList<Problem>();
     33      return View("Index", pm);
     34    }
     35
     36    /// <summary>
     37    /// Controller for Index View
     38    /// </summary>
     39    /// <returns></returns>
     40    public ActionResult SortDesc() {
     41      Session["SelectedSubMenu"] = "Problem";
     42      ProblemModel pm = new ProblemModel();
     43
     44      //this is code for testing sortorder
     45      IOrderedEnumerable<Problem> test = pm.Problems.OrderByDescending(x => x.Name);
     46      IList<Problem> test2 = new List<Problem>();
     47      foreach (var item in test) {
     48        test2.Add(item);
     49      }
     50      pm.Problems = test2;
     51
     52      // this should be the right code
     53      //pm.Problems = pm.Problems.OrderByDescending(x => x.Name).ToArray<Problem>();
     54      return View("Index", pm);
     55    }
     56    /// <summary>
     57    /// Controller for Detail View
     58    /// </summary>
     59    /// <param name="p"></param>
     60    /// <returns></returns>
     61    public ActionResult Detail(long? id) {
     62      Session["SelectedSubMenu"] = "Problem";
     63      // We use here the ProblemMode, but I think
     64      // we can also use the Problem class. (?)
     65      ProblemModel pm = new ProblemModel();
     66      if (id == null)
     67        pm.Problem = new Problem();
     68      else
     69        pm.Problem = (Problem)pm.Problems.Where(x => x.Id.Equals((long)id)).FirstOrDefault();
     70      return View(pm);
     71    }
     72
     73    /// <summary>
     74    /// Controller for Index View
     75    /// </summary>
     76    /// <returns></returns>
     77    public ActionResult Delete(long id) {
     78      Session["SelectedSubMenu"] = "Problem";
     79      // We use here the ProblemMode, but I think
     80      // we can also use the Problem class. (?)
     81      ProblemModel pm = new ProblemModel();
     82      if (id != 0) {
     83        pm.DeleteProblem(id);
     84      }
     85      return View("Index", pm);
     86    }
     87
     88    public ActionResult UploadFile(FormCollection collection) {
     89      Session["SelectedSubMenu"] = "Problem";
     90
     91      long problemId = long.Parse(collection.Get("ProblemId"));
     92
     93      ProblemModel pm = new ProblemModel();
     94
     95      foreach (string inputTagName in Request.Files) {
     96        HttpPostedFileBase file = Request.Files[inputTagName];
     97        if (file.ContentLength > 0) {
     98          // maybe for storage on server
     99          //string filePath = Path.Combine(HttpContext.Server.MapPath("../Uploads"), Path.GetFileName(file.FileName));
     100          if (file.InputStream.CanRead) {
     101            //file length
     102            int fileLength = file.ContentLength;
     103
     104            //bytearray
     105            byte[] data = new byte[fileLength];
     106
     107            //initialize input stream
     108            Stream dataStream = file.InputStream;
     109
     110            //read file into byte array
     111            dataStream.Read(data, 0, fileLength);
     112
     113            //save data
     114            pm.UpdateProblemData(problemId, data);
     115          }//if
    37116        }
     117      }//foreach
    38118
    39         /// <summary>
    40         /// Controller for Index View
    41         /// </summary>
    42         /// <returns></returns>
    43         public ActionResult SortDesc() {
    44             Session["SelectedSubMenu"] = "Problem";
    45             ProblemModel pm = new ProblemModel();
     119      return View("Index", pm);
     120    }//UploadFile
    46121
    47             //this is code for testing sortorder
    48             IOrderedEnumerable<Problem> test = pm.Problems.OrderByDescending(x => x.Name);
    49             IList<Problem> test2 = new List<Problem>();
    50             foreach(var item in test) {
    51                 test2.Add(item);
    52             }
    53             pm.Problems = test2;
     122    /// <summary>
     123    /// Controller for Detail View
     124    /// </summary>
     125    /// <returns></returns>
     126    public ActionResult SaveChanges(FormCollection collection) {
     127      long problemId = long.Parse(collection.Get("ProblemId"));
     128      String problemName = collection.Get("ProblemName");
     129      String problemDescription = collection.Get("ProblemDescription");
     130      String problemDataTypeName = collection.Get("ProblemDataTypeName");
     131      long problemClassId = long.Parse(collection.Get("ProblemClassId"));
     132      long platformId = long.Parse(collection.Get("PlatformId"));
    54133
    55             // this should be the right code
    56             //pm.Problems = pm.Problems.OrderByDescending(x => x.Name).ToArray<Problem>();
    57             return View("Index", pm);
    58         }
    59         /// <summary>
    60         /// Controller for Detail View
    61         /// </summary>
    62         /// <param name="p"></param>
    63         /// <returns></returns>
    64     public ActionResult Detail(long? id)
    65         {
    66             Session["SelectedSubMenu"] = "Problem";
    67             // We use here the ProblemMode, but I think
    68             // we can also use the Problem class. (?)
    69             ProblemModel pm = new ProblemModel();
    70             if(id == null)
    71                 pm.Problem = new Problem();
    72             else
    73                 pm.Problem = (Problem)pm.Problems.Where(x => x.Id.Equals((long)id)).FirstOrDefault();
    74       return View(pm);
    75     }
     134      // Later, we will get the runs from the session ...
     135      ProblemModel pm = new ProblemModel();
     136      if (problemId != 0)
     137        pm.Problem = (Problem)pm.Problems.Where(x => x.Id.Equals(problemId)).FirstOrDefault();
    76138
    77         /// <summary>
    78         /// Controller for Index View
    79         /// </summary>
    80         /// <returns></returns>
    81         public ActionResult Delete(long id) {
    82             Session["SelectedSubMenu"] = "Problem";
    83             // We use here the ProblemMode, but I think
    84             // we can also use the Problem class. (?)
    85             ProblemModel pm = new ProblemModel();
    86             if(id != 0) {
    87                 pm.DeleteProblem(id);
    88             }
    89             return View("Index", pm);
    90         }
    91        
    92         public ActionResult UploadFile(FormCollection collection) {
    93             Session["SelectedSubMenu"] = "Problem";
     139      pm.Problem.Name = problemName;
     140      pm.Problem.Description = problemDescription;
     141      pm.Problem.DataTypeName = problemDataTypeName;
     142      pm.Problem.DataTypeTypeName = "";
     143      pm.Problem.ProblemClassId = problemClassId;
     144      pm.Problem.PlatformId = platformId;
    94145
    95             long problemId = long.Parse(collection.Get("ProblemId"));           
     146      pm.SaveProblem(pm.Problem);
    96147
    97             ProblemModel pm = new ProblemModel();
    98 
    99             foreach (string inputTagName in Request.Files) {
    100                 HttpPostedFileBase file = Request.Files[inputTagName];
    101                 if (file.ContentLength > 0) {
    102                     // maybe for storage on server
    103                     //string filePath = Path.Combine(HttpContext.Server.MapPath("../Uploads"), Path.GetFileName(file.FileName));
    104                     if (file.InputStream.CanRead) {
    105                         //file length
    106                         int fileLength = file.ContentLength;
    107 
    108                         //bytearray
    109                         byte[] data = new byte[fileLength];
    110 
    111                         //initialize input stream
    112                         Stream dataStream = file.InputStream;
    113 
    114                         //read file into byte array
    115                         dataStream.Read(data, 0, fileLength);
    116 
    117                         //save data
    118                         pm.UpdateProblemData(problemId, data);
    119                     }//if
    120                 }
    121             }//foreach
    122 
    123             return View("Index", pm);
    124         }//UploadFile
    125 
    126         /// <summary>
    127         /// Controller for Detail View
    128         /// </summary>
    129         /// <returns></returns>
    130         public ActionResult SaveChanges(FormCollection collection) {           
    131             long problemId = long.Parse(collection.Get("ProblemId"));
    132             String problemName = collection.Get("ProblemName");
    133             String problemDescription = collection.Get("ProblemDescription");
    134             String problemDataTypeName = collection.Get("ProblemDataTypeName");
    135             long problemClassId = long.Parse(collection.Get("ProblemClassId"));
    136             long platformId = long.Parse(collection.Get("PlatformId"));
    137 
    138             // Later, we will get the runs from the session ...
    139             ProblemModel pm = new ProblemModel();
    140             if(problemId != 0)
    141                 pm.Problem = (Problem)pm.Problems.Where(x => x.Id.Equals(problemId)).FirstOrDefault();
    142 
    143             pm.Problem.Name = problemName;
    144             pm.Problem.Description = problemDescription;
    145             pm.Problem.DataTypeName = problemDataTypeName;
    146             pm.Problem.DataTypeTypeName = "";
    147             pm.Problem.ProblemClassId = problemClassId;
    148             pm.Problem.PlatformId = platformId;
    149 
    150             pm.SaveProblem(pm.Problem);
    151 
    152             return View("Index",pm);
    153         }
    154   }
     148      return View("Index", pm);
     149    }
     150  }
    155151}
Note: See TracChangeset for help on using the changeset viewer.