Exemplo n.º 1
0
        public virtual ActionResult Edit(ScenarioListForVotes collection)
        {
            var scenarioId = collection.ScenariosForVotes.Select(x => x.scenarioID).FirstOrDefault();
            var scenario = scenarioRepository.GetByID((int)scenarioId);
            var projID = scenario.ProjectID;

               try
            {
                int i = 0;
                foreach (var s in collection.ScenariosForVotes)  //for each scenario
                {
                    //get utility record
                    Scenario scenarioToUpdate = scenarioRepository.GetByID((int)s.scenarioID);
                    //want to save valid entries even if ModelState is not valid
                    //User may not want to fill out entire form at once.
                    if (s.Votes != null && scenarioToUpdate.Votes != s.Votes)
                    {   //update description
                        scenarioToUpdate.Votes = s.Votes;
                        i++;
                    }
                }//end foreach scenario
                scenarioRepository.Save();
                ModelStateHelpers.ModelMessage = i + " Record(s) Saved Successfully";

                //update complete status on steps
                var stepsRepository = new StepsRepository();
                stepsRepository.UpdateSteps(projID);
                stepsRepository.Save();

                if (ModelState.IsValid)
                {
                    var slist = populateScenatioListVotes(projID);  // return type ScenarioListForVotes
                    return View(slist);
                    // Message = "Saved Successfully";
                }
                else
                {

                    ModelState.AddModelError("ID", "Record not Added Sucessfully");

                    //var vmodel = ScenarioViewModel.TopThird(scenarioRepository);
                    return View(collection);
                }

            }//end try
            catch
            {
                ModelState.AddModelError("ID", "Record not Added Sucessfully");
                //var vmodel = ScenarioViewModel.TopThird(scenarioRepository);
                return View(collection);
            }
        }
Exemplo n.º 2
0
 public virtual ActionResult UpdatePriority(int[] priority)
 {
     Scenario s;
     var result = new jr { success = "true" };
     if (ModelState.IsValid)
     {
         try
         {
             for (int i = 0; i < priority.Length; i++)
             {
                  s = scenarioRepository.GetByID(priority[i]);
                  s.Priority = i + 1;
                  scenarioRepository.Save();
             }
             //update complete status on steps
             var stepsRepository = new StepsRepository();
             stepsRepository.UpdateSteps();
             stepsRepository.Save();
         }
         catch
         {//For Error w/o defined message
             ModelState.AddModelError("ID", "Not Added Sucessfully");
              result = new jr { success = "false" };
              return Json(result);
         }//end catch
     }//else not valid
     else ModelState.AddModelError("ID", "Record not Added Sucessfully");
     ModelState.Clear(); // this is the key, you could also just clear ModelState for the field
     var vmodel = ScenarioViewModel.CreateIndex(scenarioRepository);
     return View(vmodel);
 }
Exemplo n.º 3
0
        public virtual ActionResult UpdatePriority(int[] priority)
        {
            ModelState.Clear();

            //priority keeps coming in null, even though posted
            if (priority == null)
            {
                HttpContext ctx = System.Web.HttpContext.Current;
                string[] valArr = ctx.Request.Params.GetValues(0);
                Array.Resize(ref priority, valArr.Length);

                for (int i = 0; i < valArr.Length; i++)
                {
                    priority[i] = Convert.ToInt16(valArr[i]);
                }//end for
            }//end if

            Scenario s;
            s = scenarioRepository.GetByID(priority[1]);
            var result = new jr { success = "true" };
            if (ModelState.IsValid)
            {
                try
                {
                    for (int i = 0; i < priority.Length; i++)
                    {
                         s = scenarioRepository.GetByID(priority[i]);
                         s.Priority = i + 1;
                         scenarioRepository.Save();
                    }
                    //update complete status on steps
                    scenarioRepository.ClearVotesBottomTwoThirds(s.ProjectID);
                    var stepsRepository = new StepsRepository();
                    stepsRepository.UpdateSteps(s.ProjectID);
                    stepsRepository.Save();
                }
                catch
                {//For Error w/o defined message
                    ModelState.AddModelError("ID", "Not Added Sucessfully");
                    //var vmodelError = ScenarioViewModel.CreateIndex(scenarioRepository, s.ProjectID);
                    //return View(vmodelError);
                     result = new jr { success = "false" };
                     return Json(result);
                }//end catch
            }//else not valid
            else ModelState.AddModelError("ID", "Record not Added Sucessfully");
            ModelState.Clear(); // this is the key, you could also just clear ModelState for the field

            var vmodel = ScenarioViewModel.CreateIndex(scenarioRepository, s.Project.ID);
            var scenarios = vmodel.Scenarios;
            return PartialView("ScenarioList", scenarios);

            //return View(vmodel);
            //return Action (Index);
        }