public TransactionResultDTO getContacts(SearchContactDTO searchOptions = null) { TransactionResultDTO result = new TransactionResultDTO(); List <Contact> listContacts; try { if (searchOptions != null) { result = validateSearchContactEntity(searchOptions); if (result.code == TransactionResultDTO.transactionResultCode.Success) { listContacts = contactsDAO.getContacts(searchOptions); result.code = TransactionResultDTO.transactionResultCode.Success; result.object1 = listContacts; } } else { listContacts = contactsDAO.getContacts(); result.code = TransactionResultDTO.transactionResultCode.Success; result.object1 = listContacts; } } catch (Exception ex) { listContacts = null; throw ex; } return(result); }
private TransactionResultDTO validateSearchContactEntity(SearchContactDTO entityToValidate) { TransactionResultDTO result = new TransactionResultDTO(); try { string lengthError = resourceManager.GetString("ErrorLongitudSuperada", cultureInfo); string formatError = resourceManager.GetString("ErrorFormatoIncorrecto", cultureInfo); string incompleteDatesRangeError = resourceManager.GetString("ErrorRangoFechasIncompleto", cultureInfo); string incorrectDatesRangeError = resourceManager.GetString("ErrorRangoFechasIncorrecto", cultureInfo); // Validate first name length if (entityToValidate.firstName.Length > FIRSTNAME_LENGTH) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = String.Format(lengthError, resourceManager.GetString("Nombre", cultureInfo), FIRSTNAME_LENGTH); return(result); } // Validate last name length if (entityToValidate.lastName.Length > LASTNAME_LENGTH) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = String.Format(lengthError, resourceManager.GetString("Apellidos", cultureInfo), LASTNAME_LENGTH); return(result); } // Validate genre format if (entityToValidate.genre != string.Empty) { if (entityToValidate.genre != "F" && entityToValidate.genre != "M") { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = String.Format(formatError, resourceManager.GetString("Genero", cultureInfo)); return(result); } } // Validate email format if (entityToValidate.email != string.Empty) { if (!Validations.isValidEmailFormat(entityToValidate.email)) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = String.Format(formatError, resourceManager.GetString("Email", cultureInfo)); return(result); } } // Validate email length if (entityToValidate.email.Length > EMAIL_LENGTH) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = String.Format(lengthError, resourceManager.GetString("Email", cultureInfo), EMAIL_LENGTH); return(result); } // Validate mobile number length if (entityToValidate.mobileNumber.Length > MOBILENUMBER_LENGTH) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = String.Format(lengthError, resourceManager.GetString("NumeroMovil", cultureInfo), MOBILENUMBER_LENGTH); return(result); } // Validate landline number length if (entityToValidate.landlineNumber.Length > LANDLINENUMBER_LENGTH) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = String.Format(lengthError, resourceManager.GetString("NumeroTelefono", cultureInfo), LANDLINENUMBER_LENGTH); return(result); } // Validate comments length if (entityToValidate.comments.Length > COMMENTS_LENGTH) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = String.Format(lengthError, resourceManager.GetString("Comentarios", cultureInfo), COMMENTS_LENGTH); return(result); } // Validate dates range to be complete if ((entityToValidate.createdSince != null && entityToValidate.createdUntil == null) || (entityToValidate.createdSince == null && entityToValidate.createdUntil != null)) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = String.Format(incompleteDatesRangeError, resourceManager.GetString("FechaCreacion", cultureInfo)); return(result); } // Validate since date to be less or equal than until date if (entityToValidate.createdSince != null && entityToValidate.createdUntil != null) { if (entityToValidate.createdSince > entityToValidate.createdUntil) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = String.Format(incorrectDatesRangeError, resourceManager.GetString("FechaCreacion", cultureInfo)); return(result); } } result.code = TransactionResultDTO.transactionResultCode.Success; } catch (Exception ex) { throw ex; } return(result); }
public List <Contact> getContacts(SearchContactDTO searchOptions = null) { DataTable dt = new DataTable(); List <SqlParameter> sqlParameters = new List <SqlParameter>(); string sqlSentence = ""; try { sqlSentence += "SELECT * FROM contacts "; sqlSentence += "WHERE contacts.memberId = @memberId "; if (searchOptions != null) { if (searchOptions.firstName != string.Empty) { sqlSentence += "AND contacts.firstName LIKE '%" + searchOptions.firstName + "%' "; } if (searchOptions.lastName != string.Empty) { sqlSentence += "AND contacts.lastName LIKE '%" + searchOptions.lastName + "%' "; } if (searchOptions.genre != string.Empty) { if (searchOptions.genre.ToUpper() == "F" || searchOptions.genre.ToUpper() == "M") { sqlSentence += "AND contacts.genre = @genre "; sqlParameters.Add(new SqlParameter("@genre", searchOptions.genre)); } } if (searchOptions.email != string.Empty) { sqlSentence += "AND contacts.email LIKE '%" + searchOptions.email + "%' "; } if (searchOptions.mobileNumber != string.Empty) { sqlSentence += "AND contacts.mobileNumber LIKE '%" + searchOptions.mobileNumber + "%' "; } if (searchOptions.landlineNumber != string.Empty) { sqlSentence += "AND contacts.landlineNumber LIKE '%" + searchOptions.landlineNumber + "%' "; } if (searchOptions.onlyActive && !searchOptions.onlyInactive) { sqlSentence += "AND contacts.isActive = @active "; sqlParameters.Add(new SqlParameter("@active", true)); } if (searchOptions.onlyInactive && !searchOptions.onlyActive) { sqlSentence += "AND contacts.isActive = @active "; sqlParameters.Add(new SqlParameter("@active", false)); } if (searchOptions.onlyWithPicture && !searchOptions.onlyWithoutPicture) { sqlSentence += "AND contacts.picExtension IS NOT NULL "; } if (searchOptions.onlyWithoutPicture && !searchOptions.onlyWithPicture) { sqlSentence += "AND contacts.picExtension IS NULL "; } if (searchOptions.comments != string.Empty) { sqlSentence += "AND contacts.comments LIKE '%" + searchOptions.comments + "%' "; } if (searchOptions.createdSince != null && searchOptions.createdUntil != null) { if (searchOptions.createdSince <= searchOptions.createdUntil) { sqlSentence += "AND (contacts.createdAt BETWEEN @dateSince AND @dateUntil) "; SqlParameter dateSince = new SqlParameter("@dateSince", searchOptions.createdSince); SqlParameter dateUntil = new SqlParameter("@dateUntil", searchOptions.createdUntil); dateSince.DbType = DbType.DateTime; dateUntil.DbType = DbType.DateTime; sqlParameters.Add(dateSince); sqlParameters.Add(dateUntil); } } } sqlSentence += "ORDER BY contacts.firstName, contacts.lastName "; sqlParameters.Add(new SqlParameter("@memberId", memberInfo.id)); dt = dbWrapper.FillDataTable(sqlSentence, sqlParameters); } catch (Exception ex) { throw ex; } return((List <Contact>)getConvertedDatatable(dt, typeof(List <Contact>))); }