Example #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            SignCategory signCategory = null;

            var rockContext         = new RockContext();
            var signCategoryService = new SignCategoryService(rockContext);
            var attributeService    = new AttributeService(rockContext);

            int signCategoryId = int.Parse(hfSignCategoryId.Value);

            if (signCategoryId != 0)
            {
                signCategory = signCategoryService.Get(signCategoryId);
            }

            if (signCategory == null)
            {
                // Check for existing
                var existingDevice = signCategoryService.Queryable()
                                     .Where(k => k.Name == tbName.Text)
                                     .FirstOrDefault();
                if (existingDevice != null)
                {
                    nbDuplicateSign.Text    = string.Format("A sign category already exists with the name '{0}'. Please use a different device name.", existingDevice.Name);
                    nbDuplicateSign.Visible = true;
                }
                else
                {
                    signCategory = new SignCategory();
                    signCategoryService.Add(signCategory);
                }
            }


            if (signCategory != null)
            {
                signCategory.Name        = tbName.Text;
                signCategory.Description = tbDescription.Text;

                if (!signCategory.IsValid || !Page.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                rockContext.SaveChanges();

                NavigateToParentPage();
            }
        }
Example #2
0
        protected void gSignCategories_Delete(object sender, RowEventArgs e)
        {
            var rockContext = new RockContext();
            SignCategoryService signCategoryService = new SignCategoryService(rockContext);
            SignCategory        signCategory        = signCategoryService.Get(e.RowKeyId);

            if (signCategory != null)
            {
                signCategoryService.Delete(signCategory);
                rockContext.SaveChanges();
            }

            BindGrid();
        }
Example #3
0
        /// <summary>
        /// Shows the edit.
        /// </summary>
        /// <param name="DeviceId">The device identifier.</param>
        public void ShowDetail(int signCategoryId)
        {
            pnlDetails.Visible = true;
            SignCategory signCategory = null;

            var rockContext = new RockContext();

            if (!signCategoryId.Equals(0))
            {
                signCategory      = new SignCategoryService(rockContext).Get(signCategoryId);
                lActionTitle.Text = ActionTitle.Edit(SignCategory.FriendlyTypeName).FormatAsHtmlTitle();
            }

            if (signCategory == null)
            {
                signCategory = new SignCategory {
                    Id = 0
                };
                lActionTitle.Text = ActionTitle.Add(SignCategory.FriendlyTypeName).FormatAsHtmlTitle();
            }

            hfSignCategoryId.Value = signCategory.Id.ToString();

            tbName.Text        = signCategory.Name;
            tbDescription.Text = signCategory.Description;

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if (!IsUserAuthorized(Authorization.EDIT))
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(SignCategory.FriendlyTypeName);
            }

            if (readOnly)
            {
                lActionTitle.Text = ActionTitle.View(SignCategory.FriendlyTypeName);
                btnCancel.Text    = "Close";
            }

            tbName.ReadOnly        = readOnly;
            tbDescription.ReadOnly = readOnly;

            btnSave.Visible = !readOnly;
        }