0

I am using MVC3 with entity framework database

I just have a table which has the day of the week, the muscle you want to train and the amount of sets you wanna do for that muscle.

So basicly I am making a schedule. I start off with creating a schedule. And when I create a schedule, I want to make sure there are only one day of the week days in my table. (so Monday will be there one time)

The creating part works, but checking if it already excists and then giving the ok sign to fill the database with records is my problem. I am pretty sure that this needs to be done in my controller.

Get the Post from the view, and check if it already excists in my database. can someone help with an example?

deltu100
  • 581
  • 7
  • 26
  • Database is aspnetDB or sql server ? – Pankaj Apr 16 '12 at 17:27
  • This has already been discussed here : http://stackoverflow.com/questions/7443416/mvc-entity-framework-validation-to-prevent-duplicate-records – Beenish Khan Apr 16 '12 at 17:31
  • @beenish, I have no idea what they are doing. The answer was just talking about the error messages, and not really the steps of checking for duplication – deltu100 Apr 16 '12 at 17:46

1 Answers1

1

The best way to go in MVC with this would be to use a custom Data Annotation on your model. Here is an example: http://byatool.com/mvc/custom-data-annotations-with-mvc-how-to-check-multiple-properties-at-one-time/

Your custom annotation should check the database to see if any exist with the same value. You could do a lot more with it than just that.

You will need to use this with the ModelState.IsValid - What is ModelState.IsValid valid for in ASP.NET MVC in NerdDinner?

Community
  • 1
  • 1
David Savage
  • 760
  • 5
  • 15