title: Duplication of code when on WEB Api validation
body: <p>I have some check for each method in WEB API on token from the header to match the record in database. I need to use this validation for each WEB API method. In that case for each method I need copy/paste the same piece of code. How to redesign the methods in order to avoid code duplication?</p>
  
  <p>Below is an example of two methods that at the begging has the same piece of code.</p>
  
  <pre><code>[HttpPost]
  [Route("QRCConnect")]
  public async Task&lt;IHttpActionResult&gt; QRCConnect([Required]string userId, [Required]int eventId, [Required]int supplierId)
  {
      try
      {
          if (!ModelState.IsValid)
          {
              return BadRequest(ModelState);
          }
          var token = GetTokenFromHeader(Request.Headers);
          var api = await _webApiService.GetApiByToken(token).ConfigureAwait(false);
          if (api == null)
          {
              return Ok(GenerateErrorsModel(404, TokenNotFoundMessage));
          }
  
          if (api.IsExpired)
          {
              return Ok(GenerateErrorsModel(400, TokenExpiredMessage));
          }
          ...
  
  [HttpGet]
  [Route("GetBuyerInfo")]
  public async Task&lt;IHttpActionResult&gt; GetBuyerInfo(string userId)
  {
      try
      {
          var token = GetTokenFromHeader(Request.Headers);
          var api = await _webApiService.GetApiByToken(token).ConfigureAwait(false);
          if (api == null)
          {
              return Ok(GenerateErrorsModel(404, TokenNotFoundMessage));
          }
  
          if (api.IsExpired)
          {
              return Ok(GenerateErrorsModel(400, TokenExpiredMessage));
          }
          ...
  </code></pre>