Esempio n. 1
0
 public IHttpActionResult CreateTemplateVersion([FromBody] CreateTemplateVersionRequest template)
 {
     template.ValidateNotNull();
     template.ValidateContent();
     return(Ok(new CreateTemplateVersionResponse()
     {
         Data = _templateVersionManipulation.Add(template),
         Success = Common.Enumerations.ResponseStatus.Succeeded
     }));
 }
Esempio n. 2
0
        public int Add(CreateTemplateRequest template)
        {
            if (!_folderManipulation.Exists(template.FolderId))
            {
                throw new NsiArgumentException(string.Format(TemplateManagementMessages.FolderInvalidId));
            }

            TemplateDomain templateDomain = new TemplateDomain
            {
                Name        = template.Name,
                FolderId    = template.FolderId,
                DateCreated = DateTime.Now
            };

            var result = _templateRepository.Add(templateDomain);

            if (result <= 0)
            {
                throw new NsiBaseException(string.Format(TemplateManagementMessages.TemplateCreationFailed));
            }

            TemplateVersionDomain templateVersionDomain = new TemplateVersionDomain
            {
                Code        = VERSION_CODE,
                TemplateId  = result,
                IsDefault   = true,
                DateCreated = templateDomain.DateCreated,
                Content     = JsonConvert.SerializeObject(template.Content)
            };
            var version = _templateVersionManipulation.Add(templateVersionDomain);

            if (version <= 0)
            {
                throw new NsiBaseException(string.Format(TemplateManagementMessages.TemplateCreationFailed));
            }

            return(result);
        }