コード例 #1
0
        //Set User permission over spesific store
        public Tuple <bool, string> setPermmisions(int store_id, int[] permission_set, bool saveChanges = false)
        {
            Logger.logEvent(this, System.Reflection.MethodBase.GetCurrentMethod());
            if (store_id < 1)
            {
                return(new Tuple <bool, string>(false, "No such Store id\n"));
            }
            if (permission_set == null)
            {
                return(new Tuple <bool, string>(false, "Null Argument\n"));
            }
            if (!isStorManager(store_id) && !isStoreOwner(store_id))
            {
                return(new Tuple <bool, string>(false, "The user is not Store Manager or owner\n"));
            }

            if (Store_options.ContainsKey(store_id))
            {
                int[] oldp = Store_options[store_id];

                List <UserStorePermissions> perms = DbManager.Instance.GetUserStorePermissionSet(store_id, this.Name);
                Store_options.Remove(store_id);
                try
                {
                    DbManager.Instance.DeletePermission(perms);
                }
                catch (Exception ex)
                {
                    Logger.logError("Delete Permissions error : " + ex.Message, this, System.Reflection.MethodBase.GetCurrentMethod());
                    return(new Tuple <bool, string>(false, "Delete Permissions DB Failed cannot proceed"));
                }
            }
            Store_options.Add(store_id, permission_set);
            List <UserStorePermissions> permsN = AdapterUser.CreateNewPermissionSet(Name, store_id, permission_set);

            try
            {
                DbManager.Instance.InsertUserStorePermissionSet(permsN, saveChanges);
            }
            catch (Exception ex)
            {
                Logger.logError("Insert Permissions error : " + ex.Message, this, System.Reflection.MethodBase.GetCurrentMethod());
                return(new Tuple <bool, string>(false, "Insert Permissions DB Failed cannot proceed"));
            }
            return(new Tuple <bool, string>(true, ""));
        }