現在、プロジェクトのリファクタリングを行っていますが、よくわからないことの 1 つは、ビジネス検証エラーの処理方法です。
現在、xVal ライブラリの RulesException クラスを使用していますが、このライブラリは開発されていないので、それに応じてコードを更新する必要があると思います。ドメイン モデルでのメソッドの例を次に示します。
public virtual void AddComment(ProfileComment comment)
{
// ensure account is active before sending a message
if (comment.FromAccount.AccountStatus != Enums.Common.AccountStatus.Active) throw new RulesException("", "Your account is not active");
// throw exception if user has blocked this user
if (HasUserBeenBlocked(comment.FromAccount)) throw new RulesException("", "User has blocked this action being performed.");
TotalComments++;
Comments.Add(comment);
}
次に、次のようにコントローラーレベルでこの例外をキャッチします。
// process adding new comment
try
{
accountTasks.PostProfileComment(user, account, profileComment);
}
catch (RulesException ex)
{
ex.AddModelStateErrors(ModelState);
}
if (!ModelState.IsValid)
{
return Json(ModelState.Errors());
}
代替として何をお勧めしますか、それとも私が持っているものに固執することをお勧めしますか?