Ejemplo n.º 1
0
        public static async Task <int> CreatePropertyKeyAsync(HttpClient httpClient, ILogger logger, PropertyKey propertyKey)
        {
            var fields = propertyKey.ToCreate();

            logger.LogInformation($"Creating PropertyKey: {JsonConvert.SerializeObject(fields, Formatting.Indented)}");
            var content = JsonConvert.SerializeObject(fields);

            var response = await httpClient.PostAsync("propertykeys", new StringContent(content, Encoding.UTF8, "application/json"));

            if (await IsSuccessCall(response, logger, content))
            {
                var responseContent = await response.Content.ReadAsStringAsync();

                if (!int.TryParse(responseContent, out var createdId))
                {
                    logger.LogError($"Returned value from POST did not parse into a int: {responseContent}");
                }

                await FeedbackHelper.Channel.SendMessageAsync($"PropertyKey '{propertyKey.Label}' successfully created with the ID {createdId}", MessageType.Info);

                return(createdId);
            }

            return(0);
        }