private void saveRoleActions(int clientID, int roleID)
        {
            RoleAction roleAction = null;

            using (ActionManager repository = new ActionManager()) {
                repository.DeleteAll(clientID, roleID);

                foreach (ListItem item in cblRoleActions.Items) {
                    if (item.Selected) {
                        roleAction = new RoleAction();
                        roleAction.ClientID = clientID;
                        roleAction.RoleID = roleID;
                        roleAction.ActionID = Convert.ToInt32(item.Value);

                        repository.Save(roleAction);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void DoAuthenticate(CRM.Data.Entities.SecUser user)
        {
            string url = null;
            string userData = null;
            List<int> roleActions = null;

            Session["UserId"] = user.UserId;
            Session["UserName"] = user.UserName;
            Session["RoleId"] = user.SecRole.RoleId.ToString();

            // 201307-29
            Session["ClientId"] = user.ClientID;
            if (user.Client.Count > 0)
            {
                Session["ClientShowTask"] = user.Client == null ? true : (user.Client.FirstOrDefault().isShowTasks ?? true);
            }
            else
            {
                Session["ClientShowTask"] = true;
            }

            userData = string.Format("{0}|{1}|{2} {3}|{4}", user.SecRole.RoleName, user.SecRole.RoleId, user.FirstName, user.LastName, user.Email);

            var ticket = new FormsAuthenticationTicket
                (
                   1,
                   user.UserId.ToString(),
                   DateTime.Now,
                   DateTime.Now.AddMinutes(120),
                   true,
                   userData,	//(user.SecRole.RoleName + "|" + user.SecRole.RoleId.ToString()),
                   FormsAuthentication.FormsCookiePath
                );

            string encryptedTicket = FormsAuthentication.Encrypt(ticket);
            Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket));
            Session["rolePermission"] = resRolePermission = SecRoleModuleManager.getRolePermission(user.SecRole.RoleId).ToList();

            // get role actions
            if (user.RoleId != (int)UserRole.Administrator)
            {
                using (ActionManager repository = new ActionManager())
                {
                    roleActions = repository.GetActions((int)user.ClientID, (int)user.RoleId);
                    Session["roleActions"] = roleActions;
                }
            }

            //if (user.SecRole.RoleId == (int)UserRole.Adjuster)
            //	url = "~/Protected/Intake/form.aspx";
            //else
            if (Request.QueryString["url"] != null)
            {
                url = Request.QueryString["url"].ToString();
            }
            else
            {
                url = FormsAuthentication.DefaultUrl;
                Session["Count"] = null;

                formatException();
                setRulexception();

                setGlobalSession();

                Thread thread = new Thread(delegate()
                {
                    workerObject.DoWork();
                });
                //ThreadPool.QueueUserWorkItem(new WaitCallback(workerObject.DoWork), leadView, testse);

                // workerThread = new Thread(workerObject.DoWork);

                thread.Start();
            }

            Response.Redirect(url);
        }
        private void bindRoleActions(int roleID)
        {
            List<Data.Entities.Action> actions = null;
            List<RoleAction> roleActions = null;

            clientID = SessionHelper.getClientId();

            // bind actions
            using (ActionManager repository = new ActionManager()) {
                actions = repository.GetActions();

                roleActions = repository.GetRoleActions(clientID, roleID);
            }

            // show all actions
            CollectionManager.Fillchk(cblRoleActions, "ActionID", "ActionName", actions);

            if (roleActions != null && roleActions.Count > 0) {

                foreach (RoleAction roleAction in roleActions) {
                    ListItem item = cblRoleActions.Items.FindByValue(roleAction.ActionID.ToString());
                    if (item != null)
                        item.Selected = true;
                }
            }
        }