using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core.Commands;
using Tango.PPC.Common;
using Tango.PPC.Common.Navigation;
using SimpleValidator.Extensions;
using System.ComponentModel.DataAnnotations;
namespace Tango.PPC.UI.ViewModels
{
public class LoginViewVM : PPCViewModel
{
public RelayCommand LoginCommand { get; set; }
private String _email;
[Required(ErrorMessage = "Email is required")]
[EmailAddress(ErrorMessage = "Please enter a valid email address")]
public String Email
{
get { return _email; }
set { _email = value; RaisePropertyChangedAuto(); }
}
private String _password;
[Required(ErrorMessage = "Password is required")]
public String Password
{
get { return _password; }
set { _password = value; RaisePropertyChangedAuto(); }
}
public LoginViewVM()
{
LoginCommand = new RelayCommand(Login);
Email = "roy@twine-s.com";
Password = "1234";
}
public override void OnApplicationStarted()
{
}
private void Login()
{
if (Validate())
{
var user = AuthenticationProvider.Login(Email, Password);
if (user == null)
{
NotificationProvider.ShowWarning("Email or password are incorrect.");
}
ApplicationManager.ModulesInitialized += (_, __) =>
{
NavigationManager.NavigateTo(NavigationView.HomeModule);
};
}
}
}
}