Exemple #1
0
        public async Task <ActionResult> DeleteAgent(int id)
        {
            try
            {
                var agentToDelete = await _repository.GetAgentById(id);

                if (agentToDelete == null)
                {
                    return(NotFound($"Agent with Id = {id} not found"));
                }

                return(Ok(await _repository.DeleteExistingAgent(id)));
            }
            catch (System.Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  "There were error in deleting the data from the database!"));
            }
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(RedirectToPage("/AgentNotFound"));
            }

            Agent = await _repository.GetAgentById(id.Value);

            if (Agent == null)
            {
                return(RedirectToPage("/AgentNotFound"));
            }
            Agent agent = await _repository.DeleteExistingAgent(Agent.AgentId);

            if (agent == null)
            {
                return(RedirectToPage("/DatabaseError"));
            }
            return(RedirectToPage("Index"));
        }