Esempio n. 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);
        }
Esempio n. 2
0
        public async Task<HttpResponseMessage> GetColumnLevelMetadataFromFile(int fileId)
        {
            DM.File file = fileService.GetFileByFileId(fileId);
            if (file == null)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, MessageStrings.FileNotFound);
            }

            ColumnLevelMetadataViewModel columnLevelMetadataViewModel = new ColumnLevelMetadataViewModel();
            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();

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

            return Request.CreateResponse(HttpStatusCode.OK, columnLevelMetadataViewModel);
        }