/// <inheritdoc/> public override object GetObsidianBlockInitialization() { using (var rockContext = new RockContext()) { var templateId = RequestContext.GetPageParameter(PageParameterKey.FormTemplateId).AsIntegerOrNull(); // Build the basic view model information required to edit a // form template. var viewModel = new FormTemplateDetailConfiguration { Sources = GetOptionSources(rockContext), ParentUrl = this.GetParentPageUrl() }; // If we have a template specified in the query string then // load the information from it to populate the form. if (templateId.HasValue && templateId.Value != 0) { var template = new WorkflowFormBuilderTemplateService(rockContext).Get(templateId.Value); if (template != null && template.IsAuthorized(Authorization.VIEW, RequestContext.CurrentPerson)) { viewModel.TemplateGuid = template.Guid; viewModel.Template = GetTemplateDetailViewModel(template, rockContext); viewModel.IsEditable = template.IsAuthorized(Authorization.EDIT, RequestContext.CurrentPerson); } else { // null means "not found or some other error prevented viewing". viewModel.TemplateGuid = null; } } else { // Guid.Empty means "create a new template". viewModel.TemplateGuid = Guid.Empty; viewModel.IsEditable = true; } return(viewModel); } }
public BlockActionResult StartEdit(Guid guid) { using (var rockContext = new RockContext()) { var template = new WorkflowFormBuilderTemplateService(rockContext).Get(guid); // Verify the template exists and the individual has the correct // permissions to make the edits. if (template == null || !template.IsAuthorized(Authorization.EDIT, RequestContext.CurrentPerson)) { return(ActionBadRequest("Invalid template.")); } return(ActionOk(GetTemplateEditViewModel(template, rockContext))); } }