public async Task <IActionResult> TerminateProcess(int processId, bool terminateNoStatusing = false)
        {
            try
            {
                Person user = _contextPersonStore.Get(HttpContext.RequestAborted, HttpContext.Items);

                if (user == null)
                {
                    throw new Exception("Error fetching User Information.");
                }

                var terminateProcessResponse = await _processFacade.TerminateProcessAsync(processId, terminateNoStatusing, user, HttpContext.RequestAborted, HttpContext.Items);

                return(Ok(terminateProcessResponse));
            }
            catch (InvalidOperationException opEx)
            {
                //https://stackoverflow.com/questions/44597099/asp-net-core-giving-me-code-500-on-forbid
                //return StatusCode(403, opEx.Message);
                return(Conflict(opEx));
            }
            catch (UnauthorizedAccessException)
            {
                return(Unauthorized());
            }
            catch (ArgumentException argumentException)
            {
                return(BadRequest(argumentException.Message));
            }
            catch (Exception exception)
            {
                _logger.LogError($"{HttpContext.TraceIdentifier} Unable to terminate the process. Reason: {exception}");
                throw exception;
            }
        }
Beispiel #2
0
        public async Task <IActionResult> ApplyActorAction([FromBody] ActorAction actorAction)
        {
            //  We need to get the authorized user and pass that thorugh so we can use that in the security model.
            try
            {
                Person user = _contextPersonStore.Get(HttpContext.RequestAborted, HttpContext.Items);

                if (user == null)
                {
                    throw new Exception("Error fetching User Information.");
                }

                var result = await _activityFacade.ApplyActorActionAsync(actorAction, user, HttpContext.RequestAborted, HttpContext.Items);

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

                return(Ok(result));
            }
            catch (AggregateException exception)
            {
                _logger.LogInformation($"{HttpContext.TraceIdentifier} AggregateException: {exception}");
                return(BadRequest(exception.Message));
            }
            catch (InvalidOperationException exception)
            {
                _logger.LogInformation($"{HttpContext.TraceIdentifier} InvalidOperationException: {exception}");
                return(BadRequest(exception.Message));
            }
            catch (ArgumentException exception)
            {
                _logger.LogInformation($"{HttpContext.TraceIdentifier} ArgumentException: {exception}");
                return(BadRequest(exception.Message));
            }
            catch (Exception exception)
            {
                _logger.LogError($"{HttpContext.TraceIdentifier} Unable to Apply Actor Action. Reason: {exception}");
                throw;
            }
        }
        public IActionResult GetCurrentUserAsync()
        {
            // TODO: Use global exception filters.
            try
            {
                Person user = _contextPersonStore.Get(HttpContext.RequestAborted, HttpContext.Items);

                if (user == null)
                {
                    throw new Exception("Error fetching User Information.");
                }

                return(Ok(user));
            }
            catch (Exception exception)
            {
                _logger.LogError($"{HttpContext.TraceIdentifier} Unable to retrieve person. Reason: {exception}");
                throw;
            }
        }