public async Task <ActionResult> MakeReservation( [FromBody] ReservationViewModel model, [FromHeader] string captcha, [FromHeader] string captchaType, [FromServices] CaptchaVerifyHelper captchaVerifyHelper, [FromServices] IStringLocalizer <HomeController> localizer) { var result = new ResultModel <bool>(); var isCodeValid = await captchaVerifyHelper.ValidateVerifyCodeAsync(captchaType, captcha); if (!isCodeValid) { result.Status = ResultStatus.RequestError; result.ErrorMsg = localizer["InvalidCaptchaInfo"]; return(Json(result)); } try { if (ModelState.IsValid) { if (!HttpContext.RequestServices.GetService <ReservationHelper>() .MakeReservation(model, out var msg)) { result.ErrorMsg = msg; return(Json(result)); } result.Result = true; result.Status = ResultStatus.Success; } } catch (Exception ex) { Logger.Error(ex); result.Status = ResultStatus.ProcessFail; result.ErrorMsg = ex.Message; } return(Json(result)); }
public async Task <IActionResult> MakeReservation( [FromBody] ReservationViewModel model, [FromHeader] string captcha, [FromHeader] string captchaType, [FromServices] CaptchaVerifyHelper captchaVerifyHelper ) { var result = new ResultModel <bool> { Status = ResultStatus.RequestError }; var isCodeValid = await captchaVerifyHelper .ValidateVerifyCodeAsync(captchaType, captcha); if (!isCodeValid) { result.ErrorMsg = "验证码有误, 请重新验证"; return(Ok(result)); } try { if (!HttpContext.RequestServices.GetService <ReservationHelper>() .MakeReservation(model, out var msg)) { result.ErrorMsg = msg; } else { result.Result = true; result.Status = ResultStatus.Success; } } catch (Exception ex) { Logger.Error(ex, $"Make reservation exception: {ex.Message}"); result.Status = ResultStatus.ProcessFail; result.ErrorMsg = ex.Message; } return(Ok(result)); }