1

We need to create a program that collects runsheets and other form data.

All the forms need to be saved as they're typed, unless explicitly discarded, even the form field data is invalid.
The user should always be able to 'Save for later', or just shut off his window, and data should be saved.

The problem is I'm gonna have to have all the runsheets indexed and searchable, including the invalid ones.

I'm looking at few options:

  • Have a subclass of the same type that implements the validation (will that work?)
  • Serialize the invalid records as XML and store it somewhere else until its validated and saved permanently.
  • Not use validation attributes, but just custom validation (i.e. using IValidatableObject interface), that will bypass validation if another property on the record indicates that validation should be skipped, but then I might end up with a lot of data in the database in the same table, maybe this is not a problem as long as I'm control. I'm really considering this option the most.

My real doubt is:

  • If I store data elsewhere, searching will be a nightmare
  • If I make the validation in an external runtime method, avoiding the use of validation attributes, the columns in the database won't reflect the real property requirements (i.e. required fields).

I think I'll go for this option, because having to search two tables bothers me more, and also because indeed the columns won't be so strict, but I can still set their MaxLength and some other vital properties that are vital for the database structure but do not really disturb the validation process.
Really it's not that I'll have to store a datetime as a string or going that low.

I just wanted to hear from people who faced a similar situation and might have some smooth magical method...

Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632

2 Answers2

1

I think I'm just gonna go for very undisturbing validation in the model (i.e. MaxLength etc.), and a property that determines whether the model should be saved without validation, then implementing IValidatableObject I'll implement all the required validation attributes as custom custom validation.

Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
0

how about saving them all as cookie in user browser as a form of strings ( strings require no Validation in clientSide unless you bind it to). And just use Server validations for you database commits.

Check here for more information about saving data into cookies:

Storing multiple values in cookies

as I said use no client Validation in your model.

for that just use ViewModels and save ViewModel in Cookies. Then on your Controller just validate them when user wants to finally save into database.

Community
  • 1
  • 1
MRebati
  • 591
  • 14
  • 29
  • 1
    OP states that invalid data still needs to be indexable and searchable, so presumably the data will still need to be stored server-side. – Will Ray Aug 10 '16 at 05:02
  • 1
    You can just save data without validations as String in your database. and use your required validations via ViewModel or your Controllers for finalizing the data store procedure. – MRebati Aug 10 '16 at 05:04
  • The process of how to go about doing that is precisely the question, no? – Will Ray Aug 10 '16 at 05:16
  • Let me rephrase myself. for example you have DateTime as final model. All you do is to save that as string in another class (table of database) and check that as temp data. you can parse datetime in your controller for your analyzing usage. then if user wants to finalize the data saving then it will be saved with validations on your controllers. – MRebati Aug 10 '16 at 05:31
  • @MRebati The problem starts with the search and indexing if I store it in an external table. – Shimmy Weitzhandler Aug 10 '16 at 19:46
  • I have a solution for that. Use a flag in your table. If you're saving validated data change the flag. And if you're not validating data entry then don't change. And use validations in your controller. Not in your entity models. This will change the problem with indexing and searches. – MRebati Aug 10 '16 at 19:50
  • Sure that was the idea. I thought there was a better way. – Shimmy Weitzhandler Aug 10 '16 at 19:54
  • It will be messy since you have to handle validations in code and also saving invalid data in your main data storage. But as I said the first solution looks better. All you have to do is to parse data and join these collections and do the searches and other things. – MRebati Aug 10 '16 at 19:57
  • It's either messy indexing and search or messy validation. I vote hands down for messy validation. Putting two tables together for search will be a nightmare. Validation by code is sufferable, however I'll try to keep whatever I can as attribute - meaning validation always on for when possible. – Shimmy Weitzhandler Aug 11 '16 at 03:01