Example #1
0
        public async Task AddTemplate(TemplateInput input)
        {
            if (string.IsNullOrEmpty(input.Content))
            {
                input.Content = string.Empty;
            }

            if (!string.IsNullOrEmpty(input.CopyFrom))
            {
                input.Content = (await _templateManager.GetTemplateContentAsync(input.CopyFrom)).Content;
            }

            var template = await _templateManager.GetTemplateContentAsync(input.TemplateName);

            if (template != null)
            {
                template.Content = input.Content;
                var resultEdit = await _templateManager.EditTemplate(template);

                if (resultEdit.HasError)
                {
                    throw new UserFriendlyException(L(resultEdit.ErrorMessage));
                }
                return;
            }

            var result = await _templateManager.AddTemplate(new TemplateInfo()
            {
                Content   = input.Content,
                IsPartial = input.IsPartial,
                Name      = input.TemplateName.Sluggify(),
            });

            if (result.HasError)
            {
                throw new UserFriendlyException(L(result.ErrorMessage));
            }
        }