0

I have a multiple page Web Application that needs to be refreshed after a user has entered in data to then display the data on the table. I have Scoped dependencies so my users do not see the same data table as they are unique to each user. After they enter the data and the page refreshes the page goes blank and the scope is empty. How would I go about keeping the data from the scopes after refresh? I essentially needs a Singlton dependency that isn't shared between users. This is a Blazor Server Side Application. EDIT: Accept Button Method

if (Controlled_Variables.Attendance != null)
        {
            if (_JBS.CheckFields(_JBF.JobID, _JBF.WorkCenter, _JBF.SetupRun) == false)
            {
                string prompted = await jsRunTime.InvokeAsync<string>("alert", "Please Verify Job ID, Work Center, and Setup/Run are selected!");
            }
            else
            {
                FilledOut = true;
                _JBF.transactionData = Guid.NewGuid();
                _JBF.jobOperationID = _JBF.WorkCenter;

                DateTime recordDate = DateTime.Now;

                JobOperationRecord JOR = await _JBS.GetJobOperationRecordByOperationID(_JBF.WorkCenter);
                WorkCenterRecord SingleWorkCenter = await _JBS.GetWorkCenterInformation(JOR.Work_Center);
                EmployeeRecord Employee = await _JBS.GetEmployeeRecord(Controlled_Variables.Employee_ID);

                try
                {
                    if (Check.IsThisAnActiveJob(_JBF.JobID))
                    {
                        bool Complete = await First_Article_Complete(_JBF.jobOperationID, _JBF.SetupRun);
                        if (Complete)
                        {
                            Controlled_Variables.Sessions.Clear();
                            Controlled_Variables.Sessions = await _JBS.GetOpenJobOperationTimeSessionForUser(Controlled_Variables.Employee_ID);

                            bool activeNonGhostSession = false;

                            foreach (JobOperationSessionManager Session in Controlled_Variables.Sessions)
                            {
                                if (Session.ghost == "Y")
                                {
                                    Controlled_Variables.ActiveSession = Session;
                                    activeNonGhostSession = true;

                                }
                            }

                            _JBS.UpdateJobOperationStatus(JOR.Job_Operation.ToString(), JOR.Status == "C" ? "C" : "S");

                            if (!activeNonGhostSession && !_JBF.GhostedCheck)
                            {
                                _JBS.AddNewJobOperationTimeSessionForUser(Controlled_Variables.Employee_ID, "N", _JBF.transactionData.ToString(), JOR.Work_Center,
                                    _JBF.jobOperationID, _JBF.JobID, recordDate.ToString("yyyy-MM-dd HH:mm:ss"), _JBF.jobOperationTime.ToString(), _JBF.SetupRun);

                                _JBF.sessionManagerCreated = true;

                                _JBS.InsertIntoTransactionDetail_NewEntry_JobOperation(_JBF.transactionData.ToString(), _JBF.jobOperationID, _JBF.jobOperationTime.ToString(),
                                    JOR.Work_Center, _JBF.JobID);

                                _JBF.transDetailCreated = true;

                                _JBS.InsertIntoTransactionData_NewEntry_JobOperation(_JBF.transactionData.ToString(), Controlled_Variables.Employee_ID, recordDate.ToString());

                                _JBF.transDataCreated = true;

                                _JBS.InsertIntoJobOperationTime_NewEntry_JobOperationStart(_JBF.jobOperationID, Controlled_Variables.Employee_ID, recordDate.ToString(),
                                Employee.Hourly_Rate.ToString(), SingleWorkCenter.Labor_Burden.ToString(), SingleWorkCenter.Machine_Burden.ToString(), SingleWorkCenter.GA_Burden.ToString(),
                                _JBF.jobOperationTime.ToString(), JOR.Work_Center, _JBF.jobOperationTimeObjectID.ToString(), JOR.ObjectID.ToString(), Employee.ObjectID.ToString());

                                _JBF.jobOperationTimeCreated = true;

                                btnStartJob = true;
                                btnStopJob = false;
                                NavManage.NavigateTo(NavManage.Uri, forceLoad: true);
                                string prompted = await jsRunTime.InvokeAsync<string>("alert", "The job has been entered successfully.", "ERROR");

Sorry for the confusion for the use of refresh. I needed to reload the table to allow the data put in by users to be visable after they hit accept. To do this I added a navigation manager

NavManage.NavigateTo(NavManage.Uri, forceLoad: true);

Which force loads the page and displays the new data. If there may be another way to do this to keep the scope I am open to using a different method. As you can see I have tried to just recall the method in which the table data is loaded into to possibly get the new data populated but then the application never reiterates the loop to actually display the data on the page

@for (int i = 0; i < Controlled_Variables.TransactionData.Count; i++)
        {
            var TransacData = Controlled_Variables.TransactionData[i];
            TransacData.index = i;
             

            @for (int l = 0; l < Controlled_Variables.TransactionDetail.Count; l++)
            {
                var transacdetail = Controlled_Variables.TransactionDetail[l];
                transacdetail.index = l;
                TransactionDetailRecord selectData = Controlled_Variables.TransactionDetail[l]; 

                @if (transacdetail.Transaction_Data == TransacData.Transaction_Data)
                {
                    <div><input value="@selectData" type="radio" name="Select" onclick="@(() => ShowSelectedRecord(selectData, TransacData))"> </div>
                    <div>@transacdetail.Target_Integer</div>
                    <div>@transacdetail.Job</div>
                    <div>@Controlled_Variables.Job.Part_Number</div>
                    <div>@TransacData.Transaction_Start</div>
                    if (TransacData.Transaction_Type == 10)
                    {
                        <div>@TransacData.Transaction_Type</div>
                        btnStartJob = true;
                        btnStopJob = false;
                    }
                    else
                    {
                        <div>@TransacData.Transaction_Type</div>
                        btnStartJob = false;
                        btnStopJob = true;
                    }
                    <div>@Controlled_Variables.Job.Customer</div>
                    <div>@transacdetail.Work_Center</div>
                    <div>@transacdetail.Quantity</div>
                    <div>@TransacData.Transaction_End</div>
                    <div>@transacdetail.Entry_Type</div>
                    <div>@transacdetail.Labor_Hrs</div>
                    <div>@transacdetail.Machine_Hrs</div>
                    <div>@TransacData.Transaction_Data</div>
                    <div>@transacdetail.Transaction_Detail</div>
                }
            }
        }
enet
  • 41,195
  • 5
  • 76
  • 113
Aiden P
  • 23
  • 1
  • 8
  • What means 'Page refreshes' for you? In Blazor that does not a sense. The page is all time the same. It is a SPA, the page never refreshes, if refreshes then it means it is a new instance of the app (stop and restart app for the user) – dani herrera May 19 '22 at 18:26
  • Where is your code ? No, you don't need a Singelton... You need to use Scoped, not Singleton. A Scoped object in Blazor Server App is scoped to the Circuit (connection). What do you mean refresh? Reload ? When you reload an ASP you create a fresh instance of the app... Show your code. – enet May 19 '22 at 18:51
  • `NavManage.NavigateTo(NavManage.Uri, forceLoad: true);` is like "I close the app and start it again". – dani herrera May 22 '22 at 16:51
  • @daniherrera Is there a way to call back up to the HTML loop to refresh the table? that is the only reason I am using the NavManage. I know there has to be a way to call it back but I can not think of one. I also have not found anything online that seems to work with Blazor. – Aiden P May 23 '22 at 10:56
  • If you create a Minimal Reproducible Sample repo I can try to fix it. – dani herrera May 23 '22 at 10:58
  • _[The important feature of a minimal reproducible example is that it is as small and as simple as possible, such that it is just sufficient to demonstrate the problem, but without any additional complexity or dependencies which will make resolution harder.](https://en.wikipedia.org/wiki/Minimal_reproducible_example#:~:text=In%20computing%2C%20a%20minimal%20reproducible,to%20be%20demonstrated%20and%20reproduced.)_ – dani herrera May 23 '22 at 19:53

0 Answers0