public async Task GetDocumentsAsync()

in tree/master/cloud/src/solution/Microsoft.Legal.MatterCenter.Web/Common/DocumentProvision.cs [348:551]


        public async Task<SearchResponseVM> GetDocumentsAsync(SearchRequestVM searchRequestVM, ClientContext clientContext)
        {
            var searchObject = searchRequestVM.SearchObject;
            // Encode all fields which are coming from js
            SearchUtility.EncodeSearchDetails(searchObject.Filters, false);
            // Encode Search Term
            searchObject.SearchTerm = (searchObject.SearchTerm != null) ?
                WebUtility.HtmlEncode(searchObject.SearchTerm).Replace(ServiceConstants.ENCODED_DOUBLE_QUOTES, ServiceConstants.DOUBLE_QUOTE) : string.Empty;

            var searchResultsVM = await docRepository.GetDocumentsAsync(searchRequestVM,clientContext);

            if (searchResultsVM.TotalRows > 0)
            {                
                dynamic documentDataList = new List<dynamic>();
                IEnumerable<IDictionary<string, object>> searchResults = searchResultsVM.SearchResults;
                foreach (var searchResult in searchResults)
                {
                    
                    dynamic documentData = new ExpandoObject();
                    foreach (var key in searchResult.Keys)
                    {
                        documentData.Checker = false;
                        ServiceUtility.AddProperty(documentData, "Checker", false);
                        if (key.ToString().ToLower() == searchSettings.ManagedPropertyDocumentClientName.ToString().ToLower())
                        {
                            ServiceUtility.AddProperty(documentData,
                                configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentClient").Key,
                                searchResult[key].ToString());
                        }

                        if (key.ToString().ToLower() == searchSettings.ManagedPropertyFileName.ToString().ToLower())
                        {
                            if (searchResult[key] != null &&  (searchResult[key].ToString()!=string.Empty))
                            {
                                string fileNameWithOutExt = System.IO.Path.GetFileNameWithoutExtension(searchResult[key].ToString());
                                ServiceUtility.AddProperty(documentData,
                                    configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentName").Key,
                                    fileNameWithOutExt);
                            }
                                
                        }

                        if (key.ToString().ToLower() == searchSettings.ManagedPropertyDocumentClientId.ToString().ToLower())
                        {
                            ServiceUtility.AddProperty(documentData,
                                configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentClientId").Key,
                                searchResult[key].ToString());
                        }
                        if (key.ToString().ToLower() == searchSettings.ManagedPropertySiteName.ToString().ToLower())
                        {
                            ServiceUtility.AddProperty(documentData,
                                configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentClientUrl").Key,
                                searchResult[key].ToString());
                        }
                        if (key.ToString().ToLower() == searchSettings.ManagedPropertyDocumentVersion.ToString().ToLower())
                        {
                            ServiceUtility.AddProperty(documentData,
                                configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentVersion").Key,
                                searchResult[key].ToString());
                        }
                        if (key.ToString().ToLower() == searchSettings.ManagedPropertyDocumentMatterName.ToString().ToLower())
                        {
                            if(searchResult[key].ToString()!=string.Empty)
                            {
                                ServiceUtility.AddProperty(documentData,
                                    configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentMatterName").Key,
                                    searchResult[key].ToString());
                            }
                            else
                            {
                                ServiceUtility.AddProperty(documentData,
                                    configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentMatterName").Key,
                                    searchResult["Title"].ToString());
                            }
                        }                        
                        if (key.ToString().ToLower() == searchSettings.ManagedPropertyDocumentMatterId.ToString().ToLower())
                        {
                            ServiceUtility.AddProperty(documentData,
                                configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentMatterId").Key,
                                searchResult[key].ToString());
                        }
                        if (key.ToString().ToLower() == searchSettings.ManagedPropertyDocumentCheckOutUser.ToString().ToLower())
                        {
                            ServiceUtility.AddProperty(documentData,
                                configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentCheckoutUser").Key,
                                searchResult[key].ToString());
                        }
                        //-------------------------
                        if (key.ToString().ToLower() == searchSettings.ManagedPropertyCreated.ToString().ToLower())
                        {
                            if (searchResult[key] != null && (searchResult[key].ToString() != string.Empty))
                            {
                                ServiceUtility.AddProperty(documentData,
                                configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentCreatedDate").Key,
                                searchResult[key].ToString());
                            }
                        }
                        if (key.ToString().ToLower() == searchSettings.ManagedPropertyFileExtension.ToString().ToLower())
                        {
                            ServiceUtility.AddProperty(documentData,
                                configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentExtension").Key,
                                searchResult[key].ToString());
                            if (searchResult[key].ToString().ToLower() == "csv")
                            {
                                ServiceUtility.AddProperty(documentData,
                                configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentIconUrl").Key,
                                $"{generalSettings.SiteURL}/_layouts/15/images/generaldocument.png");
                            }
                            else if (searchResult[key].ToString().ToLower() != "pdf")
                            {
                                ServiceUtility.AddProperty(documentData,
                                configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentIconUrl").Key,
                                $"{generalSettings.SiteURL}/_layouts/15/images/ic{searchResult[key].ToString().ToLower()}.gif");
                            }
                            else
                            {
                                ServiceUtility.AddProperty(documentData,
                                configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentIconUrl").Key,
                                $"{generalSettings.SiteURL}/_layouts/15/images/ic{searchResult[key].ToString().ToLower()}.png");
                            }
                        }
                        
                        if (key.ToString().ToLower() == searchSettings.ManagedPropertyPath.ToString().ToLower())
                        {
                            ServiceUtility.AddProperty(documentData,
                                configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentOWAUrl").Key,
                                searchResult[key].ToString());
                            ServiceUtility.AddProperty(documentData,
                                configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentUrl").Key,
                                searchResult[key].ToString());
                        }
                        if (key.ToString().ToLower() == "serverredirectedurl")
                        {
                            if (searchResult[key] != null)
                            {
                                ServiceUtility.AddProperty(documentData,
                                    configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentOWAUrl").Key,
                                    searchResult[key].ToString());
                                ServiceUtility.AddProperty(documentData,
                                    configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentUrl").Key,
                                    searchResult[key].ToString());
                            }                                
                        }
                        if (key.ToString().ToLower() == searchSettings.ManagedPropertyLastModifiedTime.ToString().ToLower())
                        {
                            ServiceUtility.AddProperty(documentData,
                                configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentModifiedDate").Key,
                                searchResult[key].ToString());                            
                        }

                        if (key.ToString().ToLower() == searchSettings.ManagedPropertyAuthor.ToString().ToLower())
                        {
                            ServiceUtility.AddProperty(documentData,
                                configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentOwner").Key,
                                searchResult[key].ToString());
                        }
                        if (key.ToString().ToLower() == searchSettings.ManagedPropertyDocumentId.ToLower())
                        {
                            if (searchResult[key] != null)
                            {
                                ServiceUtility.AddProperty(documentData,
                                    configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("docId").Key,
                                    searchResult[key].ToString());
                            }
                        }

                        if (key.ToString().ToLower() == searchSettings.ManagedPropertyPracticeGroup.ToString().ToLower())
                        {
                            ServiceUtility.AddProperty(documentData,
                                configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentPracticeGroup").Key,
                                searchResult[key].ToString());
                        }

                        if (key.ToString().ToLower() == "parentlink")
                        {
                            ServiceUtility.AddProperty(documentData,
                                configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentParentUrl").Key,
                                searchResult[key].ToString());
                            string documentUrl = searchResult[key].ToString().Substring(0, searchResult[key].ToString().LastIndexOf("/"));
                            string siteUrl = searchResult["SiteName"].ToString();
                            string matterGuid = searchResult[key].ToString().ToLower().Replace(siteUrl, "").Split('/')[1];
                            string matterUrl = $"{siteUrl}/sitepages/{matterGuid}.aspx";
                            ServiceUtility.AddProperty(documentData,
                                configuration.GetSection("Search").GetSection("SearchColumnsUIPickerForDocument").GetSection("documentMatterUrl").Key,
                                matterUrl);
                        }  
                        ServiceUtility.AddProperty(documentData, "PinType", "Pin");
                        ServiceUtility.AddProperty(documentData, "DocGuid", Guid.NewGuid().ToString());
                    }
                    documentDataList.Add(documentData);
                }
                searchResultsVM.DocumentDataList = documentDataList;
                searchResultsVM.SearchResults = null;
                if (searchRequestVM.SearchObject.IsUnique && searchResultsVM.DocumentDataList != null && !string.IsNullOrWhiteSpace(searchRequestVM.SearchObject.UniqueColumnName))
                {
                    searchResultsVM.DocumentDataList = GetUniqueResults(searchRequestVM, searchResultsVM);
                }
                return searchResultsVM;
            }         
            else
            {
                return searchResultsVM;
            }
        }