This repository has been archived on 2020-12-20. You can view files and clone it, but cannot push or open issues or pull requests.
aurora-sharp-desktop/Aurora/Design/Views/Party/NewPartyDialog/NewPartyDialogViewModel.cs
2019-12-07 13:47:45 -05:00

72 lines
2.0 KiB
C#

using System;
using Xamarin.Forms;
namespace Aurora.Design.Views.Party.NewPartyDialog
{
public class NewPartyDialogViewModel : BaseDialogViewModel
{
public NewPartyDialogViewModel()
{
this.ReturnObject = new ConnectionDetails();
HostCommand = new Command(OnHostExecute, OnHostCanExecute);
JoinCommand = new Command(OnJoinExecute, OnJoinCanCanExecute);
}
public string Hostname
{
get
{
if (ReturnObject is ConnectionDetails)
{
ConnectionDetails obj = ReturnObject as ConnectionDetails;
return obj.HostName;
};
return string.Empty;
}
set
{
if (ReturnObject is ConnectionDetails)
{
ConnectionDetails obj = ReturnObject as ConnectionDetails;
if (value != obj.HostName)
{
obj.HostName = value;
}
OnPropertyChanged(Hostname);
HostCommand.ChangeCanExecute();
JoinCommand.ChangeCanExecute();
}
}
}
public void OnHostExecute()
{
ConnectionDetails obj = base.ReturnObject as ConnectionDetails;
obj.ConnectionType = ConnectionType.Host;
Finish();
}
public Command HostCommand { get; private set; }
public Command JoinCommand { get; private set; }
public bool OnHostCanExecute()
{
return string.IsNullOrWhiteSpace(Hostname);
}
public void OnJoinExecute()
{
ConnectionDetails obj = base.ReturnObject as ConnectionDetails;
obj.ConnectionType = ConnectionType.Join;
Finish();
}
public bool OnJoinCanCanExecute()
{
return !string.IsNullOrWhiteSpace(Hostname);
}
}
}