66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
using AdventureWorks.EntityLayer;
|
|
using AdventureWorks.ViewModelLayer.ViewModelClasses;
|
|
using Common.Library;
|
|
using System.Windows.Input;
|
|
|
|
namespace AdventureWorks.MAUI.CommandClasses
|
|
{
|
|
public class ProductViewModelCommands : ProductViewModel
|
|
{
|
|
#region Constructors
|
|
public ProductViewModelCommands() : base()
|
|
{
|
|
}
|
|
public ProductViewModelCommands(IRepository<Product> repo) : base(repo)
|
|
{
|
|
}
|
|
#endregion
|
|
|
|
public ICommand SaveCommand { get; private set; }
|
|
public ICommand EditCommand { get; private set; }
|
|
|
|
private bool _IsSaveCommandEnabled = true;
|
|
public bool IsSaveCommandEnabled
|
|
{
|
|
get { return _IsSaveCommandEnabled; }
|
|
set
|
|
{
|
|
_IsSaveCommandEnabled = value;
|
|
RaisePropertyChanged(nameof(IsSaveCommandEnabled));
|
|
}
|
|
}
|
|
|
|
public override void Init()
|
|
{
|
|
base.Init();
|
|
SaveCommand = new Command(async () => await SaveAsync(), () => IsSaveCommandEnabled);
|
|
EditCommand = new Command<int>(async (id) => await EditAsync(id), (id) => id > 0);
|
|
}
|
|
|
|
public async Task<bool> SaveAsync()
|
|
{
|
|
var ret = base.Save();
|
|
if (ret)
|
|
{
|
|
await Shell.Current.GoToAsync("..");
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
protected async Task EditAsync(int id)
|
|
{
|
|
await Shell.Current.GoToAsync($"{nameof(Views.ProductDetailView)}?id={id}");
|
|
}
|
|
|
|
public void LoadProducts()
|
|
{
|
|
Get();
|
|
}
|
|
public void LoadProductById(int id)
|
|
{
|
|
ProductObject = Get(id);
|
|
}
|
|
}
|
|
}
|