Foreach在执行工作流时没有在mvc中正确检查

本文关键字:检查 mvc 执行 工作流 Foreach | 更新日期: 2023-09-27 18:20:48

我在做一个工作流检查,其中我有两个值,当foreach条件只检查一次时,它进入循环并退出,而不进入下一个循环。

  public CustomBusinessServices InvokeWorkFlowPermissionBusinessRule(dynamic workFlowImplemented, out string serviceName, out int permissionId)
    {
        try
        {
            List<WorkflowEligibilityMapping> workFlowPermissionService = new List<WorkflowEligibilityMapping>();// to handle null values
            int current_ControllerId = Convert.ToInt32(workFlowImplemented); //ControllerId
            using (var db = new AdminDb())
            {
                //to select services against this controller
                workFlowPermissionService = (from definition in db.WorkFlowDefinition.AsNoTracking()
                                             join model in db.WorkFlowModel.AsNoTracking()
                                             on definition.WorkFlowDefinitionId equals model.WorkFlowDefinitionId
                                             join permission in db.WorkFlowPermission.AsNoTracking()
                                             on model.WorkFlowDefinitionId equals permission.WorkFlowDefinitionId
                                             where model.ControllerNameId.Equals(current_ControllerId)
                                             select new WorkflowEligibilityMapping
                                             {
                                                 Service = permission.Service,
                                                 WorkFlowPermissionId = permission.WorkFlowPermissionId
                                             }).ToList();
            }
            int[] workFlowServiceDetails = workFlowPermissionService.Select(x => x.WorkFlowPermissionId).ToArray();
            //to Login userId
            var userId = Assyst.PanERP.Common.AppSession.Common.UserID;
            /*******************Issue in foreach i think**************************************/
            foreach (int workFlowServiceDetail in workFlowServiceDetails)
            /*******workFlowServiceDetails have 2 valus********/
            {
                using (var db = new AdminDb())
                {
                    string workFlowServiceDtl = (from perm in db.WorkFlowPermission.AsNoTracking()
                                                 where perm.WorkFlowPermissionId == workFlowServiceDetail
                                                 select perm.Service).FirstOrDefault();
                    //to select eligibility rules against this service
                    string eligibility = (from definition in db.WorkFlowDefinition.AsNoTracking()
                                          join model in db.WorkFlowModel.AsNoTracking()
                                          on definition.WorkFlowDefinitionId equals model.WorkFlowDefinitionId
                                          join permission in db.WorkFlowPermission.AsNoTracking()
                                          on model.WorkFlowDefinitionId equals permission.WorkFlowDefinitionId
                                          where model.ControllerNameId.Equals(current_ControllerId) && permission.WorkFlowPermissionId == workFlowServiceDetail
                                          select permission.EligibilityRule).FirstOrDefault();
                    if (eligibility == null)
                    {
                        string validationMessage = "";
                        validationMessage = "Please set eligibility for workflow permission";
                        serviceName = null;
                        permissionId = 0;
                        return new CustomBusinessServices() { strMessage = validationMessage };
                    }
                    string[] strTxt = workFlowServiceDtl.Split(';'); //split the service name by ';' and strore it in an array
                    string serviceUrl = string.Empty;
                    string workFlowServiceName = string.Empty;
                    string classpath = string.Empty;
                    workFlowServiceName = strTxt[0].ToString();
                    workFlowServiceName = workFlowServiceName.Replace(" ", "");//get the service name by removing empty blank space for the word
                    classpath = strTxt[1].ToString();
                    //Invoke REST based service (like Node.Js service)
                    if (strTxt.Length == 4)
                    {
                        serviceUrl = strTxt[3].ToString();
                    }
                    //Invoke c# based service
                    else
                    {
                        serviceUrl = string.Empty;
                    }
                    var userLists = PermissionCallMethod(classpath, workFlowServiceName, new[] { workFlowImplemented, eligibility }, serviceUrl);
                    if (userLists.UserList.Contains(userId))
                    {
                        serviceName = strTxt[0].ToString() + ";Assyst.PanERP.Common.WorkFlowNotificationServices;" + strTxt[2].ToString();
                        permissionId = workFlowServiceDetail;
                        return userLists;
                    }
                }
            }
            serviceName = string.Empty;
            permissionId = 0;
            return null;
        }
        catch (Exception ex)
        {
            throw ex;
            return null;
        }
    }

workFlowServiceDetails有两个值,workFlowServiceDetail获取第一个值并检查它。遍历循环并将第一个值的角色映射到末尾的用户列表,在不检查第二个值的情况下,它将移出循环。请帮助我使循环为2个值工作。退货部分有问题吗。。。?

Foreach在执行工作流时没有在mvc中正确检查

if (eligibility == null)
{
     string validationMessage = "";
     validationMessage = "Please set eligibility for workflow permission";
     serviceName = null;
     permissionId = 0;
     return new CustomBusinessServices() { strMessage = validationMessage };
}
if (userLists.UserList.Contains(userId))
{
     serviceName = strTxt[0].ToString() + ";Assyst.PanERP.Common.WorkFlowNotificationServices;" + strTxt[2].ToString();
     permissionId = workFlowServiceDetail;
     return userLists;
}

如果上述If语句中的任何一个计算结果为true,则循环将退出,而不会循环通过数组中的第二个项。原因是您正在进行第一次条件检查,请执行以下操作:

return new CustomBusinessServices() { strMessage = validationMessage };

在你的第二个:

return userLists;

return语句将退出您的方法,因此也将终止foreach。

试着先构建对象,在循环遍历完每个项目后,做一个返回语句来返回对象。