jeudi 27 décembre 2018

ASP.NET Web API 2 using Get method to search data from table multiple parameter

This is a code. i want if ID Value is 12 digit or 13 digit search will be formed and return the object value if data matched or return null if not matched.

public MobilinkN get(ulong ID)
        {
            SubInfoNEntities robject = new SubInfoNEntities();
            using (SubInfoNEntities entities = new SubInfoNEntities())
            {
                string scnic = ID.ToString();
                if (scnic.Length == 13)
                {
                    return entities.MobilinkNs.FirstOrDefault(e => e.CNIC == scnic);
                }
                else if(scnic.Length == 12)
                { 
                   return entities.MobilinkNs.FirstOrDefault(e => e.MSISDN ==scnic);
                }
                return entities.MobilinkNs.FirstOrDefault(e => e.MSISDN == scnic);

            }
        }




Aucun commentaire:

Enregistrer un commentaire