Exemplo n.º 1
0
        public ActionResult Edit(ProblemViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //If the id is 0, we're creating a new problem
                    if (model.Problem.Id == 0)
                        model.Problem.Id = GlobalStaticVars.StaticCore.AddProblem(model.Problem);
                    //Otherwise we're editing an existing problem
                    else
                        GlobalStaticVars.StaticCore.ModifyProblem(model.Problem);

                    GlobalStaticVars.StaticCore.UpdateProblemSets(model.Problem.Id, model.Sets);

                    //This is necessary in case bad prereqs (ex. duplicates) are removed by the backend
                    model.Sets = GlobalStaticVars.StaticCore.GetSetsForProblem(model.Problem.Id);
                }
                ViewBag.IsInstructor = ((UserType)Session["UserType"]) == UserType.Instructor;
                ModelState.Clear();
                return View(model);
            }
            catch (Exception e)
            {
                return RedirectToAction("ServerError", "Error");
            }
        }
Exemplo n.º 2
0
 public ActionResult Edit(int id = 0)
 {
     try
     {
         ProblemViewModel model = new ProblemViewModel();
         //If the id is 0, we're creating a new problem
         if (id == 0)
         {
             model.Problem = new ProblemData();
             model.Problem.Class = new ClassData((int) Session["ClassId"]);
         }
         //Otherwise we're editing an existing problem
         else
         {
             model.Problem = GlobalStaticVars.StaticCore.GetProblemById(id);
             model.Sets = GlobalStaticVars.StaticCore.GetSetsForProblem(id);
         }
         ViewBag.IsInstructor = ((UserType) Session["UserType"]) == UserType.Instructor;
         return View(model);
     }
     catch (Exception e)
     {
         return RedirectToAction("ServerError", "Error");
     }
 }