public JsonResult GetData() { using (ELaundryDBEntities db = new ELaundryDBEntities()) { MyRoleProvider mr = new MyRoleProvider(); db.Configuration.LazyLoadingEnabled = false; List <UserViewModel> lstuser = new List <UserViewModel>(); var lst = db.tblUsers.ToList(); string[] str = new string[] { }; foreach (var item in lst) { string roles = ""; str = mr.GetRolesForUser(item.Username); if (str.Length > 0) { foreach (var r in str) { roles += r.ToString() + ","; } roles = roles.Remove(roles.IndexOf(',')); } tblUserBranch tbub = db.tblUserBranches.Where(u => u.UserId == item.UserId).FirstOrDefault(); tblBranch br = db.tblBranches.Where(u => u.BranchId == tbub.BranchId).FirstOrDefault(); lstuser.Add(new UserViewModel() { UserId = item.UserId, Username = item.Username, Fullname = item.Fullname, RoleName = roles, BranchName = br.BranchName }); } return(Json(new { data = lstuser }, JsonRequestBehavior.AllowGet)); } }
// GET: Home public ActionResult Index() { var myRoleProvider = new MyRoleProvider(); var roles = myRoleProvider.GetRolesForUser().ToList <string>(); return(View(roles)); }
public ActionResult ChangeRoles(int?Id) { int id = Convert.ToInt32(Id); MyRoleProvider provider = new MyRoleProvider(); User user = db.Users.FirstOrDefault(u => u.Id == id); UserRolesChangeViewModel userRolesChangeViewModel = new UserRolesChangeViewModel { User = user, AllRoles = db.Roles.ToList(), UserRoles = provider.GetRolesForUser(user.Login).ToList() }; return(View(userRolesChangeViewModel)); }
public ActionResult ShowProfile() { if (HttpContext.User.Identity.Name == "") { return(RedirectToAction("HomeScreen", "Home")); } ProfileInfo userProfile = new ProfileInfo(); User currentUser = repository.GetUser(HttpContext.User.Identity.Name); MyRoleProvider tempRoleProvider = new MyRoleProvider(); userProfile.Roles = tempRoleProvider.GetRolesForUser(HttpContext.User.Identity.Name); userProfile.DisplayName = currentUser.Name; userProfile.UserTransactions = repository.GetUserTransactions(currentUser.UserID); userProfile.UserID = currentUser.UserID; return(View(userProfile)); }
public ActionResult Login(LoginInputModel logob, string ReturnUrl = " ") { try { //string username1 = User.Identity.Name; //Session.Clear(); //FormsAuthentication.SignOut(); // HttpContext.Cache.Remove(); //Response.Cookies[FormsAuthentication.FormsCookieName].Expires = DateTime.Now.AddYears(-1); //string username2 = User.Identity.Name; //Session["username"] = logob.UserName; //Session["Password"] = logob.Password; if (logob.UserName == null) { ViewBag.Unull = "!!!Enter User Id "; } if (logob.Password == null) { ViewBag.Pnull = "!!!Enter Password"; } if (ModelState.IsValid) { //formaut //Session["username"] = logob.UserName; //Session["Password"] = logob.Password; FormsAuthentication.SetAuthCookie(logob.UserName, false); var isValidUser = Membership.ValidateUser(logob.UserName, logob.Password); //string username3 = User.Identity.Name; //r iss=Membership.FindUsersByName() if (isValidUser) { //for (int i = 0; i < 3; i++) //{ //HttpContext.User = new GenericPrincipal(new GenericIdentity(logob.UserName), null); var role = rlob.GetRolesForUser(logob.UserName); HttpContext.User = new GenericPrincipal(new GenericIdentity(logob.UserName), role); if (User.Identity.IsAuthenticated) { //if (Url.IsLocalUrl(ReturnUrl)) //{ // return Redirect(ReturnUrl); //} //else //{ //ClassFY obfy = new ClassFY(); //ClassFY.Financeal_Year = obfy.getFYID(DateTime.Today); // string username = User.Identity.Name; return(RedirectToAction("EditeHomePage", "Admin")); //var l = (from U in db.tblUserLogins where U.U_USERID == username select U.U_EMAIL_ADDRESS).First(); // var user = db.tblUserLogins.Where(c => c.U_USERID == username).SingleOrDefault(); // Session["LoginUserNAme"] = user.U_EMAIL_ADDRESS.ToString(); //////if (user.U_TYPE.ToString() != null) //////{ ////// Session["UserType"] = user.U_TYPE.ToString(); ////// return RedirectToAction("MainIndex"); //////} //////else //////{ ////// Session.Clear(); ////// FormsAuthentication.SignOut(); //////} // break; // return RedirectToAction("RedirectToDefault"); //} } else { } //} } } ViewBag.LERROR = "User Id or Password Not Valid"; ModelState.AddModelError(string.Empty, "!!!User Id or Password Not Valid"); //ModelState.Clear(); // return RedirectToAction("Login"); //Session.Clear(); // FormsAuthentication.SignOut(); // return View("Login"); } catch { Session.Clear(); FormsAuthentication.SignOut(); } return(View("Login")); }
// GET: Test public ActionResult TestUserRole(string tempName) { MyRoleProvider tempRoleProvider = new MyRoleProvider(); return(PartialView(tempRoleProvider.GetRolesForUser(tempName))); }