public ActionResult Login([Bind(Include = "PhoneNumber,Password")] UserInformation reg)//Login to validate the User Credentials { try { using (JobPortalSystemContext1 db = new JobPortalSystemContext1()) { var obj = db.UserInformations.Where(a => a.PhoneNumber.Equals(reg.PhoneNumber) && a.Password.Equals(reg.Password)).FirstOrDefault(); if (obj != null) { if (obj.UserType == "Admin") { Session["PhoneNumber"] = obj.PhoneNumber.ToString(); Session["Password"] = obj.Password.ToString(); Session["UserType"] = obj.UserType.ToString(); Session["FirstName"] = obj.FirstName.ToString(); return(RedirectToAction("Index", "JobDetailsAdmin")); } else if (obj.UserType == "User") { Session["PhoneNumber"] = obj.PhoneNumber.ToString(); Session["UserType"] = obj.UserType.ToString(); Session["Password"] = obj.Password.ToString(); Session["FirstName"] = obj.FirstName.ToString(); return(RedirectToAction("Index", "JobDetails")); } else { return(RedirectToAction("Login")); } } else { return(RedirectToAction("Login")); } } } catch (Exception e) { ModelState.AddModelError("", "Failed to Login"); return(RedirectToAction("Login")); } }
public ActionResult Create([Bind(Include = "UserId,Password,FirstName,LastName,Age,Gender,Address,PhoneNumber,UserType")] UserInformation userInformation) { try { using (JobPortalSystemContext1 db = new JobPortalSystemContext1()) { db.UserInformations.Add(userInformation); db.SaveChanges(); Session["PhoneNumber"] = userInformation.PhoneNumber.ToString(); Session["Password"] = userInformation.Password.ToString(); Session["UserType"] = userInformation.UserType.ToString(); Session["FirstName"] = userInformation.FirstName.ToString(); return(RedirectToAction("Index", "JobDetails")); } } catch (Exception) { ModelState.AddModelError("", "Failed to Register details"); return(RedirectToAction("Create")); } }