72 lines
1.6 KiB
C#
72 lines
1.6 KiB
C#
using AdventureWorks.EntityLayer;
|
|
using AdventureWorks.ViewModelLayer;
|
|
using Common.Library;
|
|
using System.Windows.Input;
|
|
|
|
namespace AdventureWorks.MAUI.CommandClasses;
|
|
|
|
public class UserViewModelCommands : UserViewModel
|
|
{
|
|
#region constructors
|
|
public UserViewModelCommands() : base()
|
|
{
|
|
|
|
}
|
|
public UserViewModelCommands(IRepository<User> repo) : base(repo)
|
|
{
|
|
}
|
|
public UserViewModelCommands(IRepository<User> repo, IRepository<PhoneType> phoneRepo) : base(repo, phoneRepo)
|
|
{
|
|
}
|
|
#endregion
|
|
|
|
#region Private Variables
|
|
private bool _IsSaveCommandEnabled = true;
|
|
#endregion
|
|
|
|
#region Public Properties
|
|
public bool IsSaveCommandEnabled
|
|
{
|
|
get { return _IsSaveCommandEnabled; }
|
|
set
|
|
{
|
|
_IsSaveCommandEnabled = value;
|
|
RaisePropertyChanged(nameof(IsSaveCommandEnabled));
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Commands
|
|
public ICommand SaveCommand { get; private set; }
|
|
public ICommand EditCommand { get; private set; }
|
|
#endregion
|
|
|
|
#region Init Method
|
|
public override void Init()
|
|
{
|
|
base.Init();
|
|
SaveCommand = new Command(async () => SaveAsync(), () => IsSaveCommandEnabled);
|
|
EditCommand = new Command<int>(async (id) => await EditAsync(id), (id) => id > 0);
|
|
}
|
|
#endregion
|
|
|
|
protected async Task EditAsync(int id)
|
|
{
|
|
await Shell.Current.GoToAsync($"{nameof(Views.UserDetailView)}?id={id}");
|
|
}
|
|
|
|
public async Task<bool> SaveAsync()
|
|
{
|
|
var ret = base.Save();
|
|
if (ret)
|
|
{
|
|
await Shell.Current.GoToAsync("..");
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
}
|
|
|
|
|