Exemplo n.º 1
0
        public async Task <IActionResult> React([FromBody] TokkepediaReaction reaction)
        {
            bool result = false;

            if (ModelState.IsValid)
            {
                reaction.UserId    = User.GetUserId();
                reaction.DetailNum = 0;

                if (reaction.Kind == "comment")
                {
                    reaction.Text = reaction.Text.TrimEnd('\r', '\n');
                    var tokmojis = PurchasesTool.GetProducts().Where(x => x.ProductType == ProductType.Tokmoji).ToList();
                    foreach (var item in tokmojis)
                    {
                        reaction.Text = reaction.Text.Replace(":" + item.Image + ":", ":" + item.Id + ":");
                    }
                }

                if (!string.IsNullOrEmpty(reaction.ItemId) && !reaction.IsActive)
                {
                    result = await _reactionService.AddReaction(reaction);
                }
                else
                {
                    result = await _reactionService.DeleteReaction(reaction.ItemId);
                }
            }
            return(Json(result));
        }
Exemplo n.º 2
0
        public async Task <bool> UpdateReaction(string id, TokkepediaReaction item)
        {
            var apiUrl = $"{_apiSettings.ApiPrefix}/reaction/{id}{_apiSettings.CodePrefix}{_apiSettings.ApiKey}";
            HttpResponseMessage response = await _httpClient.PutAsJsonAsync(apiUrl, item);

            return(response.IsSuccessStatusCode);
        }
Exemplo n.º 3
0
        public async Task <bool> AddReaction(TokkepediaReaction item)
        {
            _httpClient.DefaultRequestHeaders.Remove("streamtoken"); // Remove Default
            _httpClient.DefaultRequestHeaders.Add("itemid", item.ItemId);

            var apiUrl = $"{_apiSettings.ApiPrefix}/reaction{_apiSettings.CodePrefix}{_apiSettings.ApiKey}";
            HttpResponseMessage response = await _httpClient.PostAsJsonAsync(apiUrl, item);

            return(response.IsSuccessStatusCode);
        }
Exemplo n.º 4
0
        public async Task <bool> UpdateReaction(string id, TokkepediaReaction item)
        {
            if (User == null)
            {
                throw new UnauthorizedAccessException();
            }
            client.DefaultRequestHeaders.Add("userid", User.Id);
            client.DefaultRequestHeaders.Add("token", User.IdToken);

            client.BaseAddress = new Uri($"{baseUrl}/reaction/{id}{codePrefix}{apiKey}");
            HttpResponseMessage response = await client.PutAsJsonAsync(client.BaseAddress, item);

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