Exemplo n.º 1
0
 public IActionResult Index(HomeViewModel model)
 {
     if(!ModelState.IsValid)
     {
         return Error();
     }
     if(!string.IsNullOrWhiteSpace(model.RecaptchaResponse))
     {
         var r = _recaptchaService.Verify(model.RecaptchaResponse, Request.HttpContext.Connection.RemoteIpAddress.ToString());
         if(!r.Success)
         {
             throw new UserFacingException($"You are not human.", $"Google response: {string.Join(", ", r.ErrorCodes)}");
         }
     }
     try
     {
         model.SuggestedSentences = _bookSearchService.Suggest(model.Keyword).Select(sm => new Tuple<bool, SentenceModel>(false, sm));
     }
     catch (Exception e)
     {
         model.ErrorMessage = e.Message;
     }
     HttpContext.Session.SetString(SessionKeyName, JsonConvert.SerializeObject(model));
     return RedirectToAction("Editor");
 }