private void AddColumnInfoToDb(int newColumnType, UploadViewFileColumn column) { string columnName = column.ColumnName; IngestionColumnInfo uploadedColumnInfo = new IngestionColumnInfo { IngestionColumnType = newColumnType, IngestionColumnName = columnName }; db.IngestionColumnInfoes.Add(uploadedColumnInfo); db.SaveChanges(); }
private IngestionColumnType AddColumnTypeToDb(UploadViewFileColumn column) { string uniqueColumnTypeName = MakeUniqueColumnTypeName(column.ColumnName); string columnName = column.ColumnName; string dataType = column.DataType; IngestionColumnType ingestionColumnType = new IngestionColumnType { HeaderName = columnName, IngestionColumnDataType = dataType, IngestionColumnTypeName = uniqueColumnTypeName }; db.IngestionColumnTypes.Add(ingestionColumnType); db.SaveChanges(); return ingestionColumnType; }
private List<UploadViewFileColumn> MakeColumnTypeList(int headerRow, ExcelWorksheet worksheet) { // this assumes that columns in the spreadsheet with blank header rows do // not contain relevant data List<UploadViewFileColumn> columnList = new List<UploadViewFileColumn>(); for (int column = 1; column <= worksheet.Dimension.End.Column; column++) { if (worksheet.Cells[headerRow, column].Value != null) { if (worksheet.Cells[headerRow, column].Value.ToString() != "") { UploadViewFileColumn homeViewColumn = new UploadViewFileColumn { ColumnName = worksheet.Cells[headerRow, column].Value.ToString().Trim(), DataType = SetType(worksheet.Cells[headerRow + 1, column].Value) }; if (homeViewColumn.ColumnName == "") homeViewColumn.ColumnName = "NONAME"; columnList.Add(homeViewColumn); } } } return columnList; }
//private List<int> MakeListOfMatchingFileTypes(List<UploadViewFileTab> uploadedFileTabList) //{ // // this is a list of filetypes that have this many tabs associated with them // int tabCount = uploadedFileTabList.Count; // var listOfPossibleFileTypeIds = (from x in db.IngestionFileTypes // where x.NumberOfTabs == tabCount // select x.Id).ToList(); // // if there are no filetypeid numbers in this list then this type of file is not // // in the database and we bail out // if (!listOfPossibleFileTypeIds.Any()) return null; // // here the listofpossiblefiletypeIDs is a list of all of the file types that use this many tabs // // since there are filetypes in the db that have this many tabs // // let's further trim this list to the types of files whose tab parameters // // match the uploaded file's tab's parameters // listOfPossibleFileTypeIds = MakeListOfTabsThatMatchFiles(uploadedFileTabList, listOfPossibleFileTypeIds); // if (!listOfPossibleFileTypeIds.Any()) return null; // // now the list of matchingFiles is a list of all of the filetype ids that tabs of this sort are in // // are in according to the wtiw db. let's compare that list to the list of file type ids that use // // this many tabs according to the tabtypes db. if it is in the list of possible IDs and not in the matching files // // let's remove it from the list of possible IDs // return listOfPossibleFileTypeIds; //} //private List<int> MakeListOfTabsThatMatchFiles(List<UploadViewFileTab> uploadedFileTabList, List<int> possibleFileTypeIDs ) //{ // List<int> matchingFiles = possibleFileTypeIDs; // foreach (var uploadedTab in uploadedFileTabList) // { // int columnCount = uploadedTab.ColumnList.Count; // // do tabs with this many columns exist in the db // var tabTypes = (from x in db.IngestionTabTypes // where x.NumberOfDataColumns == columnCount // select x.Id).ToList(); // // if no match on this it is a new file type // if (!tabTypes.Any()) return null; // tabTypes = MakeListOfColumnsThatMatchTabs(uploadedTab.ColumnList, tabTypes); // if (!tabTypes.Any()) return null; // // at this point the list matchingTabs consists of the tabtypeIDs from the db // // which match the type of this tab // foreach (var matchingTab in tabTypes) // { // int tab = matchingTab; // var fileList = from x in db.WhichTabsInWhichFiles // where x.TabTypeID == tab // select x.FileTypeID; // if (!fileList.Any()) return null; // foreach (var fileID in matchingFiles) // { // if (!fileList.Contains(fileID)) matchingFiles.Remove(fileID); // } // if (!matchingFiles.Any()) return null; // } // } // return matchingFiles; //} //private List<int> MakeListOfColumnsThatMatchTabs(List<UploadViewFileColumn> uploadedColumnList, List<int> listOfMatchingTabs) //{ // foreach (var uploadedColumn in uploadedColumnList) // { // string dataType = uploadedColumn.DataType; // string columnName = uploadedColumn.ColumnName; // // does this column type already exist in the db // IQueryable<int> columnTypes = from x in db.IngestionColumnTypes // where ((x.IngestionColumnDataType == dataType) // && (x.HeaderName == columnName)) // select x.Id; // // if no match on this it is a new file type // if (!columnTypes.Any()) return null; // foreach (var columnType in columnTypes) // { // int type = columnType; // IQueryable<int> matchingTabsForThisColumn = from x in db.WhichColumnsInWhichTabs // where x.ColumnID == type // select x.TabID; // if (!matchingTabsForThisColumn.Any()) return null; // foreach (var matchingTab in listOfMatchingTabs) // { // if (!matchingTabsForThisColumn.Contains(matchingTab)) listOfMatchingTabs.Remove(matchingTab); // } // } // if (!listOfMatchingTabs.Any()) return null; // } // return listOfMatchingTabs; //} private int WhatColumnTypeIsThis(UploadViewFileColumn uploadedColumn) { int columnType = (from x in db.IngestionColumnTypes where ((x.HeaderName == uploadedColumn.ColumnName) && (x.IngestionColumnDataType == uploadedColumn.DataType)) select x.Id).FirstOrDefault(); return columnType; }