public async Task <IActionResult> IntegerFactorization(Guid id) { if (id == Guid.Empty) { return(NotFound()); } try { var httpClient = await _quantumAlgorithmsHttpClient.GetClient(User.Identity.IsAuthenticated); var response = await httpClient.GetAsync($"Api/IntegerFactorization/{id}").ConfigureAwait(false); if (!response.IsSuccessStatusCode) { return(NotFound()); } var responseString = await response.Content.ReadAsStringAsync().ConfigureAwait(false); if (IsNullOrEmpty(responseString)) { throw new Exception("This should not happen."); } var model = JsonConvert.DeserializeObject <IntegerFactorizationViewModel>(responseString); if (model == null) { throw new Exception("This should not happen."); } model.Url = _configuration.GetSection("Applications")["API"] + "Api/IntegerFactorization/" + id; return(View(model)); } catch (Exception) { return(RedirectToAction("Logout", "Authentication")); } }
public async Task <IActionResult> Solve(SolveViewModel model) { if (model.Problem == Problem.IntegerFactorization) { if (ModelState[nameof(SolveViewModel.Number)].Errors.Any()) { model.IsValid = false; ModelState.Clear(); return(View(model)); } try { var httpClient = await _quantumAlgorithmsHttpClient.GetClient(User.Identity.IsAuthenticated); var request = new IntegerFactorizationCreateDto { Number = model.Number }; var response = await httpClient.PostAsync("Api/IntegerFactorization", new StringContent( JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json")); if (!response.IsSuccessStatusCode) { model.ApiRequestFailed = true; ModelState.Clear(); return(View(model)); } var responseString = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var executionId = JsonConvert.DeserializeObject <IntegerFactorizationGetDto>(responseString).Id; return(RedirectToAction("IntegerFactorization", "Solve", new { Id = executionId })); } catch (Exception) { return(RedirectToAction("Logout", "Authentication")); } } if (model.Problem == Problem.DiscreteLogarithm) { if (ModelState[nameof(SolveViewModel.Result)].Errors.Any() || ModelState[nameof(SolveViewModel.Generator)].Errors.Any() || ModelState[nameof(SolveViewModel.Modulus)].Errors.Any()) { model.IsValid = false; ModelState.Clear(); return(View(model)); } try { var httpClient = await _quantumAlgorithmsHttpClient.GetClient(User.Identity.IsAuthenticated); var request = new DiscreteLogarithmCreateDto { Result = model.Result, Generator = model.Generator, Modulus = model.Modulus }; var response = await httpClient.PostAsync("Api/DiscreteLogarithm", new StringContent( JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json")); if (!response.IsSuccessStatusCode) { model.ApiRequestFailed = true; ModelState.Clear(); return(View(model)); } var responseString = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var executionId = JsonConvert.DeserializeObject <IntegerFactorizationGetDto>(responseString).Id; return(RedirectToAction("DiscreteLogarithm", "Solve", new { Id = executionId })); } catch (Exception) { return(RedirectToAction("Logout", "Authentication")); } } return(View()); }