protected void TicketCategoriesOrderList_UpdateCommand(object sender, ReorderListCommandEventArgs e) { TextBox tb = (TextBox)e.Item.FindControl("CategoryNameTextBox"); if (!string.IsNullOrEmpty(tb.Text.Trim())) { SettingChangeResult result = SettingsManager.RenameCategory(OrderedCategories[e.Item.ItemIndex], tb.Text); OrderedCategories = new List <string>(SettingsManager.CategoriesList); TicketCategoriesOrderList.EditItemIndex = -1; switch (result) { case SettingChangeResult.Merge: Message.Text = "Ticket category has been merged with an existing category."; break; case SettingChangeResult.Failure: Message.Text = "No changes saved."; break; default: //do nothing, change will be apparent from updated order list break; } } }
public static SettingChangeResult RenameTicketType(string oldTypeName, string newTypeName) { SettingChangeResult results = SettingChangeResult.Failure; string[] newSettings = RenameStringEmunSetting("TicketTypesList", oldTypeName, newTypeName, TicketTypesList, false, out results); SaveRenamedTicketTypes(newSettings, oldTypeName, newTypeName, false); db.SaveChanges(); ticketTypes = newSettings; return(results); }
public static SettingChangeResult RenameCategory(string oldCategoryName, string newCategoryName) { SettingChangeResult results = SettingChangeResult.Failure; string[] newSettings = RenameStringEmunSetting("CategoryList", oldCategoryName, newCategoryName, CategoriesList, false, out results); SaveRenamedCategory(newSettings, oldCategoryName, newCategoryName, false); db.SaveChanges(); categories = newSettings; return(results); }
public static SettingChangeResult RenamePriority(string oldPriorityName, string newPriorityName) { SettingChangeResult results = SettingChangeResult.Failure; string[] newSettings = RenameStringEmunSetting("PriorityList", oldPriorityName, newPriorityName, PrioritiesList, false, out results); SaveRenamedPriority(newSettings, oldPriorityName, newPriorityName, false); db.SaveChanges(); priorities = newSettings; return(results); }
public static SettingChangeResult RenameValue(string name, string oldValueName, string newValueName) { SettingChangeResult results = SettingChangeResult.Failure; string[] newSettings = RenameStringEmunSetting(name, oldValueName, newValueName, GetSettings(name), false, out results); //SaveRenamedValue(name, newSettings, oldValueName, newValueName, false); db.SaveChanges(); cache[name] = newSettings; return(results); }
internal static string[] RenameStringEmunSetting(string settingName, string oldSetting, string newSetting, string[] origionalSettings, bool commitChanges, out SettingChangeResult results) { string[] newSettings = null; results = SettingChangeResult.Failure; if (oldSetting != newSetting) { int newLen = origionalSettings.Length; bool deleteOldSetting = false; //if new setting is same as an existing setting in list, we have to remove the old setting rather than rename it if (origionalSettings.Contains(newSetting)) { deleteOldSetting = true; newLen--; } List <string> newSettingssList = new List <string>(newLen); for (int i = 0; i < origionalSettings.Length; i++) { if (origionalSettings[i] == oldSetting) { if (!deleteOldSetting) { newSettingssList.Add(newSetting); } } else { newSettingssList.Add(origionalSettings[i]); } } newSettings = newSettingssList.ToArray(); SaveStringEnumToDb(settingName, newSettings, false); results = (deleteOldSetting) ? SettingChangeResult.Merge : SettingChangeResult.Success; if (commitChanges) { db.SaveChanges(); } } return(newSettings); }
internal static string[] RenameStringEmunSetting(string settingName, string oldSetting, string newSetting, string[] origionalSettings, bool commitChanges, out SettingChangeResult results) { string[] newSettings = null; results = SettingChangeResult.Failure; if (oldSetting != newSetting) { int newLen = origionalSettings.Length; bool deleteOldSetting = false; //if new setting is same as an existing setting in list, we have to remove the old setting rather than rename it if (origionalSettings.Contains(newSetting)) { deleteOldSetting = true; newLen--; } List<string> newSettingssList = new List<string>(newLen); for (int i = 0; i < origionalSettings.Length; i++) { if (origionalSettings[i] == oldSetting) { if (!deleteOldSetting) { newSettingssList.Add(newSetting); } } else { newSettingssList.Add(origionalSettings[i]); } } newSettings = newSettingssList.ToArray(); SaveStringEnumToDb(settingName, newSettings, false); results = (deleteOldSetting) ? SettingChangeResult.Merge : SettingChangeResult.Success; if (commitChanges) { db.SaveChanges(); } } return newSettings; }