Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using CocoTest.Core.Services;
- using MvvmCross.Core.ViewModels;
- namespace CocoTest.Core.ViewModels
- {
- public class LoginViewModel : MvxViewModel
- {
- #region Fields
- readonly ILoginService _loginService;
- readonly IDialogService _dialogService;
- #endregion Fields
- #region Constructors
- public LoginViewModel(ILoginService loginService, IDialogService dialogService)
- {
- _loginService = loginService;
- _dialogService = dialogService;
- }
- #endregion Constructors
- #region Properties
- string _userName;
- public string UserName
- {
- get
- {
- return _userName;
- }
- set
- {
- _userName = value;
- RaisePropertyChanged(() => UserName);
- }
- }
- string _password;
- public string Password
- {
- get
- {
- return _password;
- }
- set
- {
- _password = value;
- RaisePropertyChanged(() => Password);
- }
- }
- IMvxCommand _loginCommand;
- public IMvxCommand LoginCommand
- {
- get
- {
- _loginCommand = _loginCommand ?? new MvxCommand(AttemptLogin);
- return _loginCommand;
- }
- }
- #endregion Properties
- #region Private Methods
- async void AttemptLogin()
- {
- var ok = await _loginService.Login(UserName, Password);
- if (ok)
- {
- ShowViewModel<MainViewModel>();
- }
- else
- {
- _dialogService.Alert("Inicio de sesión fallido", "Error", "OK");
- }
- }
- #endregion Private Methods
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement