/// <summary> Constructor for a new instance of the Thematic_Headings_AdminViewer class </summary> /// <param name="User"> Authenticated user information </param> /// <param name="Current_Mode"> Mode / navigation information for the current request </param> /// <param name="Thematic_Headings"> Headings under which all the highlighted collections on the home page are organized </param> /// <param name="Tracer">Trace object keeps a list of each method executed and important milestones in rendering</param> /// <remarks> Postback from handling an edit or new thematic heading is handled here in the constructor </remarks> public Thematic_Headings_AdminViewer(User_Object User, SobekCM_Navigation_Object Current_Mode, List <Thematic_Heading> Thematic_Headings, Custom_Tracer Tracer) : base(User) { Tracer.Add_Trace("Thematic_Headings_AdminViewer.Constructor", String.Empty); // Get the current list of thematic headings thematicHeadings = Thematic_Headings; // Save the mode currentMode = Current_Mode; // Set action message to nothing to start actionMessage = String.Empty; // If the user cannot edit this, go back if ((!user.Is_System_Admin) && (!user.Is_Portal_Admin)) { currentMode.My_Sobek_Type = My_Sobek_Type_Enum.Home; HttpContext.Current.Response.Redirect(currentMode.Redirect_URL()); } // Handle any post backs if (currentMode.isPostBack) { try { // Pull the standard values from the form NameValueCollection form = HttpContext.Current.Request.Form; string save_value = form["admin_heading_tosave"]; string action_value = form["admin_heading_action"]; // Switch, depending on the request if (action_value != null) { switch (action_value.Trim().ToLower()) { case "edit": string new_name = form["form_heading_name"]; if (new_name != null) { int id = Convert.ToInt32(save_value); int order = 1 + Thematic_Headings.TakeWhile(thisHeading => thisHeading.ThematicHeadingID != id).Count(); if (SobekCM_Database.Edit_Thematic_Heading(id, order, new_name, Tracer) < 1) { actionMessage = "Unable to edit existing thematic heading"; } else { // For thread safety, lock the thematic headings list lock (Thematic_Headings) { // Repopulate the thematic headings list SobekCM_Database.Populate_Thematic_Headings(Thematic_Headings, Tracer); } actionMessage = "Thematic heading edits saved"; } } break; case "delete": int thematicDeleteId = Convert.ToInt32(save_value); if (!SobekCM_Database.Delete_Thematic_Heading(thematicDeleteId, Tracer)) { // Set action message actionMessage = "Unable to delete existing thematic heading"; } else { // For thread safety, lock the thematic headings list lock (Thematic_Headings) { // Remove this thematic heading from the list int i = 0; while (i < Thematic_Headings.Count) { if (Thematic_Headings[i].ThematicHeadingID == thematicDeleteId) { Thematic_Headings.RemoveAt(i); } else { i++; } } } // Set action message actionMessage = "Thematic heading deleted"; } break; case "new": int new_order = Thematic_Headings.Count + 1; if (SobekCM_Database.Edit_Thematic_Heading(-1, new_order, save_value, Tracer) < 1) { actionMessage = "Unable to save new thematic heading"; } else { // For thread safety, lock the thematic headings list lock (Thematic_Headings) { // Repopulate the thematic headings list SobekCM_Database.Populate_Thematic_Headings(Thematic_Headings, Tracer); } actionMessage = "New thematic heading saved"; } break; case "moveup": string[] moveup_split = save_value.Split(",".ToCharArray()); int moveup_id = Convert.ToInt32(moveup_split[0]); int moveup_order = Convert.ToInt32(moveup_split[1]); if (moveup_order > 1) { Thematic_Heading themeHeading = Thematic_Headings[moveup_order - 1]; if (themeHeading.ThematicHeadingID == moveup_id) { // For thread safety, lock the thematic headings list lock (Thematic_Headings) { // Move this thematic heading up Thematic_Headings.Remove(themeHeading); Thematic_Headings.Insert(moveup_order - 2, themeHeading); int current_order = 1; foreach (Thematic_Heading thisTheme in Thematic_Headings) { SobekCM_Database.Edit_Thematic_Heading(thisTheme.ThematicHeadingID, current_order, thisTheme.ThemeName, Tracer); current_order++; } // Repopulate the thematic headings list SobekCM_Database.Populate_Thematic_Headings(Thematic_Headings, Tracer); } } } break; case "movedown": string[] movedown_split = save_value.Split(",".ToCharArray()); int movedown_id = Convert.ToInt32(movedown_split[0]); int movedown_order = Convert.ToInt32(movedown_split[1]); if (movedown_order < Thematic_Headings.Count) { Thematic_Heading themeHeading = Thematic_Headings[movedown_order - 1]; if (themeHeading.ThematicHeadingID == movedown_id) { // For thread safety, lock the thematic headings list lock (Thematic_Headings) { // Move this thematic heading down Thematic_Headings.Remove(themeHeading); Thematic_Headings.Insert(movedown_order, themeHeading); int current_order = 1; foreach (Thematic_Heading thisTheme in Thematic_Headings) { SobekCM_Database.Edit_Thematic_Heading(thisTheme.ThematicHeadingID, current_order, thisTheme.ThemeName, Tracer); current_order++; } // Repopulate the thematic headings list SobekCM_Database.Populate_Thematic_Headings(Thematic_Headings, Tracer); } } } break; } } } catch (Exception) { actionMessage = "Unknown error caught while handling your reqeust"; } } }