public AHP.Core.Model.GenericResponse <bool> CreateUserAccount(AHP.Core.DTO.ExternalUserInfo userInfo) { AHP.Core.Model.GenericResponse <bool> response = new Core.Model.GenericResponse <bool>(); try { if (userInfo == null) { response.Success = false; response.Data = false; response.Errors.Add("User information provided is empty"); return(response); } response = _userInfoManager.CreateUser(userInfo); //send welcome email to admin if (response.Success && response.Data) { string[] toEmail = System.Configuration.ConfigurationManager.AppSettings["WelcomeEmailTo"].Split(','); //send user details email. To User _logMessages.AppendFormat("Sending email to admin {0} with user details.", string.Join(";", toEmail)); string fromEmail = System.Configuration.ConfigurationManager.AppSettings["EmailFROM"]; _logMessages.AppendFormat("Welcome email will be sent from {0}.", fromEmail); string subject = System.Configuration.ConfigurationManager.AppSettings["NewUserSubject"]; _logMessages.AppendFormat("Subject of the email is {0}.", subject); string welcomeEmailBody = System.IO.File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/EmailTemplates/NewUserEmail.html")); welcomeEmailBody = welcomeEmailBody.Replace("{Firstname}", userInfo.Firstname); welcomeEmailBody = welcomeEmailBody.Replace("{Lastname}", userInfo.Lastname); welcomeEmailBody = welcomeEmailBody.Replace("{Email}", userInfo.Email); welcomeEmailBody = welcomeEmailBody.Replace("{Username}", userInfo.Username); welcomeEmailBody = welcomeEmailBody.Replace("{SupplierId}", userInfo.SupplierId); welcomeEmailBody = welcomeEmailBody.Replace("{Role}", userInfo.Role); welcomeEmailBody = welcomeEmailBody.Replace("{Company}", userInfo.Company); //welcomeEmailBody = welcomeEmailBody.Replace("{Birthyear}", userInfo.BirthYear.ToString()); //welcomeEmailBody = welcomeEmailBody.Replace("{Birthmonth}", userInfo.BirthMonth.ToString()); //welcomeEmailBody = welcomeEmailBody.Replace("{Zipcode}", userInfo.ZipCode); if (_emailDeliveryService.SendEmail(fromEmail, toEmail, new string[] { }, subject, welcomeEmailBody)) { response.Success = true; response.Data = true; } else { response.Success = false; response.Data = false; response.Errors.Add("User successfully created. Failed to send email to admin with user information."); } } } catch (Exception ex) { _logger.Error("Error occurred creating new user account. Error info - ", ex); response.Success = false; response.Errors.Add("Error occurred creating new user account. Please try again."); } return(response); }
public AHP.Core.Model.GenericResponse <bool> ActivateEmail(string username, string email) { AHP.Core.Model.GenericResponse <bool> apiResponse = new Core.Model.GenericResponse <bool>(); AHP.Core.Model.GenericResponse <bool> dbResponse = new Core.Model.GenericResponse <bool>(); try { if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(email)) { //send welcome email. If successfully emailed then we will activate their email address on File _logMessages.AppendFormat("Setting up email for user with username {0} whose has email {1}.", username, email); string fromEmail = System.Configuration.ConfigurationManager.AppSettings["EmailFROM"]; _logMessages.AppendFormat("Welcome email will be sent from {0}.", fromEmail); string subject = System.Configuration.ConfigurationManager.AppSettings["WelcomeSubject"]; _logMessages.AppendFormat("Subject of the email is {0}.", subject); string portalUrl = System.Configuration.ConfigurationManager.AppSettings["LogonUrl"]; _logMessages.AppendFormat("Logon url for the user is {0}.", portalUrl); string welcomeEmailBody = System.IO.File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/EmailTemplates/WelcomeEmail.html")); welcomeEmailBody = welcomeEmailBody.Replace("{ServerUrl}", portalUrl); welcomeEmailBody = welcomeEmailBody.Replace("{Username}", username); welcomeEmailBody = welcomeEmailBody.Replace("{CopyrightYear}", DateTime.Today.Year.ToString()); if (_emailDeliveryService.SendEmail(fromEmail, new[] { email }, new string[] { }, subject, welcomeEmailBody)) { apiResponse.Success = true; _logMessages.AppendFormat("Welcome email has been sent successfully to user {0} with email {1}.", username, email); dbResponse = _userInfoManager.ActivateEmail(username, email, true); } else { apiResponse.Success = false; apiResponse.Errors.Add("Failed to deliver welcome email. Please correct and try again."); _logMessages.AppendFormat("Error occurred sending email to user {0} with email {1}.", username, email); dbResponse = _userInfoManager.ActivateEmail(username, email, false); } //operation succeeded only if email and db operation succeeded apiResponse.Success = apiResponse.Success && dbResponse.Success; apiResponse.Errors = dbResponse.Errors; apiResponse.Data = dbResponse.Data; } else { apiResponse.Success = false; apiResponse.Data = false; apiResponse.Errors.Add("Please provide username and email to activate user account"); } } catch (Exception ex) { _logger.Error("Error occurred activating user account. Error info - ", ex); apiResponse.Success = false; apiResponse.Errors.Add("Error occurred activating user account. Please try again."); } return(apiResponse); }
public AHP.Core.Model.GenericResponse <AHP.Core.DTO.ExternalUserInfo> UpdateUserAccount(AHP.Core.DTO.ExternalUserInfo userInfo) { AHP.Core.Model.GenericResponse <AHP.Core.DTO.ExternalUserInfo> response = new Core.Model.GenericResponse <AHP.Core.DTO.ExternalUserInfo>(); try { if (userInfo == null) { response.Success = false; response.Errors.Add("User information provided is empty"); return(response); } response = _userInfoManager.UpdateUser(userInfo); } catch (Exception ex) { _logger.Error("Error occurred creating new user account. Error info - ", ex); response.Success = false; response.Errors.Add("Error occurred creating new user account. Please try again."); } return(response); }
public GenericResponse <bool> UpdateInternalUserInfo(Core.DTO.InternalUserInfo userInfo) { AHP.Core.Model.GenericResponse <bool> response = new Core.Model.GenericResponse <bool>(); try { if (userInfo == null) { response.Success = false; response.Data = false; response.Errors.Add("User information provided is empty"); return(response); } response = _userInfoManager.UpdateInternalUser(userInfo); } catch (Exception ex) { _logger.Error("Error occurred creating new user account. Error info - ", ex); response.Success = false; response.Errors.Add("Could not process your request"); } return(response); }
public AHP.Core.Model.GenericResponse <bool> LockUserAccount(string username, string email) { AHP.Core.Model.GenericResponse <bool> response = new Core.Model.GenericResponse <bool>(); try { if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(email)) { response.Success = false; response.Data = false; response.Errors.Add("Please provide username and email to deactivate user account"); return(response); } response = _userInfoManager.LockUserAccount(username, email); } catch (Exception ex) { _logger.Error("Error occurred locking user account. Error info - ", ex); response.Success = false; response.Errors.Add("Error occurred locking user account. Please try again."); } return(response); }