Closed jibai-kia closed 1 year ago
// RewardVM.cs
using System.Collections.ObjectModel;
using Prism.Mvvm;
using CleanBrightCompany.Domain;
namespace CleanBrightCompany.ViewModels
{
public class RewardVM : BindableBase
{
private readonly IRewardManagement _management;
private ObservableCollection<Reward> _rewards;
public ObservableCollection<Reward> Rewards
{
get { return _rewards; }
set { SetProperty(ref _rewards, value); }
}
public RewardVM(IRewardManagement management)
{
_management = management;
Rewards = new ObservableCollection<Reward>(_management.GetAllRewards());
}
public void CreateReward(Reward reward)
{
_management.CreateReward(reward);
Rewards.Add(reward);
}
public void UpdateReward(Reward reward)
{
_management.UpdateReward(reward);
}
public void DeleteReward(Reward reward)
{
_management.DeleteReward(reward);
Rewards.Remove(reward);
}
}
}
-
This is a C# class file for a RewardVM, which is a class that implements the logic for managing rewards in a rewards program. The class uses the Prism.Mvvm namespace and inherits from the BindableBase class, which is a base class for implementing the INotifyPropertyChanged interface, used for data binding in WPF and UWP applications.
The RewardVM class has a private field, _management, of type IRewardsManagement, which is an interface for a management that manages rewards data. The class also has a public property, Rewards, of type ObservableCollection
The class has a constructor that takes an IRewardsManagement object as a parameter and initializes the Rewards property with the result of calling the GetAllRewards method of the management. The class also has three public methods for creating, updating, and deleting rewards. These methods call the corresponding methods of the management and update the Rewards collection accordingly.
-
This thread provides updates related to Reward View Model