コード例 #1
0
        public async Task <IActionResult> CreatePost(TemplateViewModel model)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageTemplates))
            {
                return(Unauthorized());
            }

            if (ModelState.IsValid)
            {
                if (String.IsNullOrWhiteSpace(model.Name))
                {
                    ModelState.AddModelError(nameof(TemplateViewModel.Name), T["The name is mandatory."]);
                }
            }

            if (ModelState.IsValid)
            {
                var template = new Template {
                    Content = model.Content, Description = model.Description
                };

                await _templatesManager.UpdateTemplateAsync(model.Name, template);

                return(RedirectToAction(nameof(Index)));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #2
0
        public async Task <IActionResult> CreatePost(TemplateViewModel model, string submit, string returnUrl = null)
        {
            if (!model.AdminTemplates && !await _authorizationService.AuthorizeAsync(User, Permissions.ManageTemplates))
            {
                return(Unauthorized());
            }

            if (model.AdminTemplates && !await _authorizationService.AuthorizeAsync(User, AdminTemplatesPermissions.ManageAdminTemplates))
            {
                return(Unauthorized());
            }

            ViewData["ReturnUrl"] = returnUrl;

            if (ModelState.IsValid)
            {
                if (String.IsNullOrWhiteSpace(model.Name))
                {
                    ModelState.AddModelError(nameof(TemplateViewModel.Name), S["The name is mandatory."]);
                }
                else
                {
                    var templatesDocument = model.AdminTemplates
                        ? await _adminTemplatesManager.GetTemplatesDocumentAsync()
                        : await _templatesManager.GetTemplatesDocumentAsync()
                    ;

                    if (templatesDocument.Templates.ContainsKey(model.Name))
                    {
                        ModelState.AddModelError(nameof(TemplateViewModel.Name), S["A template with the same name already exists."]);
                    }
                }
            }

            if (ModelState.IsValid)
            {
                var template = new Template {
                    Content = model.Content, Description = model.Description
                };

                await(model.AdminTemplates
                    ? _adminTemplatesManager.UpdateTemplateAsync(model.Name, template)
                    : _templatesManager.UpdateTemplateAsync(model.Name, template)
                      );

                if (submit == "SaveAndContinue")
                {
                    RedirectToAction(nameof(Edit), new { name = model.Name, adminTemplates = model.AdminTemplates, returnUrl });
                }
                else
                {
                    return(RedirectToReturnUrlOrIndex(returnUrl));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #3
0
        //新建模版函数
        public async void CreateIndexTemplate()
        {
            var MyTemplate = new TemplateViewModel {
            };

            MyTemplate.Name        = "Content__Page";
            MyTemplate.Description = "A template for the  Page content type";
            MyTemplate.Content     = "<style>" +
                                     "    .button{border:2px solid #C5C5C5;background:#EEEEEE;margin:0 4px;}" +
                                     "    .search{border:2px solid #C5c5c5;}" +
                                     "</style>" +
                                     "<center>" +
                                     "    <div class=\"container\" width=\"960\">" +
                                     "            " +
                                     "            " +
                                     "    </div>" +
                                     "</center>";
            if (ModelState.IsValid)
            {
                if (String.IsNullOrWhiteSpace(MyTemplate.Name))
                {
                    ModelState.AddModelError(nameof(TemplateViewModel.Name), T["The name is mandatory."]);
                }
            }

            if (ModelState.IsValid)
            {
                var template = new Template {
                    Content = MyTemplate.Content, Description = MyTemplate.Description
                };

                await _templatesManager.UpdateTemplateAsync(MyTemplate.Name, template);
            }
        }
コード例 #4
0
        public async Task ExecuteAsync(RecipeExecutionContext context)
        {
            if (!String.Equals(context.Name, "Templates", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            if (context.Step.Property("Templates").Value is JObject templates)
            {
                foreach (var property in templates.Properties())
                {
                    var name  = property.Name;
                    var value = property.Value.ToObject <Template>();

                    await _templatesManager.UpdateTemplateAsync(name, value);
                }
            }
        }