Exemplo n.º 1
0
        public async Task <IActionResult> DeleteHeaAgents([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            await _repository.Delete(id);

            return(Ok("Deleted"));
        }
Exemplo n.º 2
0
        public AgentsViewModel(IAgentRepository agentRepo, IViewModelFactory vmFactory,
                               IUserInteraction ui)
        {
            _agentRepo = agentRepo;
            _vmFactory = vmFactory;

            var agentVms = agentRepo.GetAll().Select(x => CreateAgentViewModel(x));

            Agents.ReplaceItems(agentVms);

            AddAgentCommand = new ActionCommand(o =>
            {
                Agents.Add(CreateAgentViewModel(null));
                IsDirty = true;
            });

            DeleteAgentCommand = new ActionCommand(_ =>
            {
                var selectedAgent = Agents.FirstOrDefault(x => x.IsSelected);
                if (selectedAgent == null)
                {
                    ui.ShowWarning("No agent selected.");
                    return;
                }
                if (!ui.AskForConfirmation($"Are you sure you want to delete the selected '{selectedAgent.Id}' agent?", "Delete agent"))
                {
                    return;
                }

                Agents.Remove(selectedAgent);
                if (!string.IsNullOrEmpty(selectedAgent.Id))
                {
                    agentRepo.Delete(selectedAgent.Id);
                }
            });

            CommitAgentsCommand = new ActionCommand(_ => CommitAgents(),
                                                    _ => IsDirty && !HasErrors);

            ResetChangesCommand = new ActionCommand(_ => {
                foreach (var agent in Agents)
                {
                    agent.ResetForm();
                }
                IsDirty = false;
            }, _ => IsDirty);

            PropertiesAreInitialized = true;
        }
        public IActionResult DeleteAlias(int id)
        {
            if (!_agentRepo.Get(id).Success)
            {
                return(NotFound($"Alias {id} not found"));
            }

            var result = _agentRepo.Delete(id);

            if (result.Success)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest(result.Messages));
            }
        }
Exemplo n.º 4
0
        public IActionResult Delete(int id)
        {
            var getAgentResult = agentRepository.Get(id);

            if (!getAgentResult.Success)
            {
                return(NotFound($"Agent {id} not found"));
            }

            var response = agentRepository.Delete(id);

            if (response.Success)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest(response.Message));
            }
        }
Exemplo n.º 5
0
 public void Delete(int id)
 {
     _agentRepository.Delete(id);
 }