/// <summary> Refresh the list of thematic headings by pulling the data back from the database </summary>
        /// <returns> TRUE if successful, otherwise FALSE </returns>
        public static bool RefreshThematicHeadings()
        {
            try
            {
                lock (thematicHeadingsLock)
                {
                    if (thematicHeadings != null)
                    {
                        thematicHeadings.Clear();
                    }
                    if (!Engine_Database.Populate_Thematic_Headings(Thematic_Headings, null))
                    {
                        thematicHeadings = null;
                        return(false);
                    }
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #2
0
        /// <summary> Constructor for a new instance of the Thematic_Headings_AdminViewer class </summary>
        /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param>
        /// <remarks> Postback from handling an edit or new thematic heading is handled here in the constructor </remarks>
        public Thematic_Headings_AdminViewer(RequestCache RequestSpecificValues) : base(RequestSpecificValues)
        {
            RequestSpecificValues.Tracer.Add_Trace("Thematic_Headings_AdminViewer.Constructor", String.Empty);

            // Set action message to nothing to start
            actionMessage = String.Empty;

            // If the RequestSpecificValues.Current_User cannot edit this, go back
            if ((!RequestSpecificValues.Current_User.Is_System_Admin) && (!RequestSpecificValues.Current_User.Is_Portal_Admin))
            {
                RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.My_Sobek;
                RequestSpecificValues.Current_Mode.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                return;
            }

            // Handle any post backs
            if (RequestSpecificValues.Current_Mode.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 + UI_ApplicationCache_Gateway.Thematic_Headings.TakeWhile(ThisHeading => ThisHeading.ID != id).Count();
                                if (Engine_Database.Edit_Thematic_Heading(id, order, new_name, RequestSpecificValues.Tracer) < 1)
                                {
                                    actionMessage = "Unable to edit existing thematic heading";
                                }
                                else
                                {
                                    // For thread safety, lock the thematic headings list
                                    Engine_ApplicationCache_Gateway.RefreshThematicHeadings();

                                    actionMessage = "Thematic heading edits saved";
                                }
                            }
                            break;

                        case "delete":
                            int thematicDeleteId = Convert.ToInt32(save_value);
                            if (!Engine_Database.Delete_Thematic_Heading(thematicDeleteId, RequestSpecificValues.Tracer))
                            {
                                // Set action message
                                actionMessage = "Unable to delete existing thematic heading";
                            }
                            else
                            {
                                // For thread safety, lock the thematic headings list
                                lock (UI_ApplicationCache_Gateway.Thematic_Headings)
                                {
                                    // Remove this thematic heading from the list
                                    int i = 0;
                                    while (i < UI_ApplicationCache_Gateway.Thematic_Headings.Count)
                                    {
                                        if (UI_ApplicationCache_Gateway.Thematic_Headings[i].ID == thematicDeleteId)
                                        {
                                            UI_ApplicationCache_Gateway.Thematic_Headings.RemoveAt(i);
                                        }
                                        else
                                        {
                                            i++;
                                        }
                                    }
                                }

                                // Set action message
                                actionMessage = "Thematic heading deleted";
                            }
                            break;


                        case "new":
                            int new_order = UI_ApplicationCache_Gateway.Thematic_Headings.Count + 1;
                            int newid     = Engine_Database.Edit_Thematic_Heading(-1, new_order, save_value, RequestSpecificValues.Tracer);
                            if (newid < 1)
                            {
                                actionMessage = "Unable to save new thematic heading";
                            }
                            else
                            {
                                // For thread safety, lock the thematic headings list
                                lock (UI_ApplicationCache_Gateway.Thematic_Headings)
                                {
                                    // Repopulate the thematic headings list
                                    Engine_Database.Populate_Thematic_Headings(UI_ApplicationCache_Gateway.Thematic_Headings, RequestSpecificValues.Tracer);
                                }

                                // Add this blank thematic heading to the code manager
                                UI_ApplicationCache_Gateway.Aggregations.Add_Blank_Thematic_Heading(newid);

                                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 = UI_ApplicationCache_Gateway.Thematic_Headings[moveup_order - 1];
                                if (themeHeading.ID == moveup_id)
                                {
                                    // For thread safety, lock the thematic headings list
                                    lock (UI_ApplicationCache_Gateway.Thematic_Headings)
                                    {
                                        // Move this thematic heading up
                                        UI_ApplicationCache_Gateway.Thematic_Headings.Remove(themeHeading);
                                        UI_ApplicationCache_Gateway.Thematic_Headings.Insert(moveup_order - 2, themeHeading);
                                        int current_order = 1;
                                        foreach (Thematic_Heading thisTheme in UI_ApplicationCache_Gateway.Thematic_Headings)
                                        {
                                            Engine_Database.Edit_Thematic_Heading(thisTheme.ID, current_order, thisTheme.Text, RequestSpecificValues.Tracer);
                                            current_order++;
                                        }

                                        // Repopulate the thematic headings list
                                        Engine_Database.Populate_Thematic_Headings(UI_ApplicationCache_Gateway.Thematic_Headings, RequestSpecificValues.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 < UI_ApplicationCache_Gateway.Thematic_Headings.Count)
                            {
                                Thematic_Heading themeHeading = UI_ApplicationCache_Gateway.Thematic_Headings[movedown_order - 1];
                                if (themeHeading.ID == movedown_id)
                                {
                                    // For thread safety, lock the thematic headings list
                                    lock (UI_ApplicationCache_Gateway.Thematic_Headings)
                                    {
                                        // Move this thematic heading down
                                        UI_ApplicationCache_Gateway.Thematic_Headings.Remove(themeHeading);
                                        UI_ApplicationCache_Gateway.Thematic_Headings.Insert(movedown_order, themeHeading);
                                        int current_order = 1;
                                        foreach (Thematic_Heading thisTheme in UI_ApplicationCache_Gateway.Thematic_Headings)
                                        {
                                            Engine_Database.Edit_Thematic_Heading(thisTheme.ID, current_order, thisTheme.Text, RequestSpecificValues.Tracer);
                                            current_order++;
                                        }

                                        // Repopulate the thematic headings list
                                        Engine_Database.Populate_Thematic_Headings(UI_ApplicationCache_Gateway.Thematic_Headings, RequestSpecificValues.Tracer);
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
                catch (Exception)
                {
                    actionMessage = "Unknown error caught while handling your reqeust";
                }
            }
        }