Lets say I have something like this:
public ActionResult Test(SomeModel m)
{
try
{
_db.SaveModel(m);
SendMailToUser(m);
RedirectToRoute("Something");
}
catch
{
return View();
}
}
And I got problems with howto deal with this if “SendMailToUser” fails. Model gets saved to database. How can I make it continue if the mail fails to send?
/M
If you just want to swallow the exception (if thrown) from the
SendMailTouser(m)function you could do:If you want to not save the model if the email sending fails, you should wrap the two in a unit-of-work or a transaction block such that it will rollback the Save if the email fails.