Example #1
0
        public async Task <IActionResult> DeleteTool(Guid toolID)
        {
            if (!await _toolRepository.ToolExistAsync(toolID))
            {
                return(NotFound());
            }
            var tool = await _toolRepository.GetToolAsync(toolID);

            _toolRepository.DeleteTool(tool);
            await _toolRepository.SaveAsync();

            return(Ok());
        }
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            var trackChanges = context.HttpContext.Request.Method.Equals("PUT") ? true : false;
            var id           = (Guid)context.ActionArguments["id"];
            var tool         = await _repository.GetToolAsync(id, trackChanges);

            if (tool == null)
            {
                _logger.LogInfo($"Tool with id: {id} doesn't exist in the database.");
                context.Result = new NotFoundResult();
            }
            else
            {
                context.HttpContext.Items.Add("tool", tool); await next();
            }
        }