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); }
public TransactionResultDTO createMember(Member enMember) { TransactionResultDTO result = new TransactionResultDTO(); try { // The member email must be unique Member existingMember = membersDao.getMember(enMember.email); if (existingMember != null) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = resourceManager.GetString("ErrorEmailYaExiste", cultureInfo); return(result); } result = validateEntity(enMember); if (result.code == TransactionResultDTO.transactionResultCode.Success) { // Overwrite the member password with more secure one enMember.password = Encoding.sha512(enMember.email, enMember.password); membersDao.createMember(enMember); result.code = TransactionResultDTO.transactionResultCode.Success; } } catch (Exception ex) { throw ex; } return(result); }
public TransactionResultDTO login(string memberUser, string memberPassword) { TransactionResultDTO result = new TransactionResultDTO(); try { Member member; member = membersDao.getMember(memberUser, Encoding.sha512(memberUser, memberPassword)); if (member != null) { result.code = TransactionResultDTO.transactionResultCode.Success; result.object1 = member; } else { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = resourceManager.GetString("ErrorUsuarioContrasenaIncorrectos", cultureInfo); } } catch (Exception ex) { throw ex; } return(result); }
public TransactionResultDTO createContact(Contact enContact) { TransactionResultDTO result = new TransactionResultDTO(); try { result = validateContactEntity(enContact); if (result.code == TransactionResultDTO.transactionResultCode.Success) { int createdContactId = contactsDAO.createContact(enContact); result.code = TransactionResultDTO.transactionResultCode.Success; result.affectedId = createdContactId; } } catch (Exception ex) { throw ex; } return(result); }
public TransactionResultDTO editContact(Contact enContact, bool deleteContactPic = false) { TransactionResultDTO result = new TransactionResultDTO(); try { result = validateContactEntity(enContact); if (result.code == TransactionResultDTO.transactionResultCode.Success) { if (deleteContactPic) { deleteContacPics(enContact.id); contactsDAO.editContactPicExtension(enContact.id, string.Empty); } contactsDAO.editContact(enContact); // Only if the new contact info contains pic extension data, we will update it // because the 'editContact' method does not update that field. if (enContact.picExtension != string.Empty) { // Look for existing pics for the contact and delete them. This because the user may // be updating the contact pic with a new one with different extension. deleteContacPics(enContact.id); contactsDAO.editContactPicExtension(enContact.id, enContact.picExtension); } result.code = TransactionResultDTO.transactionResultCode.Success; } } catch (Exception ex) { throw ex; } return(result); }
public TransactionResultDTO updatePasswordPreferences(PasswordPreferencesDTO passwordPreferences) { TransactionResultDTO result = new TransactionResultDTO(); try { MembersDAO membersDAO = new MembersDAO(); Member enMember = membersDAO.getMember(memberInfo.id); string savedPassword = enMember.password; string newPassword = Encoding.sha512(enMember.email, passwordPreferences.actualPassword); // If the saved password is the same than the 'actualPassword' sent, continue update if (savedPassword == newPassword) { PreferencesDAO preferencesDAO = new PreferencesDAO(memberInfo); // Overwrite the member new password with more secure one passwordPreferences.newPassword = Encoding.sha512(enMember.email, passwordPreferences.newPassword); preferencesDAO.updatePasswordPreferences(passwordPreferences); result.code = TransactionResultDTO.transactionResultCode.Success; } else { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = "ErrorContrasenaActualIncorrecta"; return(result); } } catch (Exception ex) { throw ex; } return(result); }
private TransactionResultDTO validateContactEntity(Contact entityToValidate) { TransactionResultDTO result = new TransactionResultDTO(); try { string lengthError = resourceManager.GetString("ErrorLongitudSuperada", cultureInfo); string formatError = resourceManager.GetString("ErrorFormatoIncorrecto", cultureInfo); // Validate first name required if (entityToValidate.firstName == string.Empty) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = resourceManager.GetString("ErrorNombreReq", cultureInfo); return(result); } // 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 required if (entityToValidate.lastName == string.Empty) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = resourceManager.GetString("ErrorApellidosReq", cultureInfo); 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 required if (entityToValidate.genre == string.Empty) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = resourceManager.GetString("ErrorGenreReq", cultureInfo); return(result); } // Validate genre format 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); } result.code = TransactionResultDTO.transactionResultCode.Success; } catch (Exception ex) { 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); }
private TransactionResultDTO validateEntity(Member entityToValidate) { TransactionResultDTO result = new TransactionResultDTO(); try { string lengthError = resourceManager.GetString("ErrorLongitudSuperada", cultureInfo); string formatError = resourceManager.GetString("ErrorFormatoIncorrecto", cultureInfo); // Validate real name required if (entityToValidate.realName == string.Empty) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = resourceManager.GetString("ErrorNombreCompletoReq", cultureInfo); return(result); } // Validate real name length if (entityToValidate.realName.Length > REALNAME_LENGTH) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = String.Format(lengthError, resourceManager.GetString("NombreCompleto", cultureInfo), REALNAME_LENGTH); return(result); } // Validate display name required if (entityToValidate.displayName == string.Empty) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = resourceManager.GetString("ErrorNombreVisibleReq", cultureInfo); return(result); } // Validate display name length if (entityToValidate.displayName.Length > DISPLAYNAME_LENGTH) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = String.Format(lengthError, resourceManager.GetString("NombreVisible", cultureInfo), DISPLAYNAME_LENGTH); return(result); } // Validate email required if (entityToValidate.email == string.Empty) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = resourceManager.GetString("ErrorEmailReq", cultureInfo); return(result); } // Validate email format 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 password required if (entityToValidate.password == string.Empty) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = resourceManager.GetString("ErrorContrasenaReq", cultureInfo); return(result); } // Validate password length if (entityToValidate.password.Length > PASSWORD_LENGTH) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = String.Format(lengthError, resourceManager.GetString("Contrasena", cultureInfo), PASSWORD_LENGTH); return(result); } // Validate lang required if (entityToValidate.language == string.Empty) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = resourceManager.GetString("ErrorIdiomaReq", cultureInfo); return(result); } // Validate landline number length if (entityToValidate.language.Length > LANG_LENGTH) { result.code = TransactionResultDTO.transactionResultCode.Failed; result.failureReason = String.Format(lengthError, resourceManager.GetString("Idioma", cultureInfo), LANG_LENGTH); return(result); } result.code = TransactionResultDTO.transactionResultCode.Success; } catch (Exception ex) { throw ex; } return(result); }