示例#1
0
        public async Task <IActionResult> ConfirmConsumer(ConsumerActionModel actionModel)
        {
            if (actionModel.ConsumerID == 0)
            {
                return(NotFound());
            }

            var consumer = await _esbModelContext.Consumers.FindAsync(actionModel.ConsumerID);

            if (consumer == null)
            {
                return(NotFound());
            }

            switch (actionModel.Action)
            {
            case ConsumerActionModel.ActionEnum.Startup:
                consumer.ActiveStatus = 1;
                break;

            case ConsumerActionModel.ActionEnum.Disable:
                consumer.ActiveStatus = 0;
                break;

            case ConsumerActionModel.ActionEnum.Delete:
                _esbModelContext.Consumers.Remove(consumer);
                await _esbModelContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));

            case ConsumerActionModel.ActionEnum.ResetToken:
                consumer.Token = StringHelper.GetRandomString(20);
                break;

            default:
                throw new Exception("Wrong arguments");
            }
            _esbModelContext.Update(consumer);
            await _esbModelContext.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
示例#2
0
        //GET: Admin/ConfirmConsumer/5?act=3&name=NC
        public IActionResult ConfirmConsumer(int id, string name, int act)
        {
            if (id <= 0 || string.IsNullOrWhiteSpace(name))
            {
                return(NotFound());
            }

            ConsumerActionModel.ActionEnum action = (ConsumerActionModel.ActionEnum)act;
            string message;

            switch (action)
            {
            case ConsumerActionModel.ActionEnum.Startup:
                message = $"准备启用客户程序'{name}',确定吗?";
                break;

            case ConsumerActionModel.ActionEnum.Disable:
                message = $"准备禁用客户程序'{name}',确定吗?";
                break;

            case ConsumerActionModel.ActionEnum.Delete:
                message = $"准备删除客户程序'{name}',确定吗?";
                break;

            case ConsumerActionModel.ActionEnum.ResetToken:
                message = $"准备重置客户程序'{name}'的证书,确定吗?";
                break;

            default:
                throw new Exception("Wrong arguments");
            }

            ConsumerActionModel viewModel = new ConsumerActionModel()
            {
                Action            = action,
                ConsumerID        = id,
                ActionDescription = message
            };

            return(View(viewModel));
        }