Exemplo n.º 1
0
 public ActionResult Edit(int classId, int problemSetId = 0)
 {
     try
     {
         if ((int) Session["ClassId"] != classId || (UserType) Session["UserType"] != UserType.Instructor)
         {
             return RedirectToAction("Unauthorized", "Error");
         }
         ProblemSetViewModel model = new ProblemSetViewModel();
         if (problemSetId == 0) //Create a new set
         {
             model.Set = new ProblemSetData();
             model.Set.Class = new ClassData((int) Session["ClassId"]);
         }
         else if (problemSetId == -1) //View the unassigned set
         {
             ProblemSetData unassigned = new ProblemSetData(-1);
             unassigned.Name = "Unassigned Problems";
             unassigned.Class = new ClassData((int) Session["ClassId"]);
             model.Set = unassigned;
             model.Problems = GlobalStaticVars.StaticCore.GetProblemsForSet(model.Set);
         }
         else //Edit a set normally
         {
             model.Set = GlobalStaticVars.StaticCore.GetSetById(problemSetId);
             model.Prereqs = GlobalStaticVars.StaticCore.GetSetPrereqs(problemSetId);
             model.Problems = GlobalStaticVars.StaticCore.GetProblemsForSet(model.Set);
         }
         return View(model);
     }
     catch (Exception e)
     {
         return RedirectToAction("ServerError", "Error");
     }
 }
Exemplo n.º 2
0
        public ActionResult Edit(ProblemSetViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (model.Set.Id == 0)
                        model.Set.Id = GlobalStaticVars.StaticCore.AddSet(model.Set);
                    else
                        GlobalStaticVars.StaticCore.ModifySet(model.Set);
                    GlobalStaticVars.StaticCore.UpdateSetPrereqs(model.Set.Id, model.Prereqs);

                    //This is necessary in case bad prereqs (ex. duplicates) are removed by the backend
                    model.Prereqs = GlobalStaticVars.StaticCore.GetSetPrereqs(model.Set.Id);
                }
                ModelState.Clear();
                return View(model);
            }
            catch (Exception e)
            {
                return RedirectToAction("ServerError", "Error");
            }
        }