public override void Up(ICmsConfiguration configuration) { using (var pagesApi = CmsContext.CreateApiContextOf<PagesApiContext>()) { const string WidgetPath = "~/Areas/bcms-newsletter/Views/Widgets/SubscribeToNewsletter.cshtml"; var request = new GetServerControlWidgetsRequest(e => e.Url == WidgetPath); var widgets = pagesApi.GetServerControlWidgets(request); if (widgets.Items.Count > 0) { return; } using (var transactionScope = new TransactionScope()) { pagesApi.CreateServerControlWidget( new CreateServerControlWidgetRequest() { Name = "Newsletter Widget", WidgetPath = WidgetPath, Options = new List<ContentOptionDto>() { new ContentOptionDto() { Type = OptionType.Text, Key = "Email placeholder", DefaultValue = "email..." }, new ContentOptionDto() { Type = OptionType.Text, Key = "Label title", DefaultValue = "Subscribe to newsletter" }, new ContentOptionDto() { Type = OptionType.Text, Key = "Submit title", DefaultValue = "Submit" }, new ContentOptionDto() { Type = OptionType.Text, Key = "Submit is disabled", DefaultValue = "false" } } }); transactionScope.Complete(); } } }
/// <summary> /// Gets the server control widgets. /// </summary> /// <param name="request">The request.</param> /// <returns> /// Server control widget list. /// </returns> /// <exception cref="CmsApiException">Failed to get widgets.</exception> public DataListResponse <ServerControlWidget> GetServerControlWidgets(GetServerControlWidgetsRequest request) { try { return(Repository.ToDataListResponse(request)); } catch (Exception inner) { var message = string.Format("Failed to get server control widgets."); Logger.Error(message, inner); throw new CmsApiException(message, inner); } }
public override void Up(ICmsConfiguration configuration) { using (var pagesApi = CmsContext.CreateApiContextOf <PagesApiContext>()) { const string WidgetPath = "~/Areas/bcms-newsletter/Views/Widgets/SubscribeToNewsletter.cshtml"; var request = new GetServerControlWidgetsRequest(e => e.Url == WidgetPath); var widgets = pagesApi.GetServerControlWidgets(request); if (widgets.Items.Count > 0) { return; } using (var transactionScope = new TransactionScope()) { pagesApi.CreateServerControlWidget( new CreateServerControlWidgetRequest() { Name = "Newsletter Widget", WidgetPath = WidgetPath, Options = new List <ContentOptionDto>() { new ContentOptionDto() { Type = OptionType.Text, Key = "Email placeholder", DefaultValue = "email..." }, new ContentOptionDto() { Type = OptionType.Text, Key = "Label title", DefaultValue = "Subscribe to newsletter" }, new ContentOptionDto() { Type = OptionType.Text, Key = "Submit title", DefaultValue = "Submit" }, new ContentOptionDto() { Type = OptionType.Text, Key = "Submit is disabled", DefaultValue = "false" } } }); transactionScope.Complete(); } } }
/// <summary> /// Gets the server control widgets. /// </summary> /// <param name="request">The request.</param> /// <returns> /// Server control widget list. /// </returns> /// <exception cref="CmsApiException">Failed to get widgets.</exception> public DataListResponse<ServerControlWidget> GetServerControlWidgets(GetServerControlWidgetsRequest request) { try { return Repository.ToDataListResponse(request); } catch (Exception inner) { var message = string.Format("Failed to get server control widgets."); Logger.Error(message, inner); throw new CmsApiException(message, inner); } }