Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9207029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:18:06+00:00 2026-06-18T00:18:06+00:00

I am creating an application that allows users to enter in their details into

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:18:07+00:00Added an answer on June 18, 2026 at 12:18 am

    You could create a a count method using EF, and then within your SaveExecute() command method, call the count, something like so;

    public int Count(int _ID)
    {
        DBEntities context = new DBEntities();
    
            return (from o in context.Entities
                    where o.EntityID == _ID
                    select o.EntityID).Count();
    }
    

    and then, in your command method;

        private void SaveExecute() //RelayCommand
        {
            if (Count(1) == 0)
            {
                InsertDetails(this); //Insert method using EF
                MessageBox.Show("Items have been addded.");
            }
            else
            {
                MessageBox.Show("An Item already exists, unable to add another one.");
            }
        }
    

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating an application that allows the user to store information about their classes.
I've been tasked with creating an application that allows users the ability to enter
I have a WPF Application which allows user to enter production Data. For that
I have an application that displays tabular information and allows the user to enter
I am creating a database application that (among many other things) allows users to
I'm creating an application for our office that allows authenticated users in the office
I'm creating a web application that allows users to make changes through Javascript. There
Background: I have created an application that allows users to submit an entry to
I have an application that allows different users to update some data that is
I have a drawing application in Android that allows the user to draw with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.