I have just refactored a lot of code out of my AccountController
into an Authentication
provider class. The controller used to perform this check:
if (_memberRepository.GetByUserName(model.UserName) != null)
{
ModelState.AddModelError("", "The user name you have chosen already exists. Please choose another.");
return View(model);
}
I have moved this into my Authentication
class, but there I have no access to ModelState
.
if (_memberRepository.GetByUserName(newMember.LoginName) != null)
{
// Panic stations!!
}
Should I:
a) Return a class that described the status or outcome of the new method? I feel this is overcomplicating things. b) Throw an Exception (maybe ArgumentException?) that signals my objection to registering a duplicate user name? This is quick and simple, yet it borders on using an exception for business logic
I see there is already a MembershipCreateUserException
, but I like to steer clear of using the build in membership functionality. It is not good OO and I feel dirty using it.