我有这种方法可以返回某个案例的所有党员,并且他们都返回以显示在一行中。我想把它分解,这样每一方都会有自己的一排。我并不是所有的各方都返回到一个列表然后显示该列表 - 我希望每一方都返回并继续循环,直到该案例的所有各方都返回一个单独的行。
当前方法返回列表中的所有各方:
public IList<Party> GetAssignedPartiesForThisAndAssociatedCases(Guid caseId, int officeId)
{
IQueryable<AssociatedCase> associatedCases = _associatedCaseService.GetAll(caseId, officeId);
IQueryable<Case> cases = (associatedCases != null && associatedCases.Count() > 0)
? associatedCases.Select(a => a.Case)
: _caseRepository.FindAll().Where(c => c.CaseId == caseId);
var parties = new List<Party>();
foreach (Case c in cases)
{
foreach (Appointment a in c.Appointments.Where(a => a.OfficeId == officeId))
{
foreach (AppointmentParty p in a.AppointmentParties.Where(ap=>ap.DateOff == null || ap.DateOff > DateTime.Today))
{
AppointmentParty p1 = p;
if (!parties.Contains(p1.Party)) parties.Add(p1.Party);
}
}
}
return parties;
}
目前,该方法将显示答案为:
案例#——案例名称——party1、party2、party3、party4、party5
我希望它显示为:
case # -- caseName -- party1
case # -- caseName -- party2
case # -- caseName -- party3
case # -- caseName -- party4
case # -- caseName -- party5
这是我的控制器中显示与各方的案例列表的部分:
IEnumerable<AssociatedCase> associatedCases = _caseCompositeService.GetAssociatedCases(viewModel.CaseId,
_currentUser.OfficeId).Where(a=>a.CaseId != viewModel.CaseId);
viewModel.AssociatedCases = associatedCases;
上面控制器中的 GetAssociatedCases 是从 CaseCompositeService 文件中调用的:
public IEnumerable<AssociatedCase> GetAssociatedCases(Guid caseId, int officeId)
{
IQueryable<AssociatedCase> associatedCases = _associatedCaseService.GetAll(caseId, officeId);
return associatedCases;
}
然后从 AssociatedCaseService 调用 GetAll 方法:
public IQueryable<AssociatedCase> GetAll(Guid caseId, int officeId)
{
AssociatedCase associatedCase =
_associatedCaseRepository.FindAll().SingleOrDefault(a => a.OfficeId == officeId && a.CaseId == caseId);
if (associatedCase == null)
return new List<AssociatedCase>().AsQueryable();
return _associatedCaseRepository.FindAll().Where(a => a.AssociatedCaseId == associatedCase.AssociatedCaseId);
}