I am creating an application that allows users to enter in their details into the database using MVVM and EF. I have a User Control which allows a user to enter a set of details into the database.
Within this application, the view-model contains properties, commands and CRUD operations.
What I want to achieve is to allow the user using this application to enter their details, but once a row has been entered into the database, disable the command altogether or throw an exception stating that one row has been added.
I have a tab control for the user to enter their details and then data grid for them to visually see the details been added.
Is this possible to achieve? How would this be done? Iterate through the rows and then find that row?
Here are my code snippets that my relevant;
View-Model;
private ICommand _AddCommand;
public ICommand AddCommand
{
get
{
if (this._AddCommand == null)
{
this._AddCommand = new RelayCommand(this.SaveExecute, this.SaveCanExecute);
}
return this._AddCommand;
}
}
private bool SaveCanExecute()
{
return !string.IsNullOrEmpty(Name);
}
private void SaveExecute()
{
InsertDetail();
}
xaml;
<Button Content="Save" Grid.Row="9" Name="btnSave" VerticalAlignment="Top" Grid.Column="1" Width="75"
Command="{Binding AddCommand}" />
Any help or guidance is appreciated as I am new to WPF and MVVM.
You could create a a
countmethod using EF, and then within yourSaveExecute()command method, call thecount, something like so;and then, in your command method;
Hope this helps!