从asp.net核心中正在运行的进程获取更新

时间:2019-02-03 12:05:37

标签: c# asp.net ajax asp.net-core

更新2/14 -是否有人对如何帮助我有想法?

我的文件导入过程需要几秒钟到一整分钟才能完成。

我需要向用户提供最新情况。 我是一个“转换”的WinForms程序员,由于它似乎越来越受欢迎,他仍在努力过渡到该“网络事物”。

我该怎么做?通常,我会更新屏幕上的控件或计数器。 如果答案很长,则不需要详细的代码响应。指向好的示例或教程的链接也将起作用。

我正在通过ajax帖子向控制器进行呼叫:

 // Make your POST
        $.ajax({
            type: "POST",
            url: '@Url.Action("ReadAndSaveCSVData", "Home")',
            data: fdata,
            contentType: false,
            processData: false,
            //async: false,
            success: function (response) {
                if (response != null) {
                    if (response) {
                        alert("Data Imported");
                        $('#fUpload').val('');
                    }
                    else {
                        alert("Import Failed");
                    }
                }
                //load1.style.display = 'none';
            },
            error: function (e) {
                //load1.style.display = 'none';
                //alert(e.responseText);
            }
        });

正在执行工作的控制器是这样设置的:

  using (LOBContext db = new LOBContext())
                    {
                        using (var transaction = db.Database.BeginTransaction())
                        {
                            try
                            {
                                LOBContext db2 = new LOBContext(); //create a seperate data context for creating new records that need to be accessed here.

                                foreach (var li in list)
                                {
                                    PayrollTimecardEntries tc = new PayrollTimecardEntries();

                                    //Get the Id's of the related records, or create them
                                    getPayrollDeptType(db, db2, li, tc);
                                    getEmployeeId(db, db2, li, tc);
                                    getPunchTypeId(db, db2, li, tc);

                                    tc.PunchDate = li.punchDate;
                                    tc.Hours = li.hours;
                                    tc.PaycorCreatedDatetime = li.paycoreCreatedDatetime;
                                    tc.CreatedbyPaycorUsername = li.paycoreCreatedByUserName.Trim('"');

                                    //see if this is a new entry or not
                                    int result = (from seek in db2.PayrollTimecardEntries
                                                  where seek.EmployeeId == tc.EmployeeId &&
                                                  seek.Hours == tc.Hours &&
                                                  seek.PaycorCreatedDatetime == tc.PaycorCreatedDatetime
                                                  select seek.Id).FirstOrDefault();
                                    if (result == 0) //only add new timecard entries
                                    {
                                        db2.PayrollTimecardEntries.Add(tc);
                                        db2.SaveChanges();

                                    }
                                }
                                transaction.Commit();
                            }
                            catch (Exception ex)
                            {
                                transaction.Rollback();
                                throw ex;
                            }
                        }
                    }
                    importSuccess = true;
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }

        return importSuccess;

0 个答案:

没有答案