}//END addCustomerGroup method // ================================================================================== /// <summary> /// THis method genrates and send a user notification email. Send to new users and /// when a user's password is updated by the administrator. /// </summary> // ---------------------------------------------------------------------------------- public EvEmail.EmailStatus sendUserNotificationEmail ( EvStaticContentTemplates.NotiificationTypes Notification ) { this.LogMethod ( "sendUserNotificationEmail" ); this.LogDebug ( "Notification: " + Notification ); this.LogDebug ( "ApplicationParameters.ApplicationUrl: " + this.AdapterObjects.ApplicationUrl ); this.LogDebug ( "SupportEmailAddress: " + this.AdapterObjects.SupportEmailAddress ); this.LogDebug ( "AdminUserProfile.UserId: " + this.Session.AdminUserProfile.UserId ); this.LogDebug ( "AdminUserProfile.Password: "******"AdminUserProfile.EmailAddress: " + this.Session.AdminUserProfile.EmailAddress ); // // Initialise the update variables. // string EmailTitle = String.Empty; string EmailBody = String.Empty; EvEmail email = new EvEmail ( ); EvEmail.EmailStatus emailStatus = EvEmail.EmailStatus.Null; // // Validate that the necessary parametes exist. // if ( this.AdapterObjects.ApplicationUrl == String.Empty || this.Session.AdminUserProfile.EmailAddress == String.Empty || this.AdapterObjects.SupportEmailAddress == String.Empty ) { this.LogValue ( "Parameters Missing" ); this.LogMethodEnd ( "sendUserNotificationEmail" ); return EvEmail.EmailStatus.Parameters_Missing_Error; } switch ( Notification ) { case EvStaticContentTemplates.NotiificationTypes.Update_Password_Email: { EmailTitle = this.AdapterObjects.ContentTemplates.UpdatePasswordEmail_Title; EmailBody = this.AdapterObjects.ContentTemplates.UpdatePasswordEmail_Body; break; } case EvStaticContentTemplates.NotiificationTypes.Reset_Password_Email: { EmailTitle = this.AdapterObjects.ContentTemplates.ResetPasswordEmail_Title; EmailBody = this.AdapterObjects.ContentTemplates.ResetPasswordEmail_Body; break; } case EvStaticContentTemplates.NotiificationTypes.Password_Change_Email: { EmailTitle = this.AdapterObjects.ContentTemplates.PasswordConfirmationEmail_Title; EmailBody = this.AdapterObjects.ContentTemplates.PasswordConfirmationEmail_Body; break; } case EvStaticContentTemplates.NotiificationTypes.Introductory_Email: default: { EmailTitle = this.AdapterObjects.ContentTemplates.IntroductoryEmail_Title; EmailBody = this.AdapterObjects.ContentTemplates.IntroductoryEmail_Body; break; } }//End switch statementf EmailTitle = EmailTitle.Replace ( "\r\n\r\n", "\r\n \r\n" ); EmailTitle = EmailTitle.Replace ( EvcStatics.TEXT_SUBSITUTION_FIRST_NAME, this.Session.AdminUserProfile.GivenName ); EmailTitle = EmailTitle.Replace ( EvcStatics.TEXT_SUBSITUTION_FAMILY_NAME, this.Session.AdminUserProfile.FamilyName ); EmailTitle = EmailTitle.Replace ( EvcStatics.TEXT_SUBSITUTION_ADAPTER_TITLE, this.AdapterObjects.Settings.Title ); EmailBody = EmailBody.Replace ( "\r\n\r\n", "\r\n \r\n" ); EmailBody = EmailBody.Replace ( EvcStatics.TEXT_SUBSITUTION_FIRST_NAME, this.Session.AdminUserProfile.GivenName ); EmailBody = EmailBody.Replace ( EvcStatics.TEXT_SUBSITUTION_FAMILY_NAME, this.Session.AdminUserProfile.FamilyName ); EmailBody = EmailBody.Replace ( EvcStatics.TEXT_SUBSITUTION_EMAIL_ADDRESS, this.Session.AdminUserProfile.EmailAddress ); EmailBody = EmailBody.Replace ( EvcStatics.TEXT_SUBSITUTION_USER_ID, this.Session.AdminUserProfile.UserId ); EmailBody = EmailBody.Replace ( EvcStatics.TEXT_SUBSITUTION_PASSWORD, this.Session.AdminUserProfile.Password ); EmailBody = EmailBody.Replace ( EvcStatics.TEXT_SUBSITUTION_ORG_ID, this.Session.SelectedUserType.ToString() ); EmailBody = EmailBody.Replace ( EvcStatics.TEXT_SUBSITUTION_ORG_NAME, this.Session.AdminUserProfile.OrganisationName ); EmailBody = EmailBody.Replace ( EvcStatics.TEXT_SUBSITUTION_ADAPTER_TITLE, this.AdapterObjects.Settings.Title ); EmailBody = EmailBody.Replace ( EvcStatics.TEXT_SUBSITUTION_PASSWORD_RESET_URL, this.AdapterObjects.PasswordResetUrl ); EmailBody = EmailBody.Replace ( EvcStatics.TEXT_SUBSITUTION_DATE_STAMP, DateTime.Now.ToLongDateString ( ) + " at " + DateTime.Now.ToShortTimeString ( ) ); this.LogValue ( "EmailTitle: " + EmailTitle ); // // Define the markdown options. // MarkdownSharp.MarkdownOptions markDownOptions = new MarkdownSharp.MarkdownOptions ( ); markDownOptions.AutoHyperlink = true; markDownOptions.AutoNewlines = true; markDownOptions.EmptyElementSuffix = "/>"; markDownOptions.EncodeProblemUrlCharacters = true; markDownOptions.LinkEmails = true; markDownOptions.StrictBoldItalic = true; // // Initialise the markdown class // MarkdownSharp.Markdown markDown = new MarkdownSharp.Markdown ( markDownOptions ); // // perform the html body transformation. // EmailBody = markDown.Transform ( EmailBody ); // // Initialise the report alert class // email.SmtpServer = this.AdapterObjects.Settings.SmtpServer; email.SmtpServerPort = this.AdapterObjects.Settings.SmtpServerPort; email.SmtpUserId = this.AdapterObjects.Settings.SmtpUserId; email.SmtpPassword = this.AdapterObjects.Settings.SmtpPassword; // // Set the email alert to the recipents // emailStatus = email.sendEmail ( EmailTitle, EmailBody, this.AdapterObjects.SupportEmailAddress, this.Session.AdminUserProfile.EmailAddress, String.Empty ); this.LogValue ( "Email DebugLog: " + email.Log ); // // Log email send error. // if ( emailStatus != EvEmail.EmailStatus.Email_Sent ) { this.LogError ( EvEventCodes.Database_Record_Update_Error, "User Notificatin Email Event Status: " + emailStatus + "\r\n" + email.Log ); this.LogClass ( email.Log ); } this.LogMethodEnd ( "sendUserNotificationEmail" ); return emailStatus; }//END sendUserNotificationEmail method
// ================================================================================== /// <summary> /// THis method saves the ResultData object updating the field values contained in the /// parameter list. /// </summary> /// <returns>Application Data object</returns> // ---------------------------------------------------------------------------------- private EvEventCodes saveUserProfile ( ) { this.LogMethod ( "saveUserProfile" ); try { // // Initialise the methods variables and objects. // EvEventCodes result = EvEventCodes.Ok; bool isANewUser = false; // // Reset the Guid if a new user is beeing created. // if ( this.Session.AdminUserProfile.Guid == EvStatics.CONST_NEW_OBJECT_ID ) { this.Session.AdminUserProfile.Guid = Guid.Empty; if ( string.IsNullOrEmpty ( this.Session.AdminUserProfile.Password ) == true ) { this.createDefaultPassword ( ); } isANewUser = true; } // // update the object. // result = this._Bll_UserProfiles.saveItem ( this.Session.AdminUserProfile ); // // get the debug ResultData. // this.LogDebugClass ( this._Bll_UserProfiles.Log ); // // if an error state is returned create log the event. // if ( result != EvEventCodes.Ok ) { string StEvent = this._Bll_UserProfiles.Log + " returned error message: " + Evado.Digital.Model.EvcStatics.getEventMessage ( result ); this.LogError ( EvEventCodes.Database_Record_Update_Error, StEvent ); this.ErrorMessage = EdLabels.User_Profile_Save_Error_Message; this.LogMethodEnd ( "saveUserProfile" ); return result; } // // Update the ADS details. // result = this.updateAdUserProfile ( ); // // if an error state is returned create log the event. // if ( result != EvEventCodes.Ok ) { this.ErrorMessage = EdLabels.UserProfile_AD_Error_Message; string stEvent = " returned error message: " + Evado.Digital.Model.EvcStatics.getEventMessage ( result ); this.LogError ( EvEventCodes.Database_Record_Update_Error, stEvent ); this.LogMethodEnd ( "saveUserProfile" ); return result; } // // if the password is empty not notification email needs to be sent to the user // if ( this.Session.AdminUserProfile.Password == String.Empty ) { this.LogDebug ( "Password Empty" ); this.LogMethodEnd ( "saveUserProfile" ); return EvEventCodes.Ok; } if ( this.AdapterObjects.Settings.AdsGroupName == null || this.Session.AdsCustomerGroup.Name == null || this.Session.AdsEnabled == false ) { this.LogDebug ( "ADS not enabled so Email notificaton not needed." ); this.LogMethodEnd ( "saveUserProfile" ); return EvEventCodes.Ok; } // // Set the email notification. // EvEmail.EmailStatus emStatus = EvEmail.EmailStatus.Ok; if ( isANewUser == true ) { this.LogDebug ( "Sending Introductory Email" ); emStatus = this.sendUserNotificationEmail ( EvStaticContentTemplates.NotiificationTypes.Introductory_Email ); } else { this.LogDebug ( "Sending Password update Email" ); emStatus = this.sendUserNotificationEmail ( EvStaticContentTemplates.NotiificationTypes.Update_Password_Email ); } // // if an error state is returned create log the event. // if ( emStatus != EvEmail.EmailStatus.Email_Sent && emStatus != EvEmail.EmailStatus.Ok ) { switch ( emStatus ) { case EvEmail.EmailStatus.No_Reciever_Addresses: { this.ErrorMessage = EdLabels.EmailNotification_Receive_Address_Error_Message; break; } case EvEmail.EmailStatus.No_SMTP_Url: { this.ErrorMessage = EdLabels.EmailNotification_Configurtion_Error_Message; break; } case EvEmail.EmailStatus.Email_Send_Request_Failed: default: { this.ErrorMessage = EdLabels.EmailNotification_Send_Failure_Error_Message; break; } } string stEvent = "Email notitification error: " + emStatus; this.LogError ( EvEventCodes.Business_Logic_Email_Failure_Error, stEvent ); this.LogMethodEnd ( "saveUserProfile" ); return EvEventCodes.Business_Logic_Email_Failure_Error; }//END email erorr handling. this.LogMethodEnd ( "saveUserProfile" ); return EvEventCodes.Ok; } catch ( Exception Ex ) { // // Create the error message to be displayed to the user. // this.ErrorMessage = EdLabels.User_Profile_Save_Error_Message; // // Generate the log the error event. // this.LogException ( Ex ); } this.LogMethodEnd ( "saveUserProfile" ); return EvEventCodes.Database_Record_Update_Error; }//END saveUserProfile method