public async Task SetUpPageProperties(string aMessage = null, bool?isMessageGood = null, int anOperationId = 0)
        {
            if (aMessage != null)
            {
                Message = new PopUpMessageModel()
                {
                    Text          = aMessage,
                    IsMessageGood = isMessageGood
                };
            }


            var theAllOperationsTemp = await OperationDataAccess.GetAllOperations();

            AllOperations = theAllOperationsTemp.OrderBy(i => i.Name).ToList();

            var theAllOperationGroupsTemp = await OperationDataAccess.GetAllOperationGroups();

            AllOperationGroups = theAllOperationGroupsTemp.OrderBy(i => i.Name).ToList();

            //Writing all the values for the current operation to the bound properties.
            if (anOperationId != 0)
            {
                var theCurrentOperation = AllOperations.FirstOrDefault(i => i.Id == anOperationId);
                CurrentOperationId             = theCurrentOperation.Id;
                CurrentOperationName           = theCurrentOperation.Name;
                CurrentOperationCode           = theCurrentOperation.OperShortName;
                CurrentOperationDefaultDueDays = theCurrentOperation.DefaultDueDays;
                CurrentOperationThicknessReq   = theCurrentOperation.ThicknessIsRequired;
                CurrentOperationGroupId        = theCurrentOperation.Group.Id;
            }
        }
        public async Task <ActionResult> OnPost()
        {
            if (ModelState.IsValid)
            {
                var theCurrentOperation = new OperationModel()
                {
                    Name                = CurrentOperationName,
                    OperShortName       = CurrentOperationCode,
                    DefaultDueDays      = CurrentOperationDefaultDueDays,
                    ThicknessIsRequired = CurrentOperationThicknessReq,
                    OperationGroupId    = CurrentOperationGroupId
                };

                var            theReturnMessage = "";
                OperationModel result;

                if (CurrentOperationId == 0) //If the operation ID is 0, then a new operation is to be created
                {
                    result = await OperationDataAccess.CreateOperation(theCurrentOperation);

                    theReturnMessage = "New operation was created successfully.";
                }
                else //If the operation Id is not 0, then the operation with the ID selected is to be updated
                {
                    theCurrentOperation.Id = CurrentOperationId;

                    result = await OperationDataAccess.UpdateOperation(theCurrentOperation);

                    theReturnMessage = "The operation was updated successfully.";
                }

                return(RedirectToPage("OperationMaintenance", new { anOperationId = result.Id, aMessage = theReturnMessage, isMessageGood = true }));
            }

            await SetUpPageProperties();

            return(Page());
        }
        public async Task SetUpProperties(int aProcessId)
        {
            var theProcesses = await ProcessDataAccess.GetHydratedProcessesWithCurrentAnyRev();

            AllProcesses = theProcesses.ToList();
            foreach (var process in AllProcesses)
            {
                process.Revisions.OrderByDescending(i => i.ProcessRevId);
            }

            var theSteps = await StepDataAccess.GetAllSteps();

            AllSteps = theSteps.OrderBy(i => i.StepName).ToList();

            var theOperations = await OperationDataAccess.GetAllOperations();

            AllOperations = theOperations.OrderBy(i => i.Name).ToList();

            CurrentProcess = new ProcessModel();              //This needs to be created even if there isn't a process being passed in so the front-end doesn't throw a null reference exception when looking for a name.

            CurrentRev          = new ProcessRevisionModel(); //This also needs to be created right away so the front-end doesn't throw a null reference exception when loading the current step list.
            CurrentRev.StepSeqs = new List <StepSeqModel>();

            CurrentStepIds      = null;
            CurrentOperationIds = null;

            if (aProcessId > 0)
            {
                CurrentProcess   = AllProcesses.FirstOrDefault(i => i.ProcessId == aProcessId);
                CurrentProcessId = aProcessId;
                if (CurrentProcess.Revisions.Any())
                {
                    ModelState.Remove("CurrentRevId"); //The input field wasn't updating when deleting an unlocked revision.  This clears the model state for just this property
                    CurrentRev           = CurrentProcess.Revisions.OrderByDescending(i => i.ProcessRevId).FirstOrDefault();
                    CurrentRevId         = CurrentRev.ProcessRevId;
                    Comment              = CurrentRev.Comments;
                    EmpCreatedCurrentRev = await EmployeeDataAccess.GetEmployeeById(CurrentRev.CreatedByEmp);

                    CurrentOperations = new List <OperationModel>();
                    //Finds each unique operation within the revision's steps and loads it into CurrentOperations.
                    foreach (var stepSeq in CurrentRev.StepSeqs)
                    {
                        var shouldThisStepBeAdded = true;
                        foreach (var operation in CurrentOperations)
                        {
                            if (operation.Id == stepSeq.Operation.Id)
                            {
                                shouldThisStepBeAdded = false;
                            }
                        }
                        if (shouldThisStepBeAdded)
                        {
                            CurrentOperations.Add(stepSeq.Operation);
                        }
                    }
                }
                else
                {
                    ModelState.Remove("CurrentRevId"); //The input field wasn't updating when deleting an unlocked revision.  This clears the model state for just this property
                    CurrentRevId = 0;
                }
            }
        }
 public OperationBusiness()
 {
     operationDataAccess = new OperationDataAccess();
 }