I am developing a software for managing members for a club.I created an offline search function that takes 3 parameters which are object attributes and returns a list of Members.
Member class has :
String name;
String email;
String telephone;
search method :
public static List<Member> Search(String name, String email, String telephone,String username)
The method uses at least one of the attributes to search. How can I make it work on 1 attribute , 2 , or 3 in case the user knows the name, email, and telephone of the Members. I was doing this :
if (name != String.Empty) && email != String.Empty) && telephone != String.Empty))
{
if (Member.FirstName.Equals(name) && Member.Email.Equals(email) && Member.Telephone.Equals(telephone))
members_list.Add(Member.);
}
else if(name.Length > 0 && (email != String.Empty && telephone != String.Empty))
{
...
...
...etc
}
In sql it is quite easy
WHERE (FirstName = @FirstName or @FirstName is null)
AND (Email = @Email or @Email is null)
AND (Username =@Username or @Username is null)
AND (Telephone =@Telephone or @Telephone is null)
But in offline mode, it is not that simple Any suggestions for a more efficient way ?
!(name.Equals(String.Empty)usename != ""