Advertisement
Guest User

Untitled

a guest
May 27th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. public class User
  2. {
  3.     public string Login {get; set;}
  4.     public string Password {get; set;}
  5.     public string Email {get; set;}
  6. }
  7.  
  8. public class UserRegisterInput
  9. {
  10.     public string Login {get; set;}
  11.     public string Password {get; set;}
  12.     public string PasswordConfirm{get;set;}
  13.     public string Email {get; set;}
  14.     public bool IsTermsAccepted{get; set;}
  15. }
  16.  
  17. public interface IUserRepository
  18. {
  19.     User GetUserByEmail(string email);
  20.     User GetUserByLogin(string login);
  21.     User Create(User user);
  22. }
  23.  
  24. public interface IUserServices
  25. {
  26.     User Register(UserRegisterInput input);
  27. }
  28.  
  29. public class UserServices : IUserServices
  30. {
  31.     private IUserRepository _userRepository;
  32.     public UserServices(IUserRepository userRepository, IValidatorFactory validatorFactory)
  33.     {
  34.         _userRepository = userRepository;
  35.         _validatorFactory = validatorFactory;
  36.     }
  37.  
  38.     public User Register(UserRegisterInput input)
  39.     {
  40.         var validationResult = validatorFactory.Validate(input);
  41.         if (!validationResult.IsValid)
  42.             return null;
  43.        
  44.         var user = new User {Login = input.Login, Password = input.Password, Email = input.Email}
  45.         return _userRepository.Create(user);
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement