Steven Langston

Steven Langston

  • NA
  • 15
  • 534

for each if break

Mar 12 2021 10:29 AM
I need this code to not add the draft document to the list if the loged in user is not the documents author.
 
Should it work?
  1. var listofdocuments = dbContext.Documents.ToList();    
  2. var filtered = new List<Document> () ;    
  3.   
  4. foreach (var document in listofdocuments)    
  5. {    
  6.     if (document.IsDraft)    
  7.     {    
  8.         if(document.Author == User.FindFirst(ClaimTypes.NameIdentifier).Value)    
  9.               {    
  10.             filtered.Add(document);    
  11.               }    
  12.          else                        
  13.         break;    
  14.                   
  15.     }    
  16.     filtered.Add(document);    
  17. }  

Answers (4)