Hi,
I have 2 classes.
The line
return Foods.First(x => x._id == id);
Gives me an error
Error 1 'Check_Eat.Food' does not contain a definition for '_id' and no extension method '_id' accepting a first argument of type 'Check_Eat.Food' could be found (are you missing a using directive or an assembly reference?)
What I am doing wrong?
Thanks
namespace Check_Eat.Models
{
public class Food : INotifyPropertyChanged
{
#region Properties
private int id;
public int _id
{
get
{
return id;
}
set
{
if (id != value)
{
id = value;
OnNotifyPropertyChanged("_id");
}
}
}
private string _code = string.Empty;
public string code
{
get
{ return _code; }
set
{
if (_code != value)
{
_code = value;
OnNotifyPropertyChanged("code");
}
}
}
private string _category = string.Empty;
public string category
{
get
{ return _category; }
set
{
if (_category != value)
{
_category = value;
OnNotifyPropertyChanged("category");
}
}
}
private string _description = string.Empty;
public string description
{
get
{ return _description; }
set
{
if (_description != value)
{
_description = value;
OnNotifyPropertyChanged("description");
}
}
}
private string _calories = string.Empty;
public string calories
{
get
{ return _calories; }
set
{
if (_calories != value)
{
_calories = value;
OnNotifyPropertyChanged("calories");
}
}
}
private string _serving = string.Empty;
public string serving
{
get
{ return _serving; }
set
{
if (_serving != value)
{
_serving = value;
OnNotifyPropertyChanged("serving");
}
}
}
#endregion "Properties"
#region INotifyPropertyChanged Interface
public event PropertyChangedEventHandler PropertyChanged;
private void OnNotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
}
namespace Check_Eat.ViewModels
{
public class FoodViewModel : INotifyPropertyChanged
{
#region Fields and Properties
// This property will be bound to GridView's ItemsDataSource property for providing data
private ObservableCollection<Food> foods;
// This property will be bound to button's Command property for deleting item
public IDelegateCommand DeleteCommand { protected set; get; }
public ObservableCollection<Food> Foods
{
get
{
return foods;
}
set
{
if (foods != value)
{
foods = value;
OnPropertyChanged("Foods");
}
}
}
#endregion
#region Constructor
public FoodViewModel()
{
// create a DeleteCommand instance
this.DeleteCommand = new DelegateCommand(ExecuteDeleteCommand);
// Get data source
Foods = InitializeSampleData.GetData();
}
#endregion
#region Execute and CanExecute methods
void ExecuteDeleteCommand(object param)
{
int id = (Int32)param;
Food cus = GetFoodById(id);
if (cus != null)
{
Foods.Remove(cus);
}
}
#endregion
// Get the deleting item by Id property
private Food GetFoodById(int id)
{
return Foods.First(x => x._id == id);
}
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
}
ADRIAN DIBU