Created
January 19, 2013 03:00
-
-
Save taylonr/4570490 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} | |
[HttpPost] | |
public ActionResult Update(int userId, string email, string password, string firstName, string lastName) | |
{ | |
new UserLogc().Update(userId, email, password, firstName, lastName); | |
return View("UserUpdated"); | |
} | |
} | |
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; | |
}); | |
} | |
public void Update(int userId, string email, string password, string firstName, string lastName) | |
{ | |
if(userId <= 0) | |
throw new InvalidUserIdException(); | |
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(); | |
var user = repo.GetById(userId); | |
user.Email = email; | |
user.FirstName = firstName; | |
user.LastName = lastName; | |
user.Password = password; | |
repo.Save(user); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment