public static List <LocalContacts> GetAll() { DBCon con = new DBCon(); SqlCommand cmd = null; SqlDataReader SDR = null; var CurrOrgObj = HttpContext.Current.Request.Cookies["UserInfo"]; List <LocalContacts> listUnit = new List <LocalContacts>(); try { string Quary = "SELECT DISTINCT(MobileNo),* from LocalContacts "; if (CurrOrgObj != null && CurrOrgObj["OrgID"] != "0") { Quary = "SELECT DISTINCT(MobileNo),* from LocalContacts where OrgId=" + CurrOrgObj["OrgID"]; } cmd = new SqlCommand(Quary, con.Con); SDR = cmd.ExecuteReader(); while (SDR.Read()) { LocalContacts OBJINT = new LocalContacts(); OBJINT.ContctID = SDR.GetInt32(1); OBJINT.MobileNo = SDR.GetString(2); OBJINT.Cust_Name = SDR.GetString(3); listUnit.Add(OBJINT); } } catch (Exception e) { e.ToString(); } finally { cmd.Dispose(); con.Con.Close(); } return(listUnit); }
public static LocalContacts GetOne(int ID = 0, string Mobile = null) { SqlConnection Con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Con"].ToString()); Con.Open(); SqlCommand cmd = null; SqlDataReader SDR = null; var CurrOrgObj = HttpContext.Current.Request.Cookies["UserInfo"]; LocalContacts ObjTmp = new LocalContacts(); try { string Query = "SELECT TOP 1 * FROM LocalContacts"; if (ID > 0) { Query += " where ContctID=" + ID; } else if (Mobile != null) { Query += " where MobileNo=" + Mobile; } if (CurrOrgObj != null && ID == 0) { Query += " and OrgId=" + CurrOrgObj["OrgId"]; } cmd = new SqlCommand(Query, Con); SDR = cmd.ExecuteReader(); while (SDR.Read()) { ObjTmp.ContctID = SDR.GetInt32(0); ObjTmp.MobileNo = SDR.GetString(1); ObjTmp.Cust_Name = SDR.GetString(2); } } catch (System.Exception e) { e.ToString(); } finally { cmd.Dispose(); Con.Close(); } return(ObjTmp); }