/// <summary>
        /// Save the data from the model into the database
        /// </summary>
        private void SaveScreen()
        {
            Guid spellId;

            SaveFeedbackLabel.Text = "Saving Record...";
            SaveFeedbackLabel.Refresh();

            Model.Save();
            //clear the detail model in the database to make sure we save the correct data
            spellId = SpellModel.GetIdFromName(Model.SpellName);
            SpellDetailsModel.DeleteBySpell(spellId);
            for (int i = 0; i < DetailModel.Count; i++)
            {
                //note: It is possible the detail models don't yet have the correct spell ID. Make sure they do before saving
                DetailModel[i].SpellId = spellId;
                DetailModel[i].Save();
            }
            DataHasChanged = false;

            //repopulate the spell list (in case any of the names have changed or new ones added)
            PopulateSpellListBox();

            //update the modification fields
            ModDateLabel.Text    = Model.LastUpdatedDate.ToString();
            ModVersionLabel.Text = Model.LastUpdatedVersion;

            SaveFeedbackLabel.Text = "Record Saved";

            DatabaseName = Model.SpellName;
        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            // Get the plugin
            Plugin plugin = GetCurrentPlugin();

            if (plugin.HasPluginFile)
            {
                int oldId = plugin.PluginId.GetValueOrDefault();

                //set the plugin values
                plugin.PluginFile.Disabled = (!PluginActiveCheckbox.Checked);

                //set the plugins context values by iterating through data repeater values
                for (int i = 0; i < ContextsRepeater.Items.Count; i++)
                {
                    PluginContextDropDownList contextNames = (PluginContextDropDownList)ContextsRepeater.Items[i].FindControl("ContextNamesDropDownList");

                    IPluginContext context = PluginManager.GetContext(plugin, contextNames.ContextType);

                    if (context.Name != (string)contextNames.SelectedValue)
                    {
                        //selected context has changed
                        PluginManager.AddContextTypeInSection(plugin, contextNames.ContextType, (string)contextNames.SelectedValue);
                    }
                }

                //register and update the plugin
                int pluginId = ContextInfo.PluginManager.RegisterPlugin(plugin);

                if (oldId < 0)
                {
                    if (oldId != pluginId)
                    {
                        Session["FeedbackLabel"] = "registered";
                        //reload the page using the new registered plugin id
                        ReloadPlugin(pluginId);
                    }
                    else
                    {
                        FeedbackPlaceholder.Visible = true;
                        SaveFeedbackLabel.SetErrorMessage("Not Successful", "The preview plug-in was not registered");
                    }
                }
                else
                {
                    //update active status text
                    PluginActiveCheckbox.Text = (PluginActiveCheckbox.Checked ? "Yes" : "No");

                    FeedbackPlaceholder.Visible = true;
                    SaveFeedbackLabel.SetSuccessMessage("Plug-in Saved", "The plug-in was successfully updated");
                }
            }
            else
            {
                FeedbackPlaceholder.Visible = true;
                SaveFeedbackLabel.SetErrorMessage("Not Successful", "Preview plug-ins cannot be registered with invalid plugin files");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Plugin plugin = ContextInfo.PluginManager.GetAnyPluginById(WebUtils.GetIntRequestParam("PluginId", 0));

                if (!plugin.IsNull)
                {
                    // Populate the user interface
                    PluginNameLabel.Text    = plugin.Name;
                    PluginVersionLabel.Text = (plugin.HasPluginFile?plugin.PluginFile.PluginVersion.ToString():"Unknown");
                    PluginFolderLabel.Text  = plugin.PluginPath;
                    PluginGuidLabel.Text    = (plugin.IsUnregistered ? "Unregistered (save to register)" : plugin.RegistrationKey.ToString());
                    //unregister plugin option only available if registered and not currently in use
                    PluginUnregisterPlaceHolder.Visible = (!plugin.IsUnregistered && !ContextInfo.PluginManager.IsUsed(plugin));
                    DownloadPluginPackLinkButton.Text   = plugin.Name + ".zip (download)";
                    RequireAllFilesLabel.Text           = (plugin.HasPluginFile ? (plugin.PluginFile.RequireAllResourceFiles ? "Yes" : "No") : "Unknown");
                    MissingFilesLabel.Text       = (plugin.HasPluginFile ? ((plugin.Status & PluginStatus.ResourcesMissing) > 0 ? "Yes" : "No") : "Unknown");
                    PluginActiveCheckbox.Checked = !plugin.IsDisabled;
                    PluginActiveCheckbox.Text    = (plugin.IsDisabled ? "No" : "Yes");

                    //bind the plugin context type info
                    BindContexts();
                }
            }

            //set the feedback label if page reloaded after registering/unregistering
            if (Session["FeedbackLabel"] != null && !String.IsNullOrEmpty((string)Session["FeedbackLabel"]))
            {
                switch (((string)Session["FeedbackLabel"]).ToLower())
                {
                case "registered":
                    SaveFeedbackLabel.SetSuccessMessage("Plug-in Registered", "The plug-in was successfully registered");
                    break;

                case "unregistered":
                    SaveFeedbackLabel.SetSuccessMessage("Plug-in Unregistered", "The plug-in was successfully unregistered");
                    break;
                }
                Session["FeedbackLabel"]    = null;
                FeedbackPlaceholder.Visible = true;
            }
            else
            {
                FeedbackPlaceholder.Visible = false;
            }
        }
        protected void PluginUnregisterLinkButton_Click(object sender, EventArgs e)
        {
            // Get the plugin
            Plugin plugin = GetCurrentPlugin();

            int oldId = plugin.PluginId.GetValueOrDefault();

            //unregister it
            int pluginId = ContextInfo.PluginManager.UnregisterPlugin(plugin);

            if (oldId > 0 && oldId != pluginId)
            {
                Session["FeedbackLabel"] = "unregistered";
                //update details
                ReloadPlugin(pluginId);
            }
            else
            {
                FeedbackPlaceholder.Visible = true;
                SaveFeedbackLabel.SetErrorMessage("Not Successful", "The preview plug-in could not be unregistered");
            }
        }