Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is it possible to simplify this code?
Message
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01581943
Message ID:
01600891
Views:
33
>>>Could you reformat it into a switch statement?
>>>
>>>Bill
>>>
>>
>>How about this case - is there a way to simplify? (In VFP it's case expression):
>>
>>
>> Boolean isRedemptionValid = row.Field<Boolean>("IsRedemptionValid"),
>>                        isDateValid = row.Field<Boolean>("IsDateValid"),
>>                        isTimeValid = row.Field<Boolean>("IsTimeValid"),
>>                        isDowValid = row.Field<Boolean>("IsDowValid");
>>
>>                    if (isRedemptionValid && isDateValid && isTimeValid && isDowValid)
>>                        {
>>                            availability = "Available for Redemption";
>>                        }
>>                    else
>>                        if (!isRedemptionValid)
>>                        {
>>                            availability = "Not enough number of uses";
>>                        }
>>                        else
>>                            if (!isDateValid)
>>                            {
>>                                availability = "Not available in the date range";
>>                            }
>>                            else
>>                                if (!isTimeValid)
>>                                {
>>                                    availability = "Not available in the time range";
>>                                }
>>                                else
>>                                {
>>                                    availability = "Not available on that day of the week";
>>                                }
>
>Questions : Do you really want to abort the checks after the first 'fail' ?
>If 'yes' then I'd put it in a separate method with multiple returns (although I know there are those who religiously insist on one exit point :-})
>If 'no' then something based on Bill's approach (but with a string builder)

I think I want to return just the main reason. I've been thinking that I probably should just return this info as a column using case in T-SQL. Since this information is coming from a stored procedure, I see no problem adding an extra column right away.

I'll probably go with that route, Craig's suggestion made me think about it yesterday.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform