foreach循环在mvc中不起作用

时间:2015-11-06 06:31:45

标签: c# jquery asp.net-mvc

import matplotlib.pyplot as plt
import pandas as pd
Dates=['01/01/2014','02/01/2014','03/01/2014','04/01/2014','05/01/2014','06/01/2014','07/01/2014']
Values=[3,4,6,5,4,5,4]
Colors=['red','red','blue','blue','blue','red','red']
df=pd.DataFrame({'Dates':Dates,'Values':Values,'Colors':Colors})
df['Dates']=pd.to_datetime(df['Dates'],dayfirst=True)

grouped = df.groupby('Colors')
fig, ax = plt.subplots()

for key, group in grouped:
   group.plot(ax=ax, x="Dates", y="Values", label=key, color=key)

plt.show()

在此循环中,检查条件以查找用户的特定用户表单。一旦条件为真,它就跳出循环而不检查下一个。

foreach (int workFlowServiceDetail in workFlowServiceDetails)
{
   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);

     /*****************************************Problem in this loop**********/
     if (userLists.UserList.Contains(userId))
     {
          serviceName = strTxt[0].ToString() + ";Aspir.Pan.Common.WorkFlowNotificationServices;" + strTxt[2].ToString();
          permissionId = workFlowServiceDetail;
          return userLists;
     }
   }
}
serviceName = string.Empty;
permissionId = 0;
return null;
这主要是因为" return userList"。那我怎么能让循环再次运行呢。或者请建议一些方法使它工作。是否可以将返回的userList复制到某个List并在循环后返回它。如果是这样我怎么写我列表那里。请帮帮我..?

1 个答案:

答案 0 :(得分:0)

删除Foreach循环中的返回

 var userListsTemp=null;
foreach (int workFlowServiceDetail in workFlowServiceDetails)
{
   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);

     /*****************************************Problem in this loop**********/
     if (userLists.UserList.Contains(userId))
     {
          serviceName = strTxt[0].ToString() + ";Aspir.Pan.Common.WorkFlowNotificationServices;" + strTxt[2].ToString();
          permissionId = workFlowServiceDetail;

          //return userLists;
          if(userListsTemp==null)
          {
              userListsTemp=userLists;
          }
          else
          {
              userListsTemp.Concat(userLists).ToList(); 
          }    
      }
   }
}
serviceName = string.Empty;
permissionId = 0;
return null;