public IEnumerable <Resident> SetResidentInfo() { String strQuery = ""; try { using (SqlConnection societyConn = new SqlConnection()) { societyConn.ConnectionString = Utility.SocietyConnectionString; societyConn.Open(); Resident res = new Resident(); DataSet ds = res.GetActiveResident(UserID); if (ds == null) { return(null); } else if (ds.Tables[0].Rows.Count == 0) { allResidents = new List <Resident>(); return(allResidents); } else { allResidents = new List <Resident>(); foreach (DataRow item in ds.Tables[0].Rows) { string strResID = item["ResID"].ToString(); var activeDate = item["ActiveDate"].ToString(); var deActiveDate = item["DeActiveDate"].ToString(); var userType = item["Type"].ToString(); var intercomNumber = item["IntercomNumber"].ToString(); int flatID = 0; string flatNumber = ""; int serviceType = 0; string compName = ""; int _HouseID = 0; var _HouseNo = ""; var _Sector = ""; var _City = ""; var _State = ""; var _Pin = ""; if (userType == "Owner" || userType == "Tenant") { flatID = Convert.ToInt32(item["FlatID"]); flatNumber = item["FlatNumber"].ToString(); } else if (userType == "Admin") { flatID = Convert.ToInt32(item["FlatID"]); flatNumber = item["FlatNumber"].ToString(); } else if (userType == "Employee" || userType == "Admin") { int.TryParse(item["ServiceType"].ToString(), out serviceType); compName = item["CompanyName"].ToString(); } else if (userType == "Individual") { _HouseID = Convert.ToInt32(item["HouseID"]); _HouseNo = item["HouseNUmber"].ToString(); _Sector = item["Sector"].ToString(); _City = item["City"].ToString(); _State = item["State"].ToString(); _Pin = item["PinCode"].ToString(); } else { } String pActiveDate = activeDate != string.Empty ? Utility.DBStringtoLocalDateTime(activeDate).ToString("dd/MM/yyyy") : null; String pDeActiveDate = Utility.DBStringtoLocalDateTime(deActiveDate).ToString("dd/MM/yyyy"); Resident newRes = new Resident() { ResID = Convert.ToInt32(strResID), UserType = userType, SocietyID = Convert.ToInt32(item["SocietyID"]), SocietyName = item["SocietyName"].ToString(), ActiveDate = activeDate != string.Empty ? Utility.DBStringtoLocalDateTime(activeDate).ToString("dd/MM/yyyy") : "", DeActiveDate = Utility.DBStringtoLocalDateTime(deActiveDate).ToString("dd/MM/yyyy"), FlatID = flatID, FlatNumber = flatNumber, CompanyName = compName, ServiceType = serviceType, IntercomNumber = intercomNumber, HouseID = _HouseID, HouseNo = _HouseNo, Sector = _Sector, City = _City, State = _State, Pin = _Pin }; allResidents.Add(newRes); if (currentResident == null) { currentResident = newRes; } } return(allResidents); } //else if (ds.Tables[0].Rows.Count == 1) //{ // string strResID = ds.Tables[0].Rows[0]["ResID"].ToString(); // ResiID = Convert.ToInt32(strResID); // UserType = ds.Tables[0].Rows[0]["Type"].ToString(); // SocietyID = Convert.ToInt32(ds.Tables[0].Rows[0]["SocietyID"]); // ActiveDate = ds.Tables[0].Rows[0]["ActiveDate"].ToString(); // ActiveDate = Convert.ToDateTime(ActiveDate).ToString("dd/MM/yyyy"); // DeActiveDate = ds.Tables[0].Rows[0]["DeActiveDate"].ToString(); // DeActiveDate = Convert.ToDateTime(DeActiveDate).ToString("dd/MM/yyyy"); // if (UserType == "Owner" || UserType == "Tenant") // { // FlatNumber = ds.Tables[0].Rows[0]["FlatID"].ToString(); // } // else if (UserType == "ResidentAdmin") // { // FlatNumber = ds.Tables[0].Rows[0]["FlatID"].ToString(); // } // else if (UserType == "Employee" || UserType == "EmployeeAdmin") // { // ServiceType = ds.Tables[0].Rows[0]["ServiceType"].ToString(); // CompName = ds.Tables[0].Rows[0]["CompanyName"].ToString(); // } // else // { return null; } //} } //return new List<Resident>() { this}; } catch (Exception ex) { return(null); } }