Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. public UserDto GetUser(string email) {
  2. if (!ValidationUtil.IsValidEmail(email))
  3. throw new ArgumentException("Must be a properly formatted email", nameof(email));
  4. UserDto toReturn = null;
  5. toReturn = Users?.FirstOrDefault(user => user?.Email == email);
  6. return toReturn;
  7. }
  8.  
  9. public bool AreCredentialsValid(string email, string password) {
  10. bool toReturn = false;
  11. if (!ValidationUtil.IsValidEmail(email))
  12. throw new ArgumentException("Must be a properly formatted email", nameof(email));
  13. if (password == null)
  14. new ArgumentNullException(nameof(password));
  15. UserDto user = this.GetUser(email);
  16. if (user?.Email == email && user?.Password == password)
  17. toReturn = true;
  18. return toReturn;
  19. }
  20.  
  21. public UserDto GetUserIfCredentialsAreValid(string email, string password) {
  22. UserDto toReturn = null;
  23. if (AreCredentialsValid(email, password))
  24. toReturn = GetUser(email);
  25. return toReturn;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement