public async Task <IActionResult> List(Guid?appId) { if (appId == null) { return(NotFound()); } var eDocumentList = (await _dataService.GetDtoAsync <EDocumentListDTO>(extraParameters: new object[] { $"\'{appId}\'" })).ToList(); var eDocumentIds = eDocumentList.Select(x => x.Id); var branchList = (await _dataService.GetDtoAsync <BranchListDTO>(x => x.ApplicationId == appId)).ToList(); var branchContractors = _dataService.GetEntity <BranchEDocument>() .Where(x => eDocumentIds.Contains(x.EDocumentId)).ToList(); foreach (var contr in eDocumentList) { contr.ListOfBranches = new List <string>(); contr.ListOfBranches.AddRange(branchList.Where(br => branchContractors.Where(x => x.EDocumentId == contr.Id).Select(x => x.BranchId).Contains(br.Id)).Select(st => st.Name + ',' + st.PhoneNumber)); } ViewBag.appId = appId; var app = (await _dataService.GetDtoAsync <AppStateDTO>(x => x.Id == appId))?.FirstOrDefault(); if (app == null) { return(NotFound()); } ViewBag.appId = appId; ViewBag.AppSort = app.AppSort; string eDocType; switch (app.AppType) { case "PRL": eDocType = "ManufactureDossier"; break; case "IML": eDocType = "ImportDossier"; break; case "TRL": eDocType = ""; break; default: return(NotFound()); } ViewBag.eDocType = eDocType; ViewBag.IsAddable = _entityStateHelper.ApplicationAddability(appId.Value).IsEdocument; ViewBag.appType = app.AppType; eDocumentList.ForEach(dto => dto.IsEditable = _entityStateHelper.IsEditableEdoc(dto.Id) ?? false); if (app.AppSort == "AddBranchApplication") { eDocumentList = eDocumentList.OrderBy(x => x.IsFromLicense).ToList(); return(PartialView("List_AddBranchApplication", eDocumentList)); } if (app.AppSort == "AddBranchInfoApplication") { return(PartialView("List_AddBranchInfoApplication", eDocumentList)); } return(PartialView(eDocumentList)); }