单独返回项目而不是列表中的项目

时间:2012-11-09 19:18:32

标签: c# asp.net-mvc

我有这个方法返回某个案例的所有党员,并且它们全部返回显示在一行中。我想打破这一点,以便每一方都是自己的一排。我并非所有各方都返回列表然后显示该列表 - 我希望每个方都返回并继续循环,直到该案例的所有各方都在一个单独的行中返回。

当前方法返回列表中的所有参与方:

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;
    }

目前,该方法会将答案显示为:

case# - caseName - party1,party2,party3,party4,party5

我希望它显示为:

案例# - 案例名称 - 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);
    }

0 个答案:

没有答案