Marius Vasile

Marius Vasile

  • 601
  • 1.9k
  • 143.1k

asp.net core foreach and if not working properly

Feb 19 2021 9:16 AM
I have the below procedure
 
  1. var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);  
  2.             var orgid = await _context.UsersData.Where(s => s.Id == userId).Select(s => s.OrgID).FirstOrDefaultAsync();  
  3.   
  4.             var roles = await (from a in _context.UsersData.Where(a => a.Id == userId)  
  5.                                    join b in _context.CompanyDatas on a.OrgID equals b.OrgID into TempData1  
  6.                                    from c in TempData1  
  7.                                    join d in _context.AppIdentityRoles on a.Id equals d.UserId into TempData2  
  8.                                    from e in TempData2  
  9.                                    join f in _context.UsersRole on e.RoleId equals f.Id into TempData3  
  10.                                    from g in TempData3  
  11.   
  12.                                    select new   
  13.                                    {  
  14.                                        RoleName = g.Name  
  15.                                    }).ToListAsync();  
  16.   
  17.   
  18.   
  19.             string myS = "WOCraftTL";  
  20.             var status = await _context.WOMains.Where(s => s.WOMainID == womainid).Select(s => s.WOStatus).SingleOrDefaultAsync();  
  21.             foreach (var a in roles)  
  22.             {  
  23.                   
  24.                 if (a.RoleName.Contains(myS) && status == "In Progress")  
  25.                 {  
  26.                     return RedirectToPage("/WO/WOReport"new { womainid = womainid });  
  27.                 }  
  28.                 else  
  29.                 {  
  30.                     var womainidP = await _context.WOMains.Where(s => s.WONumber == won && s.WONumberS == 0).Select(s => s.WOMainID).FirstOrDefaultAsync();  
  31.                     return RedirectToPage("/WO/WOForm"new { womainid = womainidP, woS = womainid, status = WOStatusT });  
  32.                 }  
  33.             }  
the user can have multiple roles, however, WOCraftTL is assigned, I verified that and the status for one specific item is "In Progress" but when I run the program the if doesn't work, always else is activated. What am I doing wrong?

Answers (4)