public ActionResult UserPermissions(int?id, string[] perm)
        {
            // get properties of tenant
            caTenant tenant = caCurrent.CurrentTenant();

            // get properties of user
            caUser user = caCurrent.CurrentUser();

            List <AuthPermission> Permissions = new List <AuthPermission>();
            HashSet <int>         wareh       = new HashSet <int>();

            if (perm != null)
            {
                foreach (var chk in perm)
                {
                    String[] exploded = chk.Split('-');
                    wareh.Add(Convert.ToInt32(exploded[0]));

                    AuthPermission Permission = new AuthPermission();

                    Permission.WarehouseId = Convert.ToInt32(exploded[0]);
                    Permission.ActivityId  = Convert.ToInt32(exploded[1]);
                    Permission.UserId      = Convert.ToInt32(id);
                    Permission.TenantId    = tenant.TenantId;
                    Permission.DateCreated = DateTime.UtcNow;
                    Permission.DateUpdated = DateTime.UtcNow;
                    Permission.CreatedBy   = user.UserId;
                    Permission.UpdatedBy   = user.UserId;
                    Permission.IsActive    = true;
                    Permission.IsDeleted   = false;

                    // add each permission in list
                    Permissions.Add(Permission);
                }

                // assign default permissions to the users for each warehouse
                foreach (var ware in wareh)
                {
                    // get list of activities which are excluded permissions
                    // these activites are to be allowed by default with each user
                    List <AuthActivity> ExActivities = new List <AuthActivity>();
                    ExActivities = _activityServices.GetExcludedActivities();

                    foreach (var Activity in ExActivities)
                    {
                        AuthPermission Permission = new AuthPermission();

                        Permission.WarehouseId = Convert.ToInt32(ware);
                        Permission.ActivityId  = Activity.ActivityId;
                        Permission.UserId      = Convert.ToInt32(id);
                        Permission.TenantId    = tenant.TenantId;
                        Permission.DateCreated = DateTime.UtcNow;
                        Permission.DateUpdated = DateTime.UtcNow;
                        Permission.CreatedBy   = user.UserId;
                        Permission.UpdatedBy   = user.UserId;
                        Permission.IsActive    = true;
                        Permission.IsDeleted   = false;

                        // add each permission in list
                        Permissions.Add(Permission);
                    }
                }
            }

            // remove previous permissions against user if any in database context
            List <AuthPermission> OldPermissions = new List <AuthPermission>();

            OldPermissions = _activityServices.GetPermissionsByUserId((int)id);

            //remove old permissions
            _activityServices.RemoveAuthPermissions(OldPermissions);

            // add new premissions in database context
            _activityServices.AddAuthPermissions(Permissions);

            // update user dateUpdated and Updated by
            AuthUser NewUser = _userService.GetAuthUserById(Convert.ToInt32(id));

            NewUser.DateUpdated = DateTime.UtcNow;
            NewUser.UpdatedBy   = user.UserId;

            _userService.UpdateAuthUserForPermissions(NewUser, user.UserId, tenant.TenantId);

            // return back to the origional refferal page
            return(RedirectToAction("Index"));
        }