public async Task SetUpProperties()
        {
            AllNewSpecs           = new List <SpecRevModel>();
            AllNewProcessRevModel = new List <ProcessRevisionModel>();
            AllSpecIds            = new List <int>();

            var tempSpecProcessAssign = await SpecProcessAssignDataAccess.GetAllHydratedReviewNeededSpecProcessAssign();

            AllSpecProcessAssigns = (tempSpecProcessAssign != null) ? tempSpecProcessAssign.ToList() : null;

            if (AllSpecProcessAssigns != null)
            {
                foreach (var specProcessAssign in AllSpecProcessAssigns)
                {
                    if (!AllSpecIds.Contains(specProcessAssign.SpecId))
                    {
                        AllSpecIds.Add(specProcessAssign.SpecId);
                    }
                }

                foreach (var assign in AllSpecProcessAssigns)
                {
                    //Finding out if the spec is under review because of a spec rev up or a process rev up.
                    var theNewestSpecRev = (await SpecDataAccess.GetHydratedCurrentRevOfSpec(assign.SpecId)).SpecRevModels.FirstOrDefault();
                    if (theNewestSpecRev.InternalRev != assign.SpecRevId)
                    {
                        assign.IsViable = false;
                        if (!AllNewSpecs.Contains(theNewestSpecRev))
                        {
                            AllNewSpecs.Add(theNewestSpecRev);
                        }
                    }

                    var theNewestProcessRev = await ProcessDataAccess.GetHydratedCurrentProcessRev(assign.ProcessId);

                    if (theNewestProcessRev.ProcessRevId != assign.ProcessRevId)
                    {
                        AllNewProcessRevModel.Add(theNewestProcessRev);
                    }
                }
            }
        }
        //As of now, this will only get hit if a spec id is passed into the page.
        public async Task SetUpProperties(int?aSpecId)
        {
            if (aSpecId != null && aSpecId != 0)
            {
                int theSpecId      = aSpecId ?? default(int); //The spec id passed into SpecDataAccess.GetHydratedCurrentRevOfSpec needs to be of type int, not int?
                var theCurrentSpec = await SpecDataAccess.GetHydratedCurrentRevOfSpec(theSpecId);

                var theCurrentSpecRev = theCurrentSpec.SpecRevModels.FirstOrDefault();

                SpecCode        = theCurrentSpec.Code;
                SpecDescription = theCurrentSpecRev.Description;
                ExternalRev     = theCurrentSpecRev.ExternalRev;
                SamplePlanId    = theCurrentSpecRev.SamplePlanId;

                theCurrentSpecRev.SubLevels.OrderBy(i => i.LevelSeq);

                foreach (var sublevel in theCurrentSpecRev.SubLevels)
                {
                    BuildPageFromModels(sublevel);
                }
            }

            var tempAllSpecModels = await SpecDataAccess.GetAllHydratedSpecs();

            AllSpecModels = tempAllSpecModels.ToList();

            var tempAllSamplePlanModels = await SamplePlanDataAccess.GetAllHydratedSamplePlans();

            AllSamplePlans = tempAllSamplePlanModels.ToList();

            var tempAllStepModels = await StepDataAccess.GetAllSteps();

            AllSteps = tempAllStepModels.ToList();

            var tempAllStepCategoryModels = await StepDataAccess.GetAllStepCategoryies();

            AllStepCategories = tempAllStepCategoryModels.ToList();
        }
        public async Task <ActionResult> OnPost()
        {
            Message = new PopUpMessageModel();

            if (!ModelState.IsValid) //ToDo: Is this even used?
            {
                Message.Text          = ModelState.ToString();
                Message.IsMessageGood = false;

                return(Page());
            }

            if (!(await SpecDataAccess.CheckIfCodeIsUnique(SpecCode)) && CurrentSpecId == 0)
            {
                Message = new PopUpMessageModel()
                {
                    IsMessageGood = false,
                    Text          = "A specification with that code already exists"
                };

                await SetUpProperties(CurrentSpecId);

                return(Page());
            }

            var theSpec = new SpecModel()
            {
                Id   = CurrentSpecId,
                Code = SpecCode
            };

            var theSpecRev = new SpecRevModel()
            {
                //Date & Time Modified will be set at the API level.
                SpecId         = CurrentSpecId,
                Description    = SpecDescription,
                ExternalRev    = ExternalRev,
                EmployeeNumber = 941,
                SamplePlanId   = SamplePlanId
            };

            var theSubLevelList = new List <SpecSubLevelModel>(); //This will be assigned to theSpec.Sublevels at the end.

            byte subLevelSeq = 0;

            //Sublevel 1
            if (SubLevelName1 != null)
            {
                subLevelSeq++;
                theSubLevelList.Add(BuildSubLevelFromPage(subLevelSeq, SubLevelName1, ChoiceList1, IsSubLevelReq1, DefaultChoice1));
            }

            //Sublevel 2
            if (SubLevelName2 != null)
            {
                subLevelSeq++;
                theSubLevelList.Add(BuildSubLevelFromPage(subLevelSeq, SubLevelName2, ChoiceList2, IsSubLevelReq2, DefaultChoice2));
            }

            //Sublevel 3
            if (SubLevelName3 != null)
            {
                subLevelSeq++;
                theSubLevelList.Add(BuildSubLevelFromPage(subLevelSeq, SubLevelName3, ChoiceList3, IsSubLevelReq3, DefaultChoice3));
            }

            //Sublevel 4
            if (SubLevelName4 != null)
            {
                subLevelSeq++;
                theSubLevelList.Add(BuildSubLevelFromPage(subLevelSeq, SubLevelName4, ChoiceList4, IsSubLevelReq4, DefaultChoice4));
            }

            //Sublevel 5
            if (SubLevelName5 != null)
            {
                subLevelSeq++;
                theSubLevelList.Add(BuildSubLevelFromPage(subLevelSeq, SubLevelName5, ChoiceList5, IsSubLevelReq5, DefaultChoice5));
            }

            //Sublevel 6
            if (SubLevelName6 != null)
            {
                subLevelSeq++;
                theSubLevelList.Add(BuildSubLevelFromPage(subLevelSeq, SubLevelName6, ChoiceList6, IsSubLevelReq6, DefaultChoice6));
            }


            theSpecRev.SubLevels = theSubLevelList;
            var theSpecRevsTempList = new List <SpecRevModel>();

            theSpecRevsTempList.Add(theSpecRev); //This is just a list of one to hold the rev because Specification Model takes a list of revs, not just one.
            theSpec.SpecRevModels = theSpecRevsTempList;
            var theReturnedSpecId = 0;           //This is the SpecId that will be returned from the DataAccess after creating a new Spec or Reving up a Spec.

            if (CurrentSpecId == 0)              //New Spec
            {
                theReturnedSpecId = await SpecDataAccess.CreateNewHydratedSpec(theSpec);

                CurrentSpecId         = theReturnedSpecId;
                Message.Text          = "Spec created successfully.";
                Message.IsMessageGood = true;
            }
            else if (WasRevUpSelected) //Spec is being Reved-Up.
            {
                theSpec.Id        = CurrentSpecId;
                theReturnedSpecId = await SpecDataAccess.RevUpSpec(theSpecRev);

                Message.Text          = "Spec reved-up successfully";
                Message.IsMessageGood = true;
            }
            await SetUpProperties(theReturnedSpecId);

            return(Page());
        }
        public async Task SetUpProperties()
        {
            var theAllSpecs = await SpecDataAccess.GetAllHydratedSpecsWithSamplePlans();

            AllSpecs = theAllSpecs.OrderBy(i => i.Code).ToList();
        }