Source

main / Source / Excel / Excel.AddIn / Excel.AddIn / Controller / Controller.cs

Diff from to

Source/Excel/Excel.AddIn/Excel.AddIn/Controller/Controller.cs

             }
 
             List<ParameterDetail> paramterList = new List<ParameterDetail>();
-            foreach (var item in metadataListViewModel.ParameterMetadataList)
+            var paramData = from val in metadataListViewModel.ParameterMetadataList
+                            group val by val.EntityName into param
+                            select new
+                            {
+                                EntityName = param.Key,
+                                Description = param.Select(q => (String.IsNullOrEmpty(q.EntityDescription) ? "" : q.EntityDescription)).FirstOrDefault(q => !String.IsNullOrEmpty(q)),
+                                Values = param.ToList()
+                            }; 
+
+            foreach (var item in paramData)
             {
-                ParameterDetail model = new ParameterDetail();
-                model.Name = item.Name;
-                model.Description = item.Description;
-                model.Type = item.Type;
-                model.Units = item.Units;
-                paramterList.Add(model);
+                item.Values.ForEach(q =>
+                {
+                    paramterList.Add(new ParameterDetail
+                    {
+                         EntityName = item.EntityName,
+                          EntityDescription = item.Description,
+                           Name = q.Name,
+                            Description = q.Description,
+                             Type = q.Type,
+                              Units = q.Units
+                    });
+                });
             }
 
             metadataManager.UpdateMetadata(updatedMetadata, paramterList);
 
                 string identifier = string.Empty;
                 var identifierNode = metadataListViewModel.MetadataList.Where(m => m.Name.EndsWith(Common.Constants.IdentifierKeyName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
-                if (!string.IsNullOrWhiteSpace(identifierNode.Value))
+                if (identifierNode!= null && !string.IsNullOrWhiteSpace(identifierNode.Value))
                 {
                     identifier = identifierNode.Value;
                 }
                     {
                         identifier = getIdentifierResult.Message;
 
-                        identifierNode.Value = identifier;
+                        if (identifierNode != null)
+                        {
+                            identifierNode.Value = identifier;
+                        }
 
                         // Add Identifer as part of citation if the citation is already generated.
                         string citation = string.Empty;
                     if (canContinue)
                     {
                         List<object> obj = metadataManager.GetHeaderRow(output as Microsoft.Office.Interop.Excel.Range);
-
+                        string entityName = metadataManager.ActiveSheetName(output as Microsoft.Office.Interop.Excel.Range);
                         if (obj.Count > 0)
                         {
-                            metadataManager.UpdateParaMetadata(obj);
+                            metadataManager.UpdateParaMetadata(obj, sheetName:entityName);
                             canContinue = false;
                         }
                         else
                     if (canContinue)
                     {
                         List<object> obj = metadataManager.GetHeaderRow(output as Microsoft.Office.Interop.Excel.Range);
+                        string entityName = metadataManager.ActiveSheetName(output as Microsoft.Office.Interop.Excel.Range);
 
                         if (obj.Count > 0)
                         {
                                 {
                                     newParameterList.Add(new ParameterDetail()
                                     {
+                                        EntityName = entityName,
                                         Name = item.ToString().Trim()
                                     });
                                 }
         public List<string> GetSheetNames()
         {
             var sheetsNames = this.excelManager.GetSheetNames();
-
-            return sheetsNames.OrderBy(s => s.Key).Select(s => s.Value).ToList();
+            if (sheetsNames != null)
+            {
+                return sheetsNames.OrderBy(s => s.Key).Select(s => s.Value).ToList();
+            }
+            return null;
         }
 
         public string GetUserAgreement(string repositoryName)