Esempio n. 1
0
        public async Task <int> RegisterTest(RegisterTestRequest requestData)
        {
            if (!_enabled)
            {
                return(-1);
            }

            try
            {
                var httpContent = new StringContent(JsonConvert.SerializeObject(requestData), Encoding.UTF8, "application/json");
                var response    = await _httpClient.PostAsync("test/register", httpContent);

                var responseContent = await response.Content.ReadAsStringAsync();

                if (response.IsSuccessStatusCode)
                {
                    return(JsonConvert.DeserializeObject <TestDataResponse>(responseContent).Id);
                }
                else
                {
                    throw new HttpRequestException();
                }
            }
            catch
            {
                Console.WriteLine($"[{DateTime.Now}] Can't register new test");
            }

            return(-1);
        }
Esempio n. 2
0
        public async Task <IActionResult> RegisterTest([FromBody] RegisterTestRequest requestData)
        {
            var response = new TestDataResponse
            {
                Id = await _testService.GenerateNewTest(requestData.Type)
            };

            return(new JsonResult(response));
        }