private void SetUserSessionID() { if (TempData["userid"] == null) { var userid = User.Identity.GetUserId(); var applicant = new TalentContext().Employees.Where(s => s.UserId == userid); if (applicant.Any()) { //var applicantid = new TalentContext().Employees.Where(s => s.UserId == userid).FirstOrDefault().ID; var applicantid = applicant.FirstOrDefault().ID; TempData["userid"] = applicantid; } } }
private void SetEmployeeSessionID() { if (Session["employeeid"] == null) { var userid = User.Identity.GetUserId(); var emp = new TalentContext().Employees.Where(s => s.UserId == userid); if (emp.Any()) { var empid = emp.FirstOrDefault().ID; Session["employeeid"] = empid; } else { // throw new HttpException(HttpStatusCode.BadRequest,"BadRequest"); // throw new HttpException(); } } }
private void SetUserSessionID() { if (TempData["userid"] == null) { var userid = User.Identity.GetUserId(); var applicant = new TalentContext().Applicants.Where(s => s.UserId == userid); if (applicant.Any()) { var applicantid = applicant.FirstOrDefault().ID; TempData["userid"] = applicantid; } else { // throw new HttpException(HttpStatusCode.BadRequest,"BadRequest"); // throw new HttpException(); } } }
protected override bool AuthorizeCore(HttpContextBase httpContext) { returnto = httpContext.Request.CurrentExecutionFilePath; if (!Equals(httpContext.User.Identity.Name, "")) { ApplicationDbContext context = new ApplicationDbContext(); var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); var id = UserManager.FindByName(httpContext.User.Identity.Name).Id; var user = new TalentContext().Employees.Where(x => x.UserId == id); if (user.Any()) { return(true); } return(false); } else { return(false); } }