示例#1
0
        private async Task <ActionResult <EntitiesResponse <Agent> > > Activate([FromBody] List <int> ids, bool returnEntities, string expand, bool isActive)
        {
            // Parse parameters
            var expandExp = ExpandExpression.Parse(expand);
            var idsArray  = ids.ToArray();

            // Check user permissions
            await CheckActionPermissions("IsActive", idsArray);

            // Execute and return
            using var trx = ControllerUtilities.CreateTransaction();
            await _repo.Agents__Activate(ids, isActive);

            if (returnEntities)
            {
                var response = await GetByIdListAsync(idsArray, expandExp);

                trx.Complete();
                return(Ok(response));
            }
            else
            {
                trx.Complete();
                return(Ok());
            }
        }
示例#2
0
        private async Task <(List <Agent>, Extras)> SetIsActive(List <int> ids, ActionArguments args, bool isActive)
        {
            // Check user permissions
            var action       = "IsActive";
            var actionFilter = await UserPermissionsFilter(action, cancellation : default);

            ids = await CheckActionPermissionsBefore(actionFilter, ids);

            // Execute and return
            using var trx = ControllerUtilities.CreateTransaction();
            await _repo.Agents__Activate(ids, isActive);

            List <Agent> data   = null;
            Extras       extras = null;

            if (args.ReturnEntities ?? false)
            {
                (data, extras) = await GetByIds(ids, args, action, cancellation : default);
            }

            // Check user permissions again
            await CheckActionPermissionsAfter(actionFilter, ids, data);

            trx.Complete();
            return(data, extras);
        }