コード例 #1
0
        public async Task <ActionResult> Follow([FromBody] TokkepediaFollow token)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user != null)
            {
                //Either create new or update
                if (!String.IsNullOrEmpty(token.FollowId))
                {
                    try
                    {
                        TokkepediaFollow follow = new TokkepediaFollow()
                        {
                            IsFollowing       = true,
                            UserId            = user.Id,
                            UserDisplayName   = user.DisplayName,
                            UserPhoto         = user.UserPhoto,
                            FollowId          = token.FollowId,
                            FollowDisplayName = token.FollowDisplayName,
                            FollowPhoto       = token.FollowPhoto,
                            FeedLabel         = "user"
                        };
                        await _userService.CreateFollowAsync(follow);
                    }
                    catch (Exception ex)
                    {
                        var m = ex.Message;
                        return(Json(null));
                    }
                }
                else
                {
                    //Update
                    try
                    {
                        TokkepediaFollow follow = JsonConvert.DeserializeObject <TokkepediaFollow>(token.UserFollowed);
                        if (follow.IsFollowing)
                        {
                            follow.IsFollowing = false;
                        }
                        else
                        {
                            follow.IsFollowing = true;
                        }

                        follow.FollowDisplayName = token.FollowDisplayName;
                        follow.FollowPhoto       = token.FollowPhoto;
                        ++follow.UpdateCount;

                        await _userService.UpdateFollowAsync(follow);
                    }
                    catch
                    {
                        return(Json(null));
                    }
                }
            }

            return(Json(""));
        }
コード例 #2
0
        public async Task <bool> UpdateFollowAsync(TokkepediaFollow tok)
        {
            var apiUrl = $"{_apiSettings.ApiPrefix}/follow/{tok.Id}{_apiSettings.CodePrefix}{_apiSettings.ApiKey}";
            HttpResponseMessage response = await _httpClient.PutAsJsonAsync(apiUrl, tok);

            return(response.IsSuccessStatusCode);
        }
コード例 #3
0
        public async Task <bool> CreateFollowAsync(TokkepediaFollow item)
        {
            var apiUrl = new Uri($"{_apiSettings.ApiPrefix}/follow/{item.Id}{_apiSettings.CodePrefix}{_apiSettings.ApiKey}", UriKind.Relative);
            HttpResponseMessage response = await _httpClient.PostAsJsonAsync(apiUrl, item);

            return(response.IsSuccessStatusCode);
        }
コード例 #4
0
        public async Task <bool> CreateFollowAsync(TokkepediaFollow item)
        {
            if (User == null)
            {
                throw new UnauthorizedAccessException();
            }
            client.DefaultRequestHeaders.Add("userid", User.Id);
            client.DefaultRequestHeaders.Add("token", User.IdToken);
            client.BaseAddress = new Uri($"{baseUrl}/follow/{item.Id}{codePrefix}{apiKey}");
            HttpResponseMessage response = await client.PostAsJsonAsync(client.BaseAddress, item);

            client = new HttpClient();
            return(response.IsSuccessStatusCode);
        }