- .
, , , , .., .
, , -/ , "", ( ), .
"Validate", . , , .
, , .
:
, , "" (, , ..):
public abstract class Post
{
public void Validate()
{
if (!this.GeospatialIdentity.IsValidForThisTypeOfPost())
throw new DomainException(this, BusinessException.PostNotValidForThisSpatial.);
}
}
, - . DomainException , . BusinessException, . enum .
, , , " ", , , , , .
:
[HttpPost]
public ActionResult Create(QuestionViewModel viewModel)
{
if (!ModelState.IsValid)
return View(viewModel);
try
{
var model = Mapper.Map<QuestionViewModel,Question>(viewModel);
postService.Save(model);
unitOfWork.Commit();
return RedirectToAction("Index", new { id = model.PostId });
}
catch (Exception exc)
{
var typedExc = exc as DomainException;
if (typedExc != null)
{
ModelState.AddModelError("Error", typedExc.BusinessError.ToDescription());
}
else
{
ModelState.AddModelError("Error", "Sorry, an error occured saving the Post. Support has been notified. Please try again later.");
}
}
return View(viewModel);
}
, , "" , . Save post.Validate(), -.
, . Save (90% , Entity Framework), .
, , . , HTTP POST .