protected void btnOk_Click(object sender, EventArgs e) { if (copyProfileParameter.SelectedUserId.Trim().Length == 0) { copyProfileParameter.IsValid = false; return; } CopyProfileToSelectedUsers(); LinkHandler linkHandler = new LinkHandler(Page); linkHandler.RedirectToNewGroupDetail(_selUsers); this.OnClosing(); }
protected void btnOk_Click(object sender, EventArgs e) { if (copyProfileParameter.SelectedUserId.Trim().Length == 0) { copyProfileParameter.IsValid = false; return; } CopyProfileToSelectedUsers(); LinkHandler linkHandler = new LinkHandler(Page); linkHandler.RedirectToNewGroupDetail(_selUsers); this.OnClosing(); }
private void CopySelectedUsers(IList<string> targetUserIds) { var ums = ApplicationContext.Current.Services.Get<IUserManagementService>(); IList<IUser> newUserList = new List<IUser>(); var userManagementSvc = ApplicationContext.Current.Services.Get<IUserManagementService>(); try { foreach (string id in targetUserIds) { IUser existingUser = EntityFactory.GetById<IUser>(id); if (existingUser != null && existingUser.UserInfo != null) { if (existingUser.Type == UserType.Retired) throw new ApplicationException(GetLocalResourceObject("ErrorCannotCopyRetiredUser").ToString()); AddUserOptions options = SetAddUserOptions(existingUser); // create the new user with default data IUser newUser = ums.AddUser("", options); // sometimes the copy of... name is too long for the data type string nameFormat = " {0}, {1}"; if (string.IsNullOrEmpty(existingUser.UserInfo.FirstName)) nameFormat = " {0}{1}"; string fullNameFormat = string.Concat("<", GetLocalResourceObject("CopyOfNameTemplate").ToString(), nameFormat, ">"); string newName = string.Format(fullNameFormat, existingUser.UserInfo.LastName, existingUser.UserInfo.FirstName); /* the following could be used to improve the user experience, but it doesn't match the lan product */ //string copyOfTemplate = GetLocalResourceObject("CopyOfNameTemplate").ToString(); //string fullNameFormat = string.Concat("<", copyOfTemplate, nameFormat, ">"); //string newLastName = existingUser.UserInfo.LastName; //if (newLastName.Contains(string.Concat("<", copyOfTemplate))) //{ // Match match = Regex.Match(newLastName, string.Concat("<", copyOfTemplate, "(.*)", ">"), RegexOptions.IgnoreCase); // if (match.Groups.Count > 0) // newLastName = match.Groups[1].Value; //} //string newName = string.Format(fullNameFormat, newLastName, existingUser.UserInfo.FirstName); newUser.UserInfo.LastName = newName.Length > 32 ? newName.Substring(0, 32) : newName; newUser.UserInfo.UserName = newName.Length > 64 ? newName.Substring(0, 64) : newName; string userTemplate = existingUser.UserInfo.UserName; newUser.UserTemplate = userTemplate.Length > 30 ? userTemplate.Substring(0, 30) : userTemplate; newUser.Save(); if (newUser != null) newUserList.Add(newUser); } if (newUserList.Count > 0) { LinkHandler linkHandler = new LinkHandler(Page); linkHandler.RedirectToNewGroupDetail(newUserList); } } } catch (Exception exp) { // need this to replace the dialog for copy user. StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0} ", exp.Message); while (exp.InnerException != null) { sb.AppendFormat("{0} ", exp.InnerException.Message); exp = exp.InnerException; } DialogService.ShowMessage(sb.ToString(), GetLocalResourceObject("ErrorMessageTitle").ToString()); } }
private void CopySelectedUsers(IList <string> targetUserIds) { var ums = ApplicationContext.Current.Services.Get <IUserManagementService>(); IList <IUser> newUserList = new List <IUser>(); var userManagementSvc = ApplicationContext.Current.Services.Get <IUserManagementService>(); try { foreach (string id in targetUserIds) { IUser existingUser = EntityFactory.GetById <IUser>(id); if (existingUser != null && existingUser.UserInfo != null) { if (existingUser.Type == UserType.Retired) { throw new Sage.Platform.Application.ValidationException(GetLocalResourceObject("ErrorCannotCopyRetiredUser").ToString()); } AddUserOptions options = SetAddUserOptions(existingUser); // create the new user with default data IUser newUser = ums.AddUser("", options); // sometimes the copy of... name is too long for the data type string nameFormat = " {0}, {1}"; if (string.IsNullOrEmpty(existingUser.UserInfo.FirstName)) { nameFormat = " {0}{1}"; } string fullNameFormat = string.Concat("(", GetLocalResourceObject("CopyOfNameTemplate").ToString(), nameFormat, ")"); string newName = string.Format(fullNameFormat, existingUser.UserInfo.LastName, existingUser.UserInfo.FirstName); /* the following could be used to improve the user experience, but it doesn't match the lan product */ //string copyOfTemplate = GetLocalResourceObject("CopyOfNameTemplate").ToString(); //string fullNameFormat = string.Concat("<", copyOfTemplate, nameFormat, ">"); //string newLastName = existingUser.UserInfo.LastName; //if (newLastName.Contains(string.Concat("<", copyOfTemplate))) //{ // Match match = Regex.Match(newLastName, string.Concat("<", copyOfTemplate, "(.*)", ">"), RegexOptions.IgnoreCase); // if (match.Groups.Count > 0) // newLastName = match.Groups[1].Value; //} //string newName = string.Format(fullNameFormat, newLastName, existingUser.UserInfo.FirstName); newUser.UserInfo.LastName = newName.Length > 32 ? newName.Substring(0, 32) : newName; newUser.UserInfo.UserName = newName.Length > 64 ? newName.Substring(0, 64) : newName; string userTemplate = existingUser.UserInfo.UserName; newUser.UserTemplate = userTemplate.Length > 30 ? userTemplate.Substring(0, 30) : userTemplate; newUser.Save(); if (newUser != null) { newUserList.Add(newUser); } } if (newUserList.Count > 0) { LinkHandler linkHandler = new LinkHandler(Page); linkHandler.RedirectToNewGroupDetail(newUserList); } } } catch (ValidationException) { throw; } catch (Exception exp) { string sSlxErrorId = null; var sMsg = ErrorHelper.GetClientErrorHtmlMessage(exp, ref sSlxErrorId); if (!string.IsNullOrEmpty(sSlxErrorId)) { log.Error(ErrorHelper.AppendSlxErrorId("The call to CopySelectedUsers() failed", sSlxErrorId), exp); } DialogService.ShowHtmlMessage(sMsg, GetLocalResourceObject("ErrorMessageTitle").ToString(), ErrorHelper.IsDevelopmentContext() ? 600 : -1, ErrorHelper.IsDevelopmentContext() ? 800 : -1); } }
private void CopySelectedUsers(IList<string> targetUserIds) { var ums = ApplicationContext.Current.Services.Get<IUserManagementService>(); IList<IUser> newUserList = new List<IUser>(); var userManagementSvc = ApplicationContext.Current.Services.Get<IUserManagementService>(); try { foreach (string id in targetUserIds) { IUser existingUser = EntityFactory.GetById<IUser>(id); if (existingUser != null && existingUser.UserInfo != null) { if (existingUser.Type == UserType.Retired) throw new Sage.Platform.Application.ValidationException(GetLocalResourceObject("ErrorCannotCopyRetiredUser").ToString()); AddUserOptions options = SetAddUserOptions(existingUser); // create the new user with default data IUser newUser = ums.AddUser("", options); // sometimes the copy of... name is too long for the data type string nameFormat = " {0}, {1}"; if (string.IsNullOrEmpty(existingUser.UserInfo.FirstName)) nameFormat = " {0}{1}"; string fullNameFormat = string.Concat("(", GetLocalResourceObject("CopyOfNameTemplate").ToString(), nameFormat, ")"); string newName = string.Format(fullNameFormat, existingUser.UserInfo.LastName, existingUser.UserInfo.FirstName); /* the following could be used to improve the user experience, but it doesn't match the lan product */ //string copyOfTemplate = GetLocalResourceObject("CopyOfNameTemplate").ToString(); //string fullNameFormat = string.Concat("<", copyOfTemplate, nameFormat, ">"); //string newLastName = existingUser.UserInfo.LastName; //if (newLastName.Contains(string.Concat("<", copyOfTemplate))) //{ // Match match = Regex.Match(newLastName, string.Concat("<", copyOfTemplate, "(.*)", ">"), RegexOptions.IgnoreCase); // if (match.Groups.Count > 0) // newLastName = match.Groups[1].Value; //} //string newName = string.Format(fullNameFormat, newLastName, existingUser.UserInfo.FirstName); newUser.UserInfo.LastName = newName.Length > 32 ? newName.Substring(0, 32) : newName; newUser.UserInfo.UserName = newName.Length > 64 ? newName.Substring(0, 64) : newName; string userTemplate = existingUser.UserInfo.UserName; newUser.UserTemplate = userTemplate.Length > 30 ? userTemplate.Substring(0, 30) : userTemplate; newUser.Save(); if (newUser != null) newUserList.Add(newUser); } if (newUserList.Count > 0) { LinkHandler linkHandler = new LinkHandler(Page); linkHandler.RedirectToNewGroupDetail(newUserList); } } } catch (ValidationException) { throw; } catch (Exception exp) { string sSlxErrorId = null; var sMsg = ErrorHelper.GetClientErrorHtmlMessage(exp, ref sSlxErrorId); if (!string.IsNullOrEmpty(sSlxErrorId)) { log.Error(ErrorHelper.AppendSlxErrorId("The call to CopySelectedUsers() failed", sSlxErrorId), exp); } DialogService.ShowHtmlMessage(sMsg, GetLocalResourceObject("ErrorMessageTitle").ToString(), ErrorHelper.IsDevelopmentContext() ? 600 : -1, ErrorHelper.IsDevelopmentContext() ? 800 : -1); } }