코드 3-18 함수에 서술적인 기능만 유지
[HttpPost]
public IActionResult Submit(ShipmentAddress form) {
if (!validate(form)) { → 유효성 검증
return shippingFormError();
}
bool success = service.SaveShippingInfo(form); → 저장
if (!success) { → 오류 처리
reportSaveError();
return shippingFormError();
}
return RedirectToAction("Index", "BillingForm"); → 성공적인 응답
}
private bool validate(ShipmentAddress form) {
if (!ModelState.IsValid) {
return false;
}
var validationResult = service.ValidateShippingForm(form);
return validationResult == ShippingFormValidationResult.Valid;
}
private IActionResult shippingFormError() {
Response.Cookies.Append("shipping_error", "1");
return RedirectToAction("Index", "ShippingForm", form);
}
private void reportSaveError() {
ModelState.AddModelError("", "Problem occurred while " +
"saving your information, please try again");
}