public override void OnActionExecuting(HttpActionContext context) { CatalogRepository catalogRepository = new CatalogRepository(new MyRoomDbContext()); bool hasChildrens = catalogRepository.HasCatalogChildrens((int)context.ActionArguments["key"]); if (!hasChildrens) throw new HttpResponseException(context.Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "Please, delete the modules childrens")); }