public ArchitecturalStrategyViewModel(ArchitecturalStrategy strategy)
        {
            var scenarioRepository = new ScenarioRepository();
            var strategyRepository = new ArchitecturalStrategyRepository();
            Strategy = strategy;
            Strategy.Description = strategy.Description == null ? null : strategy.Description.Trim();

            AffiliatedScenarios = strategyRepository.GetAffiliatedScenariosByStratID(strategy.ID).OrderBy(x => x.Priority);

            //scenarios (in top 6th) not affiliated with strategy
            var slistNotUsed = scenarioRepository.GetTopSixth(strategy.ProjectID).OrderBy(x => x.Priority).ToList(); //new scenario
            if (strategy != null && strategy.ID !=0) //set used for existing scenario
            {
                slistNotUsed = scenarioRepository.GetTopSixth(strategy.ProjectID)
                    .Where(a => !Strategy.ExpectedUtilities.Select(x => x.Scenario.ID).Contains(a.ID)).OrderBy(x => x.Priority).ToList();
            }
            //scenarios affiliated with strategy
              //  var slistused = scenarioRepository.GetTopSixth(strategy.ProjectID)
              //                      .Where(a => strategy.ExpectedUtilities
              //                          .Select(x => x.ScenarioID). //Select Scenario IDs
            //                          Contains(a.ID)).ToList();   //a.ID =
               //needs to be list of availble scenarios, exclude already selected

                          //(theObjList, value, text to show, pre-SelectedItems)
            ScenarioSelectList = new MultiSelectList(slistNotUsed, "ID", "Name", strategy.ExpectedUtilities.Select(x => x.ScenarioID));
            ScenariosSelectedList = new MultiSelectList(AffiliatedScenarios, "ID", "Name", strategy.ExpectedUtilities.Select(x => x.ScenarioID));
            strategyForExpectedResponse = populateStrategyForExpectedResponse(strategy, AffiliatedScenarios);
        }
        // GET: /ArchitecturalStrategy/Create
        public virtual ActionResult Create(long projID)
        {
            ModelStateHelpers.ModelMessage = null; //clear any prior messages
            ArchitecturalStrategy strategy = new ArchitecturalStrategy();
            strategy.ProjectID = projID;

            return View(new ArchitecturalStrategyViewModel(strategy));
        }
        public virtual ActionResult Create(ArchitecturalStrategy strategy, int[] ScenariosIDs)
        {
            strategy.DateAdded = DateTime.Now;
            strategy.LastModified = DateTime.Now;
            strategy.Name = strategy.Name.Trim();
            strategy.Description = strategy.Description.Trim();
            strategy.Cost = strategy.Cost.Value;

            if (ScenariosIDs != null)//populate for validation
            {
                strategy.ScenariosIDs = new int[ScenariosIDs.Count()];
                Array.Copy(ScenariosIDs, strategy.ScenariosIDs, ScenariosIDs.Count());
            }
            ModelState.AddModelErrors(strategy.GetRuleViolations());
            if (ModelState.IsValid)
            {
                try
                {
                    asRepository.Add(strategy);
                    asRepository.Save();
                    asRepository.UpdateAffectedScenarios(strategy.ID, strategy.ScenariosIDs);
                    asRepository.UpdateIsComplete(strategy);
                    asRepository.Save();
                    ModelStateHelpers.ModelMessage = " Record(s) Saved Successfully.  Next update Expected Utility in Part 2 below.";
                    return View(new ArchitecturalStrategyViewModel(strategy));
                    //return Redirect(Url.RouteUrl(new { controller = "Scenario", action = "Index" }) + "#" + "tab-5");
                }
                catch
                {
                    //For Error w/o defined message
                    ModelState.AddModelError("ID", "Record not Added Sucessfully");
                    //ModelState.AddModelErrors(scenario.GetRuleViolations());
                    return View(new ArchitecturalStrategyViewModel(strategy));
                }
            }
            //else not valid
            else ModelState.AddModelError("ID", "Record not Added Sucessfully");
            return View(new ArchitecturalStrategyViewModel(strategy));
        }
Example #4
0
		private void detach_ArchitecturalStrategies(ArchitecturalStrategy entity)
		{
			this.SendPropertyChanging();
			entity.Project = null;
		}
Example #5
0
 partial void DeleteArchitecturalStrategy(ArchitecturalStrategy instance);
Example #6
0
 partial void UpdateArchitecturalStrategy(ArchitecturalStrategy instance);
