长时间发送电子邮件

时间:2017-10-09 06:12:33

标签: c# email asp.net-mvc-5

在我们的内部ERP应用程序中,F& A同事可以在月底批准开发人员的时间表。点击'批准'有一个异常的长时间延迟。这与网络无关,因为这发生在我的工作区分支,测试环境和实时环境中。

此方法发送了多封电子邮件。我怎样才能加快这个过程?

这是ApproveTimesheetByApprover方法的一个例子:

public bool ApproveTimesheetByApprover(int timesheetId, string commentConsultant, string commentAccount, int accountContactId, bool forced = false)
{
    //Get subject timesheet
    var timesheet = _timesheetsQueryHandler.GetById(timesheetId).ReturnValue;

    //Check if this user is in right group to approve this timesheet
    var approverList = _getAllGroupUsersByGroupIdQueryHandler.Execute(timesheet.Project.ApproverId).ReturnValue.Where(gu => !gu.IsDeleted).ToList();
    var approver = approverList.FirstOrDefault(x => x.UserId == UserId);
    if (approver != null)
    {
        //Db updates
        var statusCommand = new UpdateTimesheetStatusCommand(timesheetId, "approver", true);
        var statusSuccessUpdate = _timesheetCommandHandler.UpdateStatus(statusCommand);
        if (forced && statusSuccessUpdate)
        {
            var commandCons = new UpdateTimesheetStatusCommand(timesheetId, "consultant", true);
            statusSuccessUpdate = _timesheetCommandHandler.UpdateStatus(commandCons);
        }

        if (statusSuccessUpdate)
        {
            _actionLogic.SetCompleteAction(timesheetId);


            // remove approval action from the list of actions for all relevant users
            List<EmailTemplateActionReferenceDto> emailTemplateActionReferences = _emailActionNotificationLogic.GetEmailTemplateActionReference(EmailTemplates.TimesheetApprovedConsultant);
            foreach (EmailTemplateActionReferenceDto emailTemplateActionReference in emailTemplateActionReferences)
            {
                var actionTypeId = emailTemplateActionReference.ActionTypeId;
                _actionLogic.SetCompleteActionForUsers(actionTypeId, timesheetId);
            }

            //E-mail consultant
            string dateString = timesheet.SubjectDate.ToString("MMMM yyyy", new CultureInfo(_getCultureByIdQuery.Execute(timesheet.User.CultureId).Name));
            SendMailToConsultant_Approve(dateString, commentConsultant, timesheet.UserId);

            //update skilldetails
            _skillDetailsLogic.AutoUpdateSkillsAndProjectConsultantSkillsFromTimesheet(timesheet);

            if (timesheet.Account.SignsTimesheets)
            {
                var accountContactCommand = new UpdateTimesheetAccountContactCommand(timesheetId, accountContactId);
                var accountContactSuccessUpdate =
                    _timesheetCommandHandler.UpdateAccountContact(accountContactCommand);

                Guid approveEmailGuid = Guid.NewGuid();
                _updateTimesheetClientValidationGuidQuery.Execute(timesheet.Id, approveEmailGuid);


                //E-mail account
                if (accountContactSuccessUpdate)
                {
                    var approverContact = _getContactByUserIdQuery.Execute(approver.UserId);
                    var approverName = approverContact.FirstName + " " + approverContact.LastName;
                    var consultantContact = _getContactByUserIdQuery.Execute(timesheet.UserId);
                    var consultantName = consultantContact.FirstName + " " + consultantContact.LastName;
                    var accountContact = _getAccountContactQueryHandler.Execute(accountContactId).ReturnValue;
                    dateString = timesheet.SubjectDate.ToString("MMMM yyyy", new CultureInfo(_getCultureByIdQuery.Execute(accountContact.CultureId).Name));
                    SendMailToAccount(dateString, consultantName, approverName, accountContact, approveEmailGuid,
                        timesheet.Project.ProjectReference, commentAccount);
                }
            }

            return statusSuccessUpdate;
        }
    }
    return false;
}

0 个答案:

没有答案