Esempio n. 1
0
        public async Task <ActionResult> OnpostAsync()
        {
            AddedCommand addedCommand = await _addedCommandsRepository.GetCommandAsync(CommandToAdd.Name);

            if (addedCommand != null)
            {
                ModelState.AddModelError("Command Existing", "Command already exists");
                return(Page());
            }
            if (CommandToAdd.Response == null)
            {
                ModelState.AddModelError("Add a Response", "Please add a response");
                return(Page());
            }
            try
            {
                await _addedCommandsRepository.AddCommandAsync(CommandToAdd);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Could not add command", "Could not add command, Something went wrong Exception:" + ex.Message);
                return(Page());
            }

            return(RedirectToPage("Commands"));
        }
Esempio n. 2
0
        public ICommand FindCommand(string theCommand)
        {
            //Note: Check the added command DB first then check the command registry
            ICommand     Result   = null;
            AddedCommand addedCmd = _addedCommands.FirstOrDefault(c => c.Name == theCommand);

            if (addedCmd != null)
            {
                return(addedCmd);
            }
            var testCommand = _CommandRegistry.TryGetValue(theCommand, out Result);

            //return the found command or null
            return(Result);
        }
 public Task EditCommand(string name, AddedCommand command)
 {
     return(_commandsColleciton.ReplaceOneAsync(cmd => cmd.Name == name, command));
 }
 public Task AddCommandAsync(AddedCommand command)
 {
     return(_commandsColleciton.InsertOneAsync(command));
 }