Advertisement
Guest User

Untitled

a guest
Aug 4th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. using CocoTest.Core.Services;
  2. using MvvmCross.Core.ViewModels;
  3.  
  4. namespace CocoTest.Core.ViewModels
  5. {
  6. public class LoginViewModel : MvxViewModel
  7. {
  8. #region Fields
  9. readonly ILoginService _loginService;
  10. readonly IDialogService _dialogService;
  11. #endregion Fields
  12.  
  13. #region Constructors
  14. public LoginViewModel(ILoginService loginService, IDialogService dialogService)
  15. {
  16. _loginService = loginService;
  17. _dialogService = dialogService;
  18. }
  19. #endregion Constructors
  20.  
  21. #region Properties
  22. string _userName;
  23. public string UserName
  24. {
  25. get
  26. {
  27. return _userName;
  28. }
  29. set
  30. {
  31. _userName = value;
  32. RaisePropertyChanged(() => UserName);
  33. }
  34. }
  35.  
  36. string _password;
  37. public string Password
  38. {
  39. get
  40. {
  41. return _password;
  42. }
  43. set
  44. {
  45. _password = value;
  46. RaisePropertyChanged(() => Password);
  47. }
  48. }
  49.  
  50. IMvxCommand _loginCommand;
  51. public IMvxCommand LoginCommand
  52. {
  53. get
  54. {
  55. _loginCommand = _loginCommand ?? new MvxCommand(AttemptLogin);
  56. return _loginCommand;
  57. }
  58. }
  59. #endregion Properties
  60.  
  61. #region Private Methods
  62. async void AttemptLogin()
  63. {
  64. var ok = await _loginService.Login(UserName, Password);
  65. if (ok)
  66. {
  67. ShowViewModel<MainViewModel>();
  68. }
  69. else
  70. {
  71. _dialogService.Alert("Inicio de sesión fallido", "Error", "OK");
  72. }
  73. }
  74.  
  75. #endregion Private Methods
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement