private void SaveInjection()
        {
            try
            {
                var ctlModule = new InjectionController();
                InjectionInfo objInj = null;

                objInj = !string.IsNullOrEmpty(hidInjectionId.Value) ? ctlModule.GetInjectionContent(int.Parse(hidInjectionId.Value)) : new InjectionInfo();

                PopulateInjectionForSave(ref objInj);

                if (!string.IsNullOrEmpty(hidInjectionId.Value))
                {
                    ctlModule.UpdateInjectionContent(objInj);
                }
                else
                {
                    ctlModule.AddInjectionContent(objInj);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
        protected string GetInjectionTypeForDisplay(object InjectionId)
        {
            if (InjectionId == null) return string.Empty;

            var ctl = new InjectionController();
            var injection = ctl.GetInjectionContent(int.Parse(InjectionId.ToString(), NumberStyles.Integer));
            var injectionType = InjectionController.GetInjectionType(injection);

            if (injectionType == InjectionType.HtmlBottom || injectionType == InjectionType.HtmlTop)
            {
                return GetLocalizedString(injectionType.ToString());
            }
            else
            {
                var injectionProvider = InjectionController.GetCrmProvider(injection);

                if (string.IsNullOrEmpty(injectionProvider))
                {
                    return string.Concat(GetLocalizedString(injectionType.ToString()),
                        GetLocalizedString(InjectionController.GetCrmProviderDefault(injectionType)));
                }
                else
                {
                    return string.Concat(GetLocalizedString(injectionType.ToString()),
                        GetLocalizedString(injectionProvider));
                }
            }
        }
        private void BindForm(int ItemId)
        {
            var ctlModule = new InjectionController();
            var injection = new InjectionInfo();

            injection = ctlModule.GetInjectionContent(ItemId);

            txtName.Text = injection.InjectName;
            txtContent.Text = Server.HtmlDecode(injection.InjectContent);
            radInject.ClearSelection();

            if (injection.InjectTop)
            {
                radInject.Items.FindByText(GetLocalizedString("radInject.0.Text")).Selected = true;
            }
            else
            {
                radInject.Items.FindByText(GetLocalizedString("radInject.1.Text")).Selected = true;
            }

            chkEnabled.Checked = injection.IsEnabled;
            hidInjectionId.Value = injection.InjectionId.ToString();
            cvName.Enabled = false;

            cmdDelete.Visible = !string.IsNullOrEmpty(hidInjectionId.Value);

            if (injection.CustomProperties.Any(p => p.Name == InjectionInfoMembers.CrmPriorityField))
            {
                var priorityLevel = injection.CustomProperties.FirstOrDefault(p => p.Name == InjectionInfoMembers.CrmPriorityField).Value;
                txtCrmPriority.Text = (priorityLevel == "-1") ? string.Empty : priorityLevel;
            }

            if (injection.CustomProperties.Any(p => p.Name == InjectionInfoMembers.CrmProviderField))
            {
                var provider = injection.CustomProperties.FirstOrDefault(p => p.Name == InjectionInfoMembers.CrmProviderField).Value;
                ddlCrmProvider.ClearSelection();
                ddlCrmProvider.SelectedIndex = int.Parse(provider);
            }

            if (injection.CustomProperties.Any(p => p.Name == InjectionInfoMembers.LastUpdatedByField))
            {
                var updatedBy = injection.CustomProperties.FirstOrDefault(p => p.Name == InjectionInfoMembers.LastUpdatedByField);
                var updatedDate = injection.CustomProperties.FirstOrDefault(p => p.Name == InjectionInfoMembers.LastUpdatedDateField);

                var user = UserController.GetUserById(PortalSettings.PortalId, int.Parse(updatedBy.Value, NumberStyles.Integer));

                lblAudit.Text = string.Format(GetLocalizedString("lblAudit"), user.DisplayName, updatedDate.Value);
            }

            if (injection.CustomProperties.Any(p => p.Name == InjectionInfoMembers.InjectionTypeField))
            {
                var intType =int.Parse(
                    injection.CustomProperties.FirstOrDefault(p => p.Name == InjectionInfoMembers.InjectionTypeField)
                        .Value);

                radType.SelectedIndex = intType;
            }
            else
            {
                // the default for existing injections is 1 because JS/CSS wasn't an option in the past
                radType.SelectedIndex = 1;
            }

            ToggleType();
        }
        protected bool CommandUpVisible(object InjectionId)
        {
            if (InjectionId == null) return false;

            var ctlModule = new InjectionController();
            var oInject = ctlModule.GetInjectionContent(int.Parse(InjectionId.ToString(), NumberStyles.Integer));

            return (oInject.OrderShown != 1);
        }