public ActionResult SaveRoleAssignToUsers(RoleAssignUser roleassignUser, int[] Roles, int[] UserId)
        {
            for (int i = 0; i < UserId.Length; i++)
            {
                roleassignUser.UserId = UserId[i];
                roleassignUser.RoleId = Roles[i];
                db.RoleAssignUser.Add(roleassignUser);
                db.SaveChanges();
            }


            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public RoleAssignUser getStoredUserPermission()
        {
            string           username = FormsAuthentication.Decrypt(HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
            UserRegistration appuser  = db.User.SingleOrDefault(u => u.UserName.Equals(username, StringComparison.OrdinalIgnoreCase));

            try
            {
                RoleAssignUser userpermission = db.RoleAssignUser.SingleOrDefault(u => u.UserId == appuser.UserId);
                return(userpermission);
            }
            catch (NullReferenceException exp)
            {
                return(null);
            }
        }
Beispiel #3
0
        public ActionResult Action([Bind(Include = "UserId,UserName,Password,Salt,FirstName,LastName,Email,Phone,Address,SecurityQuestion,SecurityQuestionAnswer,IsActive,LastLogin")] UserRegistration userregistration, int Roles)
        {
            RoleAssignUser roleassignuser = new RoleAssignUser();

            if (ModelState.IsValid)
            {
                db.Entry(userregistration).State = EntityState.Modified;
                roleassignuser.RoleId            = Roles;
                roleassignuser.UserId            = userregistration.UserId;
                db.RoleAssignUser.Add(roleassignuser);
                db.SaveChanges();
                return(RedirectToAction("ApproveList"));
            }
            ViewBag.RoleId = new SelectList(db.Roles, "RoleId", "RoleName", roleassignuser.RoleId);

            return(View(userregistration));
        }
Beispiel #4
0
        // GET:
        public ActionResult Action(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserRegistration userregistration = db.User.Find(id);
            RoleAssignUser   roleassignuser   = new RoleAssignUser();

            if (userregistration == null)
            {
                return(HttpNotFound());
            }

            ViewBag.RoleId = new SelectList(db.Roles, "RoleId", "RoleName", roleassignuser.RoleId);

            return(View(userregistration));
        }
        public ActionResult Index(Login loginModel, string returnUrl)
        {
            if (loginModel.USERNAME == null || loginModel.PASSWARD == null || loginModel.USERNAME.Trim().Equals("") || loginModel.PASSWARD.Trim().Equals(""))
            {
                ModelState.AddModelError("", "Wrong Username or Password");
            }
            List <UserRegistration> appusers = db.User.ToList();

            foreach (var appuser in appusers)
            {
                if (appuser.UserName.Equals(loginModel.USERNAME) && encryptionDecryptionUtil.VerifyPassword(appuser.Password, loginModel.PASSWARD, appuser.Salt))
                {
                    FormsAuthentication.SetAuthCookie(loginModel.USERNAME, false);

                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                        !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        RoleAssignUser userpermission = db.RoleAssignUser.SingleOrDefault(u => u.UserId == appuser.UserId);
                        if (userpermission == null)
                        {
                            FormsAuthentication.SignOut();
                            return(RedirectToAction("AccessDenied", "Error", null));
                        }
                        appuser.LastLogin       = DateTime.Now;
                        db.Entry(appuser).State = EntityState.Modified;
                        db.SaveChanges();
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }
            if (ModelState.IsValid)
            {
                ModelState.AddModelError("", "Wrong Username or Password");
            }
            return(View(loginModel));
        }