@@ -143,7 +143,7 @@ public async Task<OperationDataResult<List<TimePlanningWorkingHoursModel>>> Inde
143143 CommentWorker = x . WorkerComment . Replace ( "\r " , "<br />" ) ,
144144 CommentOffice = x . CommentOffice . Replace ( "\r " , "<br />" ) ,
145145 // CommentOfficeAll = x.CommentOfficeAll,
146- IsLocked = ( x . Date < DateTime . Now . AddDays ( - ( int ) maxDaysEditable ) || x . Date == midnight ) ,
146+ IsLocked = ( x . Date < DateTime . Now . AddDays ( - ( int ) ( maxDaysEditable ?? 0 ) ) || x . Date == midnight ) ,
147147 IsWeekend = x . Date . DayOfWeek == DayOfWeek . Saturday || x . Date . DayOfWeek == DayOfWeek . Sunday ,
148148 NettoHoursOverride = x . NettoHoursOverride ,
149149 NettoHoursOverrideActive = x . NettoHoursOverrideActive
@@ -228,7 +228,7 @@ public async Task<OperationDataResult<List<TimePlanningWorkingHoursModel>>> Inde
228228 {
229229 Date = model . DateFrom . AddDays ( i ) ,
230230 WeekDay = ( int ) model . DateFrom . AddDays ( i ) . DayOfWeek ,
231- IsLocked = model . DateFrom . AddDays ( i ) < DateTime . Now . AddDays ( - ( int ) maxDaysEditable ) ||
231+ IsLocked = model . DateFrom . AddDays ( i ) < DateTime . Now . AddDays ( - ( int ) ( maxDaysEditable ?? 0 ) ) ||
232232 model . DateFrom . AddDays ( i ) == midnight ,
233233 IsWeekend = model . DateFrom . AddDays ( i ) . DayOfWeek == DayOfWeek . Saturday
234234 || model . DateFrom . AddDays ( i ) . DayOfWeek == DayOfWeek . Sunday
@@ -516,7 +516,7 @@ public async Task<OperationDataResult<TimePlanningWorkingHourSimpleModel>> ReadS
516516
517517 if ( sdkSite == null )
518518 {
519- return new OperationDataResult < TimePlanningWorkingHourSimpleModel > ( false , "Site not found" , null ) ;
519+ return new OperationDataResult < TimePlanningWorkingHourSimpleModel > ( false , "Site not found" , null ! ) ;
520520 }
521521
522522 var midnight = new DateTime ( dateTime . Year , dateTime . Month , dateTime . Day , 0 , 0 , 0 ) ;
@@ -642,7 +642,7 @@ public async Task<OperationDataResult<TimePlanningHoursSummaryModel>> CalculateH
642642
643643 if ( sdkSite == null )
644644 {
645- return new OperationDataResult < TimePlanningHoursSummaryModel > ( false , "Site not found" , null ) ;
645+ return new OperationDataResult < TimePlanningHoursSummaryModel > ( false , "Site not found" , null ! ) ;
646646 }
647647
648648 var planRegistrations = await dbContext . PlanRegistrations
@@ -708,7 +708,7 @@ public async Task<OperationDataResult<TimePlanningWorkingHoursModel>> Read(int s
708708 if ( result == null )
709709 {
710710 return new OperationDataResult < TimePlanningWorkingHoursModel > ( false ,
711- localizationService . GetString ( "PlanRegistrationNotFound" ) , null ) ;
711+ localizationService . GetString ( "PlanRegistrationNotFound" ) , null ! ) ;
712712 }
713713 return new OperationDataResult < TimePlanningWorkingHoursModel > ( true , "Plan registration found" ,
714714 result ) ;
@@ -992,7 +992,7 @@ public async Task<OperationResult> UpdateWorkingHour(TimePlanningWorkingHoursUpd
992992 : DateTime . Parse ( model . Pause5StoppedAt ) ,
993993 Flex = 0 ,
994994 WorkerComment = model . CommentWorker ,
995- SdkSitId = ( int ) sdkSite . MicrotingUid ,
995+ SdkSitId = sdkSite . MicrotingUid ! . Value ,
996996 Shift1PauseNumber = model . Shift1PauseNumber ,
997997 Shift2PauseNumber = model . Shift2PauseNumber ,
998998 } ;
@@ -2258,11 +2258,11 @@ private void FillDataRow(Row dataRow, Worker worker, Microting.eForm.Infrastruct
22582258 }
22592259 }
22602260
2261- private Cell CreateCell ( string value )
2261+ private Cell CreateCell ( string ? value )
22622262 {
22632263 return new Cell ( )
22642264 {
2265- CellValue = new CellValue ( value ) ,
2265+ CellValue = new CellValue ( value ?? string . Empty ) ,
22662266 DataType = CellValues . String // Explicitly setting the data type to string
22672267 } ;
22682268 }
@@ -2326,8 +2326,8 @@ private void ValidateExcel(string fileName)
23262326 count ++ ;
23272327 sb . Append ( ( "Error Count : " + count ) + "\r \n " ) ;
23282328 sb . Append ( ( "Description : " + error . Description ) + "\r \n " ) ;
2329- sb . Append ( ( "Path: " + error . Path . XPath ) + "\r \n " ) ;
2330- sb . Append ( ( "Part: " + error . Part . Uri ) + "\r \n " ) ;
2329+ sb . Append ( ( "Path: " + error . Path ? . XPath ) + "\r \n " ) ;
2330+ sb . Append ( ( "Part: " + error . Part ? . Uri ) + "\r \n " ) ;
23312331 sb . Append ( "\r \n -------------------------------------------------\r \n " ) ;
23322332 }
23332333
@@ -2694,10 +2694,18 @@ public async Task<OperationResult> Import(IFormFile file)
26942694 using ( var spreadsheetDocument = SpreadsheetDocument . Open ( stream , false ) )
26952695 {
26962696 var workbookPart = spreadsheetDocument . WorkbookPart ;
2697+ if ( workbookPart == null )
2698+ {
2699+ return new OperationResult ( false , localizationService . GetString ( "FileFormatError" ) ) ;
2700+ }
26972701 var sheets = workbookPart . Workbook . Sheets ;
26982702
26992703 foreach ( Sheet sheet in sheets )
27002704 {
2705+ if ( sheet . Name ? . Value == null || sheet . Id == null )
2706+ {
2707+ continue ;
2708+ }
27012709 var site = await sdkContext . Sites . FirstOrDefaultAsync ( x => x . Name . Replace ( " " , "" ) . ToLower ( ) == sheet . Name . Value . Replace ( " " , "" ) . ToLower ( ) ) ;
27022710 if ( site == null )
27032711 {
@@ -2711,7 +2719,7 @@ public async Task<OperationResult> Import(IFormFile file)
27112719 foreach ( var row in rows )
27122720 {
27132721 // Skip header row
2714- if ( row . RowIndex == 1 )
2722+ if ( row . RowIndex ? . Value == 1 )
27152723 {
27162724 continue ;
27172725 }
@@ -2849,10 +2857,10 @@ private string GetCellValue(WorkbookPart workbookPart, Row row, int columnIndex)
28492857 var columnLetter = GetColumnLetter ( columnIndex ) ;
28502858
28512859 // Create the cell reference (e.g., A1, B1, C1)
2852- var cellReference = columnLetter + row . RowIndex ;
2860+ var cellReference = columnLetter + row . RowIndex ? . Value ;
28532861
28542862 // Find the cell with the matching CellReference
2855- var cell = row . Elements < Cell > ( ) . FirstOrDefault ( c => c . CellReference . Value == cellReference ) ;
2863+ var cell = row . Elements < Cell > ( ) . FirstOrDefault ( c => c . CellReference ? . Value == cellReference ) ;
28562864
28572865 if ( cell == null || cell . CellValue == null )
28582866 {
@@ -2866,30 +2874,36 @@ private string GetCellValue(WorkbookPart workbookPart, Row row, int columnIndex)
28662874 if ( sharedStringTablePart != null )
28672875 {
28682876 var sharedStringTable = sharedStringTablePart . SharedStringTable ;
2869- return sharedStringTable . ElementAt ( int . Parse ( cell . CellValue . Text ) ) . InnerText ;
2877+ if ( sharedStringTable != null )
2878+ {
2879+ return sharedStringTable . ElementAt ( int . Parse ( cell . CellValue . Text ) ) . InnerText ;
2880+ }
28702881 }
28712882 }
28722883
28732884 // Check if the cell has a StyleIndex (to determine if it's a date)
28742885 if ( cell . StyleIndex != null )
28752886 {
28762887 var stylesPart = workbookPart . WorkbookStylesPart ;
2877- var cellFormat = stylesPart . Stylesheet . CellFormats . ElementAt ( ( int ) cell . StyleIndex . Value ) as CellFormat ;
2878- var isDate = IsDateFormat ( stylesPart , cellFormat ) ;
2879-
2880- // If it's a date format, interpret the numeric value as a date
2881- if ( isDate && double . TryParse ( cell . CellValue . Text , out var oaDate ) )
2888+ if ( stylesPart != null )
28822889 {
2883- var dateValue = DateTime . FromOADate ( oaDate ) ;
2884- return dateValue . ToString ( "dd.MM.yyyy" ) ; // Format as a date
2890+ var cellFormat = stylesPart . Stylesheet . CellFormats . ElementAt ( ( int ) cell . StyleIndex . Value ) as CellFormat ;
2891+ var isDate = IsDateFormat ( stylesPart , cellFormat ) ;
2892+
2893+ // If it's a date format, interpret the numeric value as a date
2894+ if ( isDate && double . TryParse ( cell . CellValue . Text , out var oaDate ) )
2895+ {
2896+ var dateValue = DateTime . FromOADate ( oaDate ) ;
2897+ return dateValue . ToString ( "dd.MM.yyyy" ) ; // Format as a date
2898+ }
28852899 }
28862900 }
28872901
28882902 // Handle other numbers or strings
28892903 return cell . CellValue . Text ;
28902904 }
28912905
2892- private bool IsDateFormat ( WorkbookStylesPart stylesPart , CellFormat cellFormat )
2906+ private bool IsDateFormat ( WorkbookStylesPart stylesPart , CellFormat ? cellFormat )
28932907 {
28942908 if ( cellFormat == null || cellFormat . NumberFormatId == null )
28952909 {
0 commit comments