예제 #1
0
        public static UserControlPermission FillUserControlPermission(IDataReader arg)
        {
            string output = "";
            output += arg.FieldCount + " ";
            

            UserControlPermission ucp = new UserControlPermission();
            ucp.Control = arg.GetString(0);
            ucp.AccessValue = arg.GetByte(1) == (byte)1 ? true : false;

            return ucp;
        }
예제 #2
0
        private static void comparePermissions(int currentID, Dictionary<string, HashSet<string>> oldPermissions, Dictionary<string, HashSet<string>> newPermissions, List<Task> tasklist, bool AccessValue)
        {
            if (!oldPermissions.Equals(newPermissions))
            {
                UserControlPermission ucp = new UserControlPermission();
                UserPermission up = new UserPermission();
                HashSet<string> deletedControls = new HashSet<string>();
                //added permissions
                foreach(var delPerms in oldPermissions)
                {
                    if (!newPermissions.Keys.Contains(delPerms.Key))
                    {
                        deletedControls.Add(delPerms.Key);
                        tasklist.Add(Task.Factory.StartNew(() => DeleteControlAccess(currentID, delPerms.Key)));
                    }
                }
                foreach (var permission in newPermissions)
                {
                    if (!deletedControls.Contains(permission.Key) && oldPermissions.ContainsKey(permission.Key))
                    {
                        //delete all permissions from control
                        if (!(permission.Value.Count > 0))
                            tasklist.Add(Task.Factory.StartNew(() => DeleteControlPermissions(currentID, permission.Key)));

                        HashSet<string> DeletePermissions = new HashSet<string>();
                        HashSet<string> AddPermissions = oldPermissions[permission.Key];

                        if (AddPermissions != null)
                        {
                            DeletePermissions.AddRange(oldPermissions[permission.Key]);
                            foreach (string s in permission.Value)
                            {
                                if (!DeletePermissions.Remove(s))
                                {
                                    up.Control = permission.Key;
                                    up.Permission = s;
                                    up.AccessValue = AccessValue;
                                    //add permission
                                    tasklist.Add(Task.Factory.StartNew(() => SetPermissionByUserID(currentID, up)));
                                }
                            }
                        }
                        else { throw new Exception("addpermission = null"); }
                        if (DeletePermissions.Count > 0)
                        {
                            foreach (string s in DeletePermissions)
                            {
                                up.Control = permission.Key;
                                up.Permission = s;
                                tasklist.Add(Task.Factory.StartNew(() => DeleteControlPermissionAccess(currentID, up)));
                            }
                        }
                    }
                    else
                    {
                        ucp.Control = permission.Key;
                        ucp.AccessValue = true;
                        tasklist.Add(Task.Factory.StartNew(() => SetPermissionByUserID(currentID, ucp)));
                        
                        foreach (string s in permission.Value)
                        {
                            up.AccessValue = AccessValue;
                            up.Control = permission.Key;
                            up.Permission = s;
                            tasklist.Add(Task.Factory.StartNew(() => SetPermissionByUserID(currentID, ucp)));
                        }
                    }

                }
            }
        }
예제 #3
0
 public static void SetPermissionByUserID(int userID, UserControlPermission ucp)
 {
     byte Value = (byte)(ucp.AccessValue ? 1 : 0);
     DAL.DAL.ExecuteNonQuery("I_User_ControlPermission_ByControlName",
         DAL.DAL.Parameter("UserID", userID),
         DAL.DAL.Parameter("ControlName", ucp.Control),
         DAL.DAL.Parameter("Value", Value)
     );
 }
예제 #4
0
        public static void AddPermissionsFromList(int userid, Dictionary<string, HashSet<string>> perm, bool accessValue)
        {
            foreach (var z in perm)
            {
                if (z.Value == null || (z.Value != null && !(z.Value.Count > 0)))
                {
                    UserControlPermission ucp = new UserControlPermission();
                    ucp.AccessValue = accessValue;
                    ucp.Control = z.Key;
                    SetPermissionByUserID(userid, ucp);
                }

                if (z.Value != null && z.Value.Count > 0)
                {
                    foreach (string action in z.Value)
                    {
                        UserPermission up = new UserPermission();
                        up.AccessValue = accessValue;
                        up.Control = z.Key;
                        up.Permission = action;
                        SetPermissionByUserID(userid, up);
                    }
                }
            }
        }