Example #1
0
        public async Task <IActionResult> FollowProfile([FromRoute] string username)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                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.AddFavoriteProfile(username, token);

                return(result
                    ? Ok()
                    : (IActionResult)Unauthorized());
            }
            catch (Exception ex)
            {
                var genericErrorModel = new GenericErrorModel(new GenericErrorModelErrors(new[] { ex.ToString() }));
                return(BadRequest(genericErrorModel));
            }
        }