Esempio n. 1
0
 public override void ExpandView(MixCmsContext _context = null, IDbContextTransaction _transaction = null)
 {
     if (Id > 0)
     {
         Fields = MixAttributeFields.UpdateViewModel
                  .Repository.GetModelListBy(a => a.AttributeSetId == Id, _context, _transaction).Data?.OrderBy(a => a.Priority).ToList();
         FormView = MixTemplates.UpdateViewModel.GetTemplateByPath(FormTemplate, Specificulture, _context, _transaction).Data;
         EdmView  = MixTemplates.UpdateViewModel.GetTemplateByPath(EdmTemplate, Specificulture, _context, _transaction).Data;
     }
     else
     {
         Fields = new List <MixAttributeFields.UpdateViewModel>();
     }
 }
Esempio n. 2
0
        RepositoryResponse <bool> ImportTheme(MixTheme parent, MixCmsContext _context, IDbContextTransaction _transaction)
        {
            var result = new RepositoryResponse <bool>()
            {
                IsSucceed = true
            };
            string fileName = $"wwwroot/{TemplateAsset.FileFolder}/{TemplateAsset.Filename}{TemplateAsset.Extension}";

            if (File.Exists(fileName))
            {
                FileRepository.Instance.UnZipFile($"{TemplateAsset.Filename}{TemplateAsset.Extension}", TemplateAsset.FileFolder);
                FileRepository.Instance.CopyWebDirectory($"{TemplateAsset.FileFolder}/Assets", AssetFolder);
                FileRepository.Instance.CopyDirectory($"{MixConstants.Folder.WebRootPath}/{TemplateAsset.FileFolder}/Templates", TemplateFolder);
                FileRepository.Instance.DeleteWebFolder(TemplateAsset.FileFolder);

                // Save template files to db
                var files = FileRepository.Instance.GetFilesWithContent(TemplateFolder);
                //TODO: Create default asset
                foreach (var file in files)
                {
                    string content = file.Content.Replace($"/Content/Templates/{TemplateAsset.Filename}/",
                                                          $"/Content/Templates/{Name}/");
                    MixTemplates.UpdateViewModel template = new MixTemplates.UpdateViewModel(
                        new MixTemplate()
                    {
                        FileFolder      = file.FileFolder,
                        FileName        = file.Filename,
                        Content         = file.Content,
                        Extension       = file.Extension,
                        CreatedDateTime = DateTime.UtcNow,
                        LastModified    = DateTime.UtcNow,
                        ThemeId         = parent.Id,
                        ThemeName       = parent.Name,
                        FolderType      = file.FolderName,
                        ModifiedBy      = CreatedBy
                    });
                    var saveResult = template.SaveModel(true, _context, _transaction);
                    result.IsSucceed = result.IsSucceed && saveResult.IsSucceed;
                    if (!saveResult.IsSucceed)
                    {
                        result.IsSucceed = false;
                        result.Exception = saveResult.Exception;
                        result.Errors.AddRange(saveResult.Errors);
                        break;
                    }
                }
            }
            return(result);
        }
Esempio n. 3
0
        private async Task <RepositoryResponse <bool> > SaveTemplatesAsync(MixTheme parent, string themeName, MixCmsContext context, IDbContextTransaction transaction)
        {
            RepositoryResponse <bool> result = new RepositoryResponse <bool>()
            {
                IsSucceed = true
            };
            // Save template files to db
            var files = FileRepository.Instance.GetFilesWithContent(TemplateFolder);

            //TODO: Create default asset
            foreach (var file in files)
            {
                string content = file.Content.Replace($"{MixFolders.SiteContentAssetsFolder}/{themeName}/",
                                                      $"{MixFolders.SiteContentAssetsFolder}/{Name}/");
                MixTemplates.UpdateViewModel template = new MixTemplates.UpdateViewModel(
                    new MixTemplate()
                {
                    FileFolder      = file.FileFolder,
                    FileName        = file.Filename,
                    Content         = file.Content,
                    Extension       = file.Extension,
                    CreatedDateTime = DateTime.UtcNow,
                    LastModified    = DateTime.UtcNow,
                    ThemeId         = parent.Id,
                    ThemeName       = parent.Name,
                    FolderType      = file.FolderName,
                    ModifiedBy      = CreatedBy
                });
                var saveResult = await template.SaveModelAsync(true, context, transaction);

                result.IsSucceed = result.IsSucceed && saveResult.IsSucceed;
                if (!saveResult.IsSucceed)
                {
                    result.IsSucceed = false;
                    result.Exception = saveResult.Exception;
                    result.Errors.AddRange(saveResult.Errors);
                    break;
                }
            }
            return(result);
        }
Esempio n. 4
0
        private async Task <RepositoryResponse <bool> > ImportThemeAsync(MixTheme parent, MixCmsContext _context, IDbContextTransaction _transaction)
        {
            var result = new RepositoryResponse <bool>()
            {
                IsSucceed = true
            };
            string filePath = $"{TemplateAsset.FileFolder}/{TemplateAsset.Filename}{TemplateAsset.Extension}";

            if (File.Exists(filePath))
            {
                string outputFolder = $"{TemplateAsset.FileFolder}/Extract";
                FileRepository.Instance.DeleteFolder(outputFolder);
                FileRepository.Instance.CreateDirectoryIfNotExist(outputFolder);
                FileRepository.Instance.UnZipFile(filePath, outputFolder);
                //Move Unzip Asset folder
                FileRepository.Instance.CopyDirectory($"{outputFolder}/Assets", $"{AssetFolder}");
                //Move Unzip Templates folder
                FileRepository.Instance.CopyDirectory($"{outputFolder}/Templates", TemplateFolder);
                //Move Unzip Uploads folder
                FileRepository.Instance.CopyDirectory($"{outputFolder}/Uploads", $"{UploadsFolder}");
                // Get SiteStructure
                var strSchema      = FileRepository.Instance.GetFile("schema.json", $"{outputFolder}/Data");
                var siteStructures = JObject.Parse(strSchema.Content).ToObject <SiteStructureViewModel>();
                FileRepository.Instance.DeleteFolder(outputFolder);
                //FileRepository.Instance.DeleteFile(filePath);
                //Import Site Structures
                result = await siteStructures.ImportAsync(Specificulture);

                if (result.IsSucceed)
                {
                    // Save template files to db
                    var files = FileRepository.Instance.GetFilesWithContent(TemplateFolder);
                    //TODO: Create default asset
                    foreach (var file in files)
                    {
                        string content = file.Content.Replace($"/Content/Templates/{siteStructures.ThemeName}/",
                                                              $"/Content/Templates/{Name}/");
                        MixTemplates.UpdateViewModel template = new MixTemplates.UpdateViewModel(
                            new MixTemplate()
                        {
                            FileFolder      = file.FileFolder,
                            FileName        = file.Filename,
                            Content         = file.Content,
                            Extension       = file.Extension,
                            CreatedDateTime = DateTime.UtcNow,
                            LastModified    = DateTime.UtcNow,
                            ThemeId         = parent.Id,
                            ThemeName       = parent.Name,
                            FolderType      = file.FolderName,
                            ModifiedBy      = CreatedBy
                        });
                        var saveResult = await template.SaveModelAsync(true, _context, _transaction);

                        result.IsSucceed = result.IsSucceed && saveResult.IsSucceed;
                        if (!saveResult.IsSucceed)
                        {
                            result.IsSucceed = false;
                            result.Exception = saveResult.Exception;
                            result.Errors.AddRange(saveResult.Errors);
                            break;
                        }
                    }
                }
            }
            return(result);
        }