public async Task <TemplateFile> Create(TemplateFileModel templateFileModel)
        {
            var existTemplateFile = await _dbRepository
                                    .Get <TemplateFile>()
                                    .FirstOrDefaultAsync(x => x.Link == templateFileModel.Link);

            if (existTemplateFile != null)
            {
                //log
                return(null);
            }

            var templateContent = await FileHelper.Download(templateFileModel.Link);

            var fullName = templateFileModel.FullName;

            var templateFile = new TemplateFile
            {
                Fullname = fullName,
                Link     = templateFileModel.Link,
                File     = new File
                {
                    Type     = FileType.Template,
                    FullName = fullName,
                    Content  = templateContent
                }
            };

            await _dbRepository.Add(templateFile);

            await _dbRepository.SaveChanges();

            return(templateFile);
        }
Esempio n. 2
0
        public async Task <ActionResult <Guid> > Create(TemplateFileModel templateFileModel)
        {
            if (templateFileModel == null)
            {
                return(BadRequest("Template was empty"));
            }

            var templateFile = await _templateService.Create(templateFileModel);

            return(Ok(templateFile?.Id));
        }