0% found this document useful (0 votes)
3 views3 pages

ZX

The Users method is an asynchronous action that retrieves user data based on specified UserType and search criteria. It checks for valid session tokens and filters users from the database according to their type (Candidate, Institution, Company, Recruiter) and search input. If no users are found or an unauthorized access exception occurs, it redirects to the login page or returns the full user list accordingly.

Uploaded by

sk.lateef2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

ZX

The Users method is an asynchronous action that retrieves user data based on specified UserType and search criteria. It checks for valid session tokens and filters users from the database according to their type (Candidate, Institution, Company, Recruiter) and search input. If no users are found or an unauthorized access exception occurs, it redirects to the login page or returns the full user list accordingly.

Uploaded by

sk.lateef2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

public async Task<IActionResult> Users(string? UserType, string?

search)
{
try
{
//checking SessinID and Token
var (token, sessionId) = _cookieService.GetTokenAndSessionId();
if (string.IsNullOrEmpty(token) || string.IsNullOrEmpty(sessionId))
{
throw new UnauthorizedAccessException("Token or SessionID is missing");
}
List<string> canid = new List<string>();
List<string> insid = new List<string>();
List<string> comid = new List<string>();

var users = await _context.UsersTbs


.Include(user => user.CandidateInfoTbs)
.Include(user => user.InstitutionsTbs)
.Include(user => user.CompaniesTbs)
.Select(u => new { u.Id, u.UserType, u.Status, u.CandidateInfoTbs,
u.InstitutionsTbs, u.CompaniesTbs, u.IsDeleted, u.IsVerified })
.ToListAsync();

var userid = _context.UsersTbs


.Select(u => u.Id);

if (UserType != null)
{
foreach (var user in users)
{
if (UserType == "Candidate")
{
users = users.Where(a => a.UserType == 1).ToList();

if (search != null)
{
string? a = user.CandidateInfoTbs.Where(a => a.FirstName.ToLower() ==
search.ToLower()).Select(a => a.UserId).FirstOrDefault();
canid.Add(a);
}
}
if (UserType == "Institution")
{
users = users.Where(a => a.UserType == 2).ToList();

if (search != null)
{
string? b = user.InstitutionsTbs.Where(a => a.InsttnName.ToLower() ==
search.ToLower()).Select(a => a.UserId).FirstOrDefault();
insid.Add(b);
}
}
if (UserType == "Company")
{
users = users.Where(a => a.UserType == 3).ToList();

if (search != null)
{
string? c = user.CompaniesTbs.Where(a => a.CompName.ToLower() ==
search.ToLower()).Select(a => a.UserId).FirstOrDefault();
comid.Add(c);
}
}
if (UserType == "Recruiter")
{
users = users.Where(a => a.UserType == 4).ToList();

if (search != null)
{
string? d = user.CompaniesTbs.Where(a => a.CompName.ToLower() ==
search.ToLower()).Select(a => a.UserId).FirstOrDefault();
comid.Add(d);
}

//if(UserType == "All")
//{
// users = users.Where(a => a.UserType == 1).ToList();

// if (search != null)
// {
// string? a = user.CandidateInfoTbs.Where(a => a.FirstName.ToLower()
== search.ToLower()).Select(a => a.UserId).FirstOrDefault();
// canid.Add(a);
// }
// users = users.Where(a => a.UserType == 2).ToList();

// if (search != null)
// {
// string? b = user.InstitutionsTbs.Where(a => a.InsttnName ==
search).Select(a => a.UserId).FirstOrDefault();
// insid.Add(b);
// }

// if (search != null)
// {
// string? c = user.CompaniesTbs.Where(a => a.CompName ==
search).Select(a => a.UserId).FirstOrDefault();
// comid.Add(c);
// }

// if (search != null)
// {
// string? d = user.CompaniesTbs.Where(a => a.CompName ==
search).Select(a => a.UserId).FirstOrDefault();
// comid.Add(d);
// }
//}
}
}

ViewBag.search = search;
if (canid.Any())
{
users = users.Where(u => canid.Contains(u.Id.ToString())).ToList();
}
else if (insid.Any())
{
users = users.Where(u => insid.Contains(u.Id.ToString())).ToList();
}
else if (comid.Any())
{
users = users.Where(u => comid.Contains(u.Id.ToString())).ToList();
}

ViewBag.UserType = UserType;
return View(users);
}
return View(users);
}
catch (UnauthorizedAccessException)
{
return RedirectToAction("Login", "Auth");
}
catch (Exception ex)
{
throw;
}

return View("users");
}

You might also like