Update:
I have a dropdownlist with seven different options like (date, subject, press, cia, media…) and user will select one of the item from the dropdownlist and click on search button to get the results.
Here is my repository class GetInquiries method which accepts 7 parameters but it will pass only one parameters at a time to the stored procedure and in case of Date (it will pass both from/to)
public List<Inquiry> GetInquiries(string fromDate, string toDate,
string subject, string press,
string cia, string media,
string status)
Here is what I have come up with passing the parameters to GetInquiries:
if (!string.IsNullOrEmpty(this.txtSubject.Text.Trim()))
{
e.Result = reporterRepo.GetInquiries(null,null,txtSubject.Text,null,null,null,null);
}
else
{
e.Result = reporterRepo.GetInquiries(null,null,null,null,null,null,null);
}
else if (!string.IsNullOrEmpty(this.fromDate.Text.Trim()))
e.Result = reporterRepo.GetInquiries(fromDate.Text,null,null,null,null,null,null)
.......................
...................
....................
I have to continue seven times with (if else if conditions) for all seven parameters.
Is there a way I can do it more clearly and more readability?
Note that
this.txtSubject.Text.Trim()will never be null, and ifthis.txtSubject.Textis null, this will throw an exception.