Example #7
0
 partial void InsertArchitecturalStrategy(ArchitecturalStrategy instance);
        //int[] scenarios
        //for EditEntities get //top 1/6 to add util descriptions
        private StrategyForExpectedResponse populateStrategyForExpectedResponse(ArchitecturalStrategy strategy, IQueryable<Scenario> affiliatedScenarios)
        {
            var scenarioRepository = new ScenarioRepository();
            var respStrat = new StrategyForExpectedResponse();
            respStrat.ScenariosForStratUtil = new List<ScenariosForStratUtil>();
            respStrat.ID = strategy.ID;
            respStrat.Name = strategy.Name;

            var sToAdd = new ScenariosForStratUtil();

            //add scenarios to strategy
            foreach (var s in affiliatedScenarios)
            {
                //get xWalkItem for Scenario  --for Expected Response
                ExpectedUtility ExpectedUtilityItem = scenarioRepository.Get_ExpectedUtility(respStrat.ID, s.ID);
                //Scenario s = scenarioRepository.GetByID(sID);
                respStrat.ScenariosForStratUtil.Add(new ScenariosForStratUtil
                    {//s = a scenario
                          scenarioID = s.ID,
                          Name = s.Name,
                          Description = s.Description.Trim(),
                          expectedUtilID = ExpectedUtilityItem.ID,
                          ExpectedUtilityDescription = ExpectedUtilityItem.ExpectedUtilityDescription == null ? null : ExpectedUtilityItem.ExpectedUtilityDescription.Trim(),
                          ExpectedUtility = ExpectedUtilityItem.ExpectedUtility1,
                          Utilities = new List<Utility>(),
                    });

                     //add utilties best/worse/current/desired

                     //order utilities according to QualityAttribute order
                    var utils = s.Utilities.OrderBy(x => x.QualityAttributeResponseType.Order);
                    foreach (var u in utils)
                    {//Utilities to Scenario
                        //add utilities to last added scenario in ScenariosForUtilUpdate list
                        respStrat.ScenariosForStratUtil[respStrat.ScenariosForStratUtil.Count - 1].Utilities
                            .Add(new Utility
                        {
                            ID = u.ID,
                            Description = u.Description,
                            QualityAttributeResponseType =   u.QualityAttributeResponseType,
                            Utility1 = u.Utility1
                        });
                    }//end util for loop

            }//end scenario for
            return respStrat;
        }
        public virtual ActionResult Edit(int id, ArchitecturalStrategy strategy)
        {
            var sToUpdate = asRepository.GetByID(id);
            TransferValuesTo(sToUpdate, strategy);

            ModelState.AddModelErrors(sToUpdate.GetRuleViolations());
            if (ModelState.IsValid)
            {
                try
                {
                    //updates scenarios affected list
                    asRepository.UpdateAffectedScenarios(sToUpdate.ID, sToUpdate.ScenariosIDs);
                    asRepository.Save();

                    //update complete status of strategy
                    asRepository.UpdateIsComplete(strategy);
                    asRepository.Save();
                    //return View(new ArchitecturalStrategyViewModel(strategy));

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

                    ModelStateHelpers.ModelMessage = " Record(s) Saved Successfully.  Next update Expected Utility in Part 2 below.";
                    sToUpdate = asRepository.GetByID(id); //sToUpdate was not showing new affiliations
                    return View(new ArchitecturalStrategyViewModel(sToUpdate));

                   // return Redirect(Url.RouteUrl(new { controller = "Scenario", action = "Index" }) + "#" + "tab-5");
                }
                catch
                {
                    //For Error w/o defined message
                    ModelState.AddModelError("ID", "Record not Added Sucessfully");
                    //ModelState.AddModelErrors(scenario.GetRuleViolations());
                    return View(new ArchitecturalStrategyViewModel(sToUpdate));
                }
            }
            //else not valid
            else ModelState.AddModelError("ID", "Record not Added Sucessfully");
            return View(new ArchitecturalStrategyViewModel(strategy));
        }
        //Transfer Values: For /ArchitecturalStrategy/Edit
        private static void TransferValuesTo(ArchitecturalStrategy sToUpdate, ArchitecturalStrategy strategy)
        {
            sToUpdate.Name = strategy.Name.Trim();
            sToUpdate.Description = strategy.Description.Trim();
            sToUpdate.DateAdded = DateTime.Now;
            sToUpdate.LastModified = DateTime.Now;
            sToUpdate.Cost = strategy.Cost;

            if (strategy.ScenariosIDs != null)//populate for validation
            {
                sToUpdate.ScenariosIDs = new int[strategy.ScenariosIDs.Count()];
                Array.Copy(strategy.ScenariosIDs, sToUpdate.ScenariosIDs, strategy.ScenariosIDs.Count());
            }
        }