What layer will I validate a CSV file in?

G

Guest

We have a debate here. We are receiving a CSV file specified by the user and
need to validate the contents, writing the "good" records to the database and
displaying the "bad" records to the user. One developer wants to loop
through the CSV file right on the web layer (ASPX) and then only pass the
"good" records onto the DAL. The other developer wants to pass the whole
file as an OBJECT to the business logic layer and then loop through there,
passing onto the DAL the "good" records and returning the "bad" records back
to the web layer to be presented to the user.

Is there a "best practice" here? The first developer is looking at the file
as just another user input to be validated, while the other developer is
looking at the file as an object, to be passed through to the BLL. Any
insights or recommendations?? Thanks!
 
S

sloan

The developer who wants to do it on the aspx page is wrong , in my opinion.

The to the bll , and return bad entries approach is acceptable. it depends
if its an "all or nothing" or "most records are ok".

But the code to check the values needs to be in the biz layer.....
You can decide what you want to do if bad records are found.

Process Good Ones, and Return Bad ones.
OR
Pass Back the Bad Ones (as fyi's), and only submit the data once they've
corrected all the data.


The issue of tiered development sometimes equates to "where do I get the
best re-use?"... and putting the code in a aspx code behind is way off on
that mark.

...

Like most things, take my advice with a grain of salt. But I'd argue my
point fervantly, if I was dealing with the scenario.
 
C

Craig Deelsnyder

We have a debate here. We are receiving a CSV file specified by the
user and
need to validate the contents, writing the "good" records to the
database and
displaying the "bad" records to the user. One developer wants to loop
through the CSV file right on the web layer (ASPX) and then only pass the
"good" records onto the DAL. The other developer wants to pass the whole
file as an OBJECT to the business logic layer and then loop through
there,
passing onto the DAL the "good" records and returning the "bad" records
back
to the web layer to be presented to the user.

I always put such logic in the business layer; either way you have to
postback and do this work on the server, so bandwidth isn't an issue
(unless your BLL is hosted out-of-process on another server). What
consitutes a 'good record' is a business validation (or perhaps data
layer, if it's truly a passthrough with no corresponding BLL object).
aspx files should only know how to get data it needs from a controller
class and bind/display it to a form, do simple validation, that's it.

My view on it, at least...and some depends on how robust your 3-tier
design is at this point....
 
G

Guest

Clarification: The first developer wants to do the validation in the CODE
BEHIND page, not on the ASPX page per se. Does this change anyone's
responses?
 
S

sloan

No, it doesn't change the response.

I'm sure we all knew that up front, it was the codebehind page, not the
html/aspx page.
 
S

sloan

Just one more thought.

Data Validation should happen in the biz table, regardless.

Now, with the web, ~sometimes we put validation in the webpage, to save a
server trip.

(Aka, make sure they put in a lastname in the txtLastName input box).

However, this is for saving some roundtrip resources,,, not because its
architecturally correct.

The check for "did the user put in their last name" should ALSO be put in
the biz layer......

That way, if the browser chokes on the javascript ( with asp.net validator
routines), the biz object will still throw the appropriate exception.

Alot of developers forget this.... since they get so used to writing
validation routines in the aspx page .. via the validator controls, or
custom javascript.

The general rule of thumb is this

"What if I need to do this .. in a winforms app?". Now.. you'll see it
makes sense to put the check in the biz object.. to check for a last name.

BECAUSE OF THE NATURE OF THE WEB, you can add the additional javascript
check... to save a trip to the web server, but that's for avoiding a round
trip, not because its correct architectually.

...
 
C

Craig Deelsnyder

KMZ_state said:
Clarification: The first developer wants to do the validation in the CODE
BEHIND page, not on the ASPX page per se. Does this change anyone's
responses?

no...'same thing' in this discussion. code-behind class is still part
of the UI layer, doesn't change a thing in my comments
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top