코드 3-15 goto 대신 로컬 함수 사용하기
[HttpPost]
public IActionResult Submit4(ShipmentAddress form) {
IActionResult error() { → 로컬 함수
Response.Cookies.Append("shipping_error", "1");
return RedirectToAction("Index", "ShippingForm", form);
}
if (!ModelState.IsValid) {
return error(); → 공통적인 오류 반환
}
var validationResult = service.ValidateShippingForm(form);
if (validationResult != ShippingFormValidationResult.Valid) {
return error(); } bool success = service.SaveShippingInfo(form); if (!success) { ModelState.AddModelError("", "Problem occurred while " + "saving your information, please try again"); return error();
→ 중복된 종료 지점
}
return RedirectToAction("Index", "BillingForm");
}