skip to Main Content
public IActionResult LoginSubmit(Employee obj)
{
    var abc = _db.Employees.Where(x => x.EmailId == obj.EmailId).FirstOrDefault();
    var passAuth = _db.Employees.Where(x => x.Password == obj.Password).FirstOrDefault();

    if (abc != null && passAuth != null)
    {
        return RedirectToAction("Index", "EmployeeLeaves");
    }
    else
    {
        return RedirectToAction("Login","Employee");
    }
}

The code above is my employee controller and I want to pass the id to the Employeeleaves controller (shown below) so that I can use it and fetch data from both the tables.

Also the login authentication condition is pretty bad. Please suggest the logic for that also. Is there any way to then fetch data from both the tables in EmployeeLeavesController using LinqJoin

private ApplicationDbContext _db;

public EmployeeLeavesController(ApplicationDbContext db)
{
    _db = db;
}

public ViewResult Index(int EmployeeId)
{
    //var employeeLeaveEMp = _db.EmployeeLeaves.Include(c => c.Employee).ToList();
    //List<Employee> employeeList = _db.Employees.ToList();
    //List<EmployeeLeaves> employeeLeaves = _db.EmployeeLeaves.Where(emp => emp.EmployeeId == EmployeeId).ToList();

    return View();
}

2

Answers


  1. As far as passing value from controller to another is concerned. You can use a session variable to store the value and then use it in the other controller.
    And yes you can fetch records from both tables using join just give a try looking and JOIN queries in LINQ

    https://www.tutorialsteacher.com/linq/linq-joining-operator-join

    Login or Signup to reply.
  2. If you just want to pass EmployeeId after user logged-in, you can pass it like below:

    return RedirectToAction("Index", "EmployeeLeaves",new {EmployeeId=abc.Id});
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search