Handle Orchard Custom Content Part with unique constraint

Topics: Customizing Orchard, General, Writing modules
Sep 15, 2013 at 9:58 AM
I have an Orchard Custom Content Part with 2 fields (Name and Description). I have created Migrations.cs with an unique constraint on "Name" column. I can see constraint created in DB, however when I try to force Orchard with duplicate values, it crashes giving a timeout error. How do I handle it gracefully ? Should the Handler of the ContentPart be modified to handle that ? Pl give some tips or point me to the relevant URL (I cant seem to find any online).
Sep 17, 2013 at 4:19 PM
Edited Sep 17, 2013 at 4:50 PM
This is something I am also interested in. It'd be nice, when adding fields for Content Definitions, to just be able to check a box that states "Unique", and when that box is checked it queries the DB to verify that it is unique before submitting the data. Would think that this would have already been requested for the main project. Not a developer unfortunately.

From what I know about JScript, it would seem like you could modify the fields to have a check box for a unique identifier. Then on a form submit, it can use a try catch (maybe) to see if any fields in the form have that check value. If so, then query against the database to check for an identical value in that field. If it comes back clean then it submits, if not then it alerts the user. By doing it like that you don't have to even modify the database, it would just be handled through code. Seems to work from a logical standpoint, I just have no clue how to actually make it work. Wish I could help more.
Sep 18, 2013 at 9:33 AM
Edited Sep 18, 2013 at 9:34 AM
I have opened some time ago an issue for this, you could vote here to bring more focus on it
https://orchard.codeplex.com/workitem/19828
Sep 18, 2013 at 9:49 AM
@CSADNT .. voted.. thanks