Ejemplo n.º 1
0
        public ActionResult Login(UserBus userBus, UserModel user)
        {
            if (ModelState.IsValid)
            {
                if (userBus.IsValid(user.email, user.password, user.userTypeId))
                {
                    CandidateProfileDL candDl = new CandidateProfileDL();
                    NoBordersDB        db     = new NoBordersDB();

                    //checking the user type ( candidate/recruiter)
                    var ut = userBus.userTypeId(user.email, user.password);
                    if (ut == 1)
                    {
                        //storing logged -in user id in session variable
                        var id = candDl.getCandidateId(user.email);
                        Session["candidate_id"] = id;


                        //getting logged in user details
                        var dummyModel = db.CandidateProfiles.SingleOrDefault(cand => cand.Id_candidate == id);

                        //getting the full name of the logged in user to be displayed on the UserProfile page
                        Session["user_name"] = dummyModel.First_name + " " + dummyModel.Last_name;

                        Membership.ValidateUser(user.email, user.password);
                        return(RedirectToAction("UserProfile", "User"));
                    }
                    else if (ut == 2)
                    {
                        Session["recruiter_email"] = user.email;
                        return(RedirectToAction("CandidatesList", "Candidates"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Login data is incorrect!");
                }
            }
            return(View(user));
        }