Skip to content

Instantly share code, notes, and snippets.

@taylonr
Last active December 11, 2015 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taylonr/4570440 to your computer and use it in GitHub Desktop.
Save taylonr/4570440 to your computer and use it in GitHub Desktop.
public class UserController : Controller
{
[HttpPost]
public ActionResult Create(string email, string password, string firstName, string lastName)
{
new UserLogic().Create(email, password, firstName, lastName);
return View("UserCreated");
}
}
public class UserLogic
{
public void Create(string email, string password, string firstName, string lastName)
{
if(string.IsNullOrWhiteSpace(email))
throw new InvalidEmailException();
if(!new Regex("^[A-Za-z]\w{6,}[A-Za-z]$").IsMatch(password))
throw new InvalidPasswordException();
if(string.IsNullOrWhiteSpace(firstName) || string.IsNullOrWhiteSpace(lastame))
throw new InvalidNameException();
var repo = new UserRepository();
repo.Create(new UserEntity{
Email = email;
Password = password;
FirstName = firstName;
LastName = lastName;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment