Exemple #1
0
        public async Task<HttpResponseMessage> GetColumnLevelMetadata(int fileId)
        {
            ////HttpResponseMessage response = await GetColumnLevelMetadataFromFile(fileId);
            ////return response;

            DM.File file = fileService.GetFileByFileId(fileId);
            if (file == null)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, MessageStrings.FileNotFound);
            }

            ////List<ColumnLevelMetadata> columnLevelMetadataList = await response.Content.ReadAsAsync<List<ColumnLevelMetadata>>();

            List<ColumnLevelMetadata> columnLevelMetadataList = new List<ColumnLevelMetadata>();

            if (file.FileColumns != null && file.FileColumns.Any())
            {
                foreach (FileColumn fileColumn in file.FileColumns)
                {
                    ColumnLevelMetadata columnLevelMetadata = new ColumnLevelMetadata()
                    {
                        Id = fileColumn.FileColumnId,
                        SelectedEntityName = fileColumn.EntityName,
                        EntityDescription = fileColumn.EntityDescription,
                        Name = fileColumn.Name,
                        Description = fileColumn.Description,
                        SelectedTypeId = fileColumn.FileColumnTypeId.Value,
                        SelectedUnitId = fileColumn.FileColumnUnitId
                    };

                    columnLevelMetadataList.Add(columnLevelMetadata);
                }
            }

            ColumnLevelMetadataViewModel columnLevelMetadataViewModel = new ColumnLevelMetadataViewModel();
            columnLevelMetadataViewModel.MetadataList = columnLevelMetadataList;
            try
            {
                columnLevelMetadataViewModel.SheetList = await this.fileService.GetDocumentSheetDetails(file);
            }
            catch (FileFormatException ex)
            {
                diagnostics.WriteErrorTrace(TraceEventId.Exception, ex);
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
            }

            columnLevelMetadataViewModel.TypeList = this.fileService.RetrieveFileColumnTypes();
            columnLevelMetadataViewModel.UnitList = this.fileService.RetrieveFileColumnUnits();

            return Request.CreateResponse(HttpStatusCode.OK, columnLevelMetadataViewModel);
        }
        private static IList<ColumnLevelMetadata> CreateColumnLevelMetadataList(string sheetName, IEnumerable<SheetCell> headerCells)
        {
            IList<ColumnLevelMetadata> columnLevelMetadaList = new List<ColumnLevelMetadata>();

            if (headerCells == null || headerCells.Count() == 0)
            {
                return columnLevelMetadaList;
            }

            for (int i = 0; i < headerCells.Count(); i++)
            {
                ColumnLevelMetadata columnLevelMetadata = new ColumnLevelMetadata();
                columnLevelMetadata.SelectedEntityName = sheetName;
                columnLevelMetadata.Name = headerCells.ElementAt(i).Value;

                columnLevelMetadaList.Add(columnLevelMetadata);
            }

            return columnLevelMetadaList;
        }
        private static IList<ColumnLevelMetadata> CreateColumnLevelMetadataList(string fileName, List<string> headers)
        {
            IList<ColumnLevelMetadata> columnLevelMetadaList = new List<ColumnLevelMetadata>();

            if (headers == null || headers.Count == 0)
            {
                return columnLevelMetadaList;
            }

            for (int i = 0; i < headers.Count; i++)
            {
                ColumnLevelMetadata columnLevelMetadata = new ColumnLevelMetadata();
                columnLevelMetadata.SelectedEntityName = fileName;
                columnLevelMetadata.Name = headers.ElementAt(i);

                columnLevelMetadaList.Add(columnLevelMetadata);
            }

            return columnLevelMetadaList;
        }