Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 如何检测数据库表中的状态更改,并添加一个计划函数以在特定时间运行?_Asp.net Mvc_Entity Framework_Asp.net Mvc 4_Datetime - Fatal编程技术网

Asp.net mvc 如何检测数据库表中的状态更改,并添加一个计划函数以在特定时间运行?

Asp.net mvc 如何检测数据库表中的状态更改,并添加一个计划函数以在特定时间运行?,asp.net-mvc,entity-framework,asp.net-mvc-4,datetime,Asp.net Mvc,Entity Framework,Asp.net Mvc 4,Datetime,假设我有一个网站,用户可以在其中创建问卷(调查),这些问卷存储在数据库中,供用户回答问题。我的想法是在问卷发生更改时向用户发送电子邮件通知,例如在问卷中添加新问题 但是,为了避免在用户继续编辑问卷时每两分钟发送一次电子邮件,我创建了一个临时表(“LoggedSurveyUpdate”),它将在编辑问卷时保留一条记录。现在我面临的挑战是,我希望电子邮件通知在最后一份问卷编辑完成一小时后发送。 我希望这是有道理的 [HttpPost] [ValidateAntiForgeryTok

假设我有一个网站,用户可以在其中创建问卷(调查),这些问卷存储在数据库中,供用户回答问题。我的想法是在问卷发生更改时向用户发送电子邮件通知,例如在问卷中添加新问题

但是,为了避免在用户继续编辑问卷时每两分钟发送一次电子邮件,我创建了一个临时表(“LoggedSurveyUpdate”),它将在编辑问卷时保留一条记录。现在我面临的挑战是,我希望电子邮件通知在最后一份问卷编辑完成一小时后发送。 我希望这是有道理的

     [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Edit(SurveyVM vm)
    {
        if (ModelState.IsValid)
        {
            try
            {
                bool readyToPublish = false;
                if (vm.Survey.Publish)
                {
                    readyToPublish = surveyLogic.CheckIfReadyToPublish(vm.Survey);
                    if (readyToPublish)
                    {
                       // User currentUser = userLogic.GetBy(x => x.UserID == vm.User.UserID);
                        Survey survey = surveyLogic.GetBy(x => x.SurveyName == vm.Survey.SurveyName && x.CustomerID == vm.Survey.CustomerID && x.SurveyID != vm.Survey.SurveyID).SingleOrDefault();
                        if (survey == null)
                        {
                            surveyLogic.Update(vm.Survey);


                           surveyLogic.SuveyUpdate(vm.Survey);
                        }

            }
            catch (Exception e) 
            {
                vm.CategoryOptions = CategoryOptionsHelper.BuildCategoryOptions(vm.Survey.CustomerID, false);
                TempData["Failure"] = "Edit Failed. Please Review Your Selections and Try Again.";
                return View(vm);
            }
} }

在临时表中插入数据的位置


创建一个(windows)服务,按照设置的时间表轮询表。@我知道如何使用此建议Google吗
      public void SuveyUpdate(Survey survey)
    {
        using (ManageLoggedSurveyUpdate updateLogic = new ManageLoggedSurveyUpdate(ref base.Uow))
        using (ManageSurvey surveyLogic = new ManageSurvey(ref base.Uow))
        using (ManageLoggedSurveyUpdate loggedSurveyUpdate = new ManageLoggedSurveyUpdate(ref base.Uow))
        {
            Survey surveys = surveyLogic.GetBy(x => x.SurveyID == survey.SurveyID && x.Publish == survey.Publish).SingleOrDefault();

            if (surveys == null)
            {
                LoggedSurveyUpdate newupdte = new LoggedSurveyUpdate()
                {
                    SurveyID = survey.SurveyID,
                    Active = true,
                    SurveyEdited = DateTime.Now,
                    UserID = (int)System.Web.HttpContext.Current.Session["UserID"],



                };
                loggedSurveyUpdate.Insert(newupdte);
            }
            else {

                LoggedSurveyUpdate newupdte = new LoggedSurveyUpdate()
                {

                    SurveyID = survey.SurveyID,
                    Active = true,
                    SurveyEdited = DateTime.Now,
                    UserID = (int)System.Web.HttpContext.Current.Session["UserID"],




                };

                loggedSurveyUpdate.Update(newupdte);


            }



        }
    }