Advertisement
Guest User

Untitled

a guest
Jul 11th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. public class DelegateCommand : ICommand
  2. {
  3. private readonly Predicate<object> _canExecute;
  4. private readonly Action<object> _execute;
  5.  
  6. public event EventHandler CanExecuteChanged;
  7.  
  8. public DelegateCommand(Action<object> execute)
  9. : this(execute, null)
  10. {
  11. }
  12.  
  13. public DelegateCommand(Action<object> execute, Predicate<object> canExecute)
  14. {
  15. _execute = execute;
  16. _canExecute = canExecute;
  17. }
  18.  
  19. public bool CanExecute(object parameter)
  20. {
  21. return _canExecute == null || _canExecute(parameter);
  22. }
  23.  
  24. public void Execute(object parameter)
  25. {
  26. _execute(parameter);
  27. }
  28.  
  29. public void RaiseCanExecuteChanged()
  30. {
  31. CanExecuteChanged?.Invoke(this, EventArgs.Empty);
  32. }
  33. }
  34.  
  35. #region RegisterCommand
  36.  
  37. private DelegateCommand _registerCommand;
  38. public ICommand RegisterCommand
  39. {
  40. get
  41. {
  42. _registerCommand = new DelegateCommand(param => Register());
  43. return _registerCommand;
  44. }
  45. }
  46.  
  47. private bool CanRegister()
  48. {
  49. return true;
  50. }
  51.  
  52. private void Register()
  53. {
  54. var newUser = new User
  55. {
  56. FirstName = _firstname,
  57. LastName = _lastname,
  58. Username = _username,
  59. Password = "", // TODO: Hashing and storing of passwords
  60. };
  61. using (var context = new WorkstreamContext())
  62. {
  63. var users = context.Set<User>();
  64. users.Add(newUser);
  65. context.SaveChanges();
  66. }
  67. }
  68.  
  69. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement