public async Task <IActionResult> AddFavoriteArticle([FromRoute] string slug) { if (string.IsNullOrWhiteSpace(slug)) { return(NotFound()); } try { var tokenHeader = Request.Headers["Authorization"]; var token = tokenHeader.Count > 0 ? tokenHeader.First().Split(' ')[1] : null; User currentUser = null; if (!string.IsNullOrWhiteSpace(token)) { currentUser = UserService.GetCurrentUser(token); } var result = await FavoritesService.AddFavorite(slug, token); return(result ? Ok() : (IActionResult)Unauthorized()); } catch (Exception ex) { var genericErrorModel = new GenericErrorModel(new GenericErrorModelErrors(new[] { ex.ToString() })); return(BadRequest(genericErrorModel)); } }