public List<Recipient> GetRecipientByCustomer(Guid customerId) { List<Recipient> listRecipient = new List<Recipient>(); try { using (SqlConnection con = new SqlConnection(VisitaJayaPerkasa.Constant.VisitaJayaPerkasaApplication.connectionString)) { con.Open(); using (SqlCommand command = new SqlCommand( "SELECT r.recipient_id, r.recipient_name, r.address, r.phone1, r.phone2, r.phone3 " + "FROM [Recipient] r " + "INNER JOIN [CUSTOMER_RECIPIENT] cr " + "ON cr.recipient_id = r.recipient_id " + "WHERE (r.deleted is null OR r.deleted = '0') " + "AND cr.customer_id = '" + customerId.ToString() + "' " + "ORDER BY recipient_name ASC" , con)) { SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Recipient recipient = new Recipient(); recipient.ID = Utility.Utility.ConvertToUUID(reader.GetValue(0).ToString()); recipient.Name = reader.GetString(1); recipient.Address = reader.GetValue(2).ToString(); recipient.Phone1 = Utility.Utility.IsDBNull(reader.GetValue(3)) ? null : reader.GetString(3); recipient.Phone2 = Utility.Utility.IsDBNull(reader.GetValue(4)) ? null : reader.GetString(4); recipient.Phone3 = Utility.Utility.IsDBNull(reader.GetValue(5)) ? null : reader.GetString(5); if (listRecipient == null) listRecipient = new List<Recipient>(); listRecipient.Add(recipient); recipient = null; } } } } catch (Exception e) { Logging.Error("SqlRecipientRepository.cs - GetRecipientByCustomer() " + e.Message); } return listRecipient; }
public List<Recipient> GetRecipient(){ List<Recipient> listRecipient = null; try { using (SqlConnection con = new SqlConnection(VisitaJayaPerkasa.Constant.VisitaJayaPerkasaApplication.connectionString)) { Constant.VisitaJayaPerkasaApplication.anyConnection = false; con.Open(); Constant.VisitaJayaPerkasaApplication.anyConnection = true; using (SqlCommand command = new SqlCommand( "SELECT recipient_id, recipient_name, address, phone1, phone2, phone3 " + "FROM [Recipient] r " + "WHERE (r.deleted is null OR r.deleted = '0') " + "ORDER BY recipient_name ASC" , con)) { SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Recipient recipient= new Recipient(); recipient.ID = Utility.Utility.ConvertToUUID(reader.GetValue(0).ToString()); recipient.Name = reader.GetString(1); recipient.Address = reader.GetValue(2).ToString(); recipient.Phone1 = Utility.Utility.IsDBNull(reader.GetValue(3)) ? null : reader.GetString(3); recipient.Phone2 = Utility.Utility.IsDBNull(reader.GetValue(4)) ? null : reader.GetString(4); recipient.Phone3 = Utility.Utility.IsDBNull(reader.GetValue(5)) ? null : reader.GetString(5); if (listRecipient == null) listRecipient = new List<Recipient>(); listRecipient.Add(recipient); recipient = null; } } } } catch (Exception e) { Logging.Error("SqlRecipientRepository.cs - GetRecipient() " + e.Message); } return listRecipient; }