public override void ExpandView(SiocCmsContext _context = null, IDbContextTransaction _transaction = null) { var getAlias = ApiUrlAliasViewModel.Repository.GetSingleModel( u => u.Specificulture == Specificulture && u.SourceId == Id.ToString() && u.Type == (int)SWCmsConstants.UrlAliasType.Page); UrlAlias = getAlias.Data; if (UrlAlias == null) { UrlAlias = new ApiUrlAliasViewModel() { Type = SWCmsConstants.UrlAliasType.Page, Specificulture = Specificulture, Alias = SeoName }; } Cultures = Cultures ?? CommonRepository.Instance.LoadCultures(Specificulture, _context, _transaction); Cultures.ForEach(c => c.IsSupported = _context.SiocCategory.Any(m => m.Id == Id && m.Specificulture == c.Specificulture)); if (!string.IsNullOrEmpty(this.Tags)) { ListTag = JArray.Parse(this.Tags); } int themeId = GlobalConfigurationService.Instance.GetLocalInt(SWCmsConstants.ConfigurationKeyword.ThemeId, Specificulture, 0); View = ApiTemplateViewModel.GetTemplateByPath(themeId, Template, SWCmsConstants.TemplateFolder.Pages, _context, _transaction); if (this.View == null) { this.View = new ApiTemplateViewModel(new SiocTemplate() { Extension = SWCmsConstants.Parameters.TemplateExtension, TemplateId = GlobalConfigurationService.Instance.GetLocalInt(SWCmsConstants.ConfigurationKeyword.ThemeId, Specificulture, 0), TemplateName = ActivedTemplate, FolderType = TemplateFolderType, FileFolder = this.TemplateFolder, FileName = SWCmsConstants.Default.DefaultTemplate, ModifiedBy = ModifiedBy, Content = "<div></div>" }); } this.Template = SwCmsHelper.GetFullPath(new string[] { this.View?.FileFolder , this.View?.FileName }); this.ModuleNavs = GetModuleNavs(_context, _transaction); this.ParentNavs = GetParentNavs(_context, _transaction); this.ChildNavs = GetChildNavs(_context, _transaction); this.PositionNavs = GetPositionNavs(_context, _transaction); }
public override void ExpandView(SiocCmsContext _context = null, IDbContextTransaction _transaction = null) { Cultures = CommonRepository.Instance.LoadCultures(Specificulture, _context, _transaction); Cultures.ForEach(c => c.IsSupported = _context.SiocModule.Any(m => m.Id == Id && m.Specificulture == c.Specificulture)); Columns = new List <ModuleFieldViewModel>(); JArray arrField = !string.IsNullOrEmpty(Fields) ? JArray.Parse(Fields) : new JArray(); foreach (var field in arrField) { ModuleFieldViewModel thisField = new ModuleFieldViewModel() { Name = CommonHelper.ParseJsonPropertyName(field["name"].ToString()), Title = field["title"]?.ToString(), Options = field["options"] != null ? field["options"].Value <JArray>() : new JArray(), Priority = field["priority"] != null ? field["priority"].Value <int>() : 0, DataType = (SWCmsConstants.DataType)(int) field["dataType"], Width = field["width"] != null ? field["width"].Value <int>() : 3, IsUnique = field["isUnique"] != null ? field["isUnique"].Value <bool>() : true, IsRequired = field["isRequired"] != null ? field["isRequired"].Value <bool>() : true, IsDisplay = field["isDisplay"] != null ? field["isDisplay"].Value <bool>() : true, IsSelect = field["isSelect"] != null ? field["isSelect"].Value <bool>() : false, IsGroupBy = field["isGroupBy"] != null ? field["isGroupBy"].Value <bool>() : false, }; Columns.Add(thisField); } int themeId = GlobalConfigurationService.Instance.GetLocalInt(SWCmsConstants.ConfigurationKeyword.ThemeId, Specificulture, 0); View = ApiTemplateViewModel.GetTemplateByPath(themeId, Template, SWCmsConstants.TemplateFolder.Modules, _context, _transaction); if (this.View == null) { this.View = new ApiTemplateViewModel(new SiocTemplate() { Extension = SWCmsConstants.Parameters.TemplateExtension, TemplateId = themeId, TemplateName = ActivedTemplate, FolderType = TemplateFolderType, FileFolder = this.TemplateFolder, FileName = SWCmsConstants.Default.DefaultTemplate, ModifiedBy = ModifiedBy, Content = "<div></div>" }, _context, _transaction); } this.Template = SwCmsHelper.GetFullPath(new string[] { this.View?.FileFolder , this.View?.FileName }); }
public override async Task <RepositoryResponse <bool> > SaveSubModelsAsync(SiocTheme parent, SiocCmsContext _context = null, IDbContextTransaction _transaction = null) { RepositoryResponse <bool> result = new RepositoryResponse <bool>() { IsSucceed = true }; if (Asset.Content != null || Asset.FileStream != null) { Asset.FileFolder = AssetFolder; string fullPath = CommonHelper.GetFullPath(new string[] { SWCmsConstants.Parameters.WebRootPath, Asset.FileFolder }); FileRepository.Instance.EmptyFolder(fullPath); var isSaved = FileRepository.Instance.SaveWebFile(Asset); result.IsSucceed = isSaved; if (isSaved) { result.IsSucceed = FileRepository.Instance.UnZipFile(Asset); if (!result.IsSucceed) { result.Errors.Add("Cannot unzip file"); } } else { result.Errors.Add("Cannot saved asset file"); } } if (Id == 0) { string defaultFolder = CommonHelper.GetFullPath(new string[] { SWCmsConstants.Parameters.TemplatesFolder, Name == "Default" ? "Default" : SWCmsConstants.Default.DefaultTemplateFolder }); bool copyResult = FileRepository.Instance.CopyDirectory(defaultFolder, TemplateFolder); var files = copyResult ? FileRepository.Instance.GetFilesWithContent(TemplateFolder) : new System.Collections.Generic.List <FileViewModel>(); //TODO: Create default asset foreach (var file in files) { ApiTemplateViewModel template = new ApiTemplateViewModel( new SiocTemplate() { FileFolder = file.FileFolder, FileName = file.Filename, Content = file.Content, Extension = file.Extension, CreatedDateTime = DateTime.UtcNow, LastModified = DateTime.UtcNow, TemplateId = Model.Id, TemplateName = Model.Name, FolderType = file.FolderName, ModifiedBy = CreatedBy }); var saveResult = await template.SaveModelAsync(true, _context, _transaction); result.IsSucceed = result.IsSucceed && saveResult.IsSucceed; if (!saveResult.IsSucceed) { result.Exception = saveResult.Exception; result.Errors.AddRange(saveResult.Errors); break; } } } // Actived Theme if (IsActived) { InfoConfigurationViewModel config = (await InfoConfigurationViewModel.Repository.GetSingleModelAsync( c => c.Keyword == SWCmsConstants.ConfigurationKeyword.Theme && c.Specificulture == Specificulture , _context, _transaction)).Data; if (config == null) { config = new InfoConfigurationViewModel() { Keyword = SWCmsConstants.ConfigurationKeyword.Theme, Specificulture = Specificulture, Category = SWCmsConstants.ConfigurationType.User, DataType = SWCmsConstants.DataType.String, Description = "Cms Theme", Value = Name }; } else { config.Value = Name; } var saveConfigResult = await config.SaveModelAsync(false, _context, _transaction); if (!saveConfigResult.IsSucceed) { Errors.AddRange(saveConfigResult.Errors); } else { GlobalConfigurationService.Instance.RefreshConfigurations(_context, _transaction); } result.IsSucceed = result.IsSucceed && saveConfigResult.IsSucceed; InfoConfigurationViewModel configId = (await InfoConfigurationViewModel.Repository.GetSingleModelAsync( c => c.Keyword == SWCmsConstants.ConfigurationKeyword.ThemeId && c.Specificulture == Specificulture, _context, _transaction)).Data; if (configId == null) { configId = new InfoConfigurationViewModel() { Keyword = SWCmsConstants.ConfigurationKeyword.ThemeId, Specificulture = Specificulture, Category = SWCmsConstants.ConfigurationType.User, DataType = SWCmsConstants.DataType.String, Description = "Cms Theme Id", Value = Model.Id.ToString() }; } else { configId.Value = Model.Id.ToString(); } var saveResult = await configId.SaveModelAsync(false, _context, _transaction); if (!saveResult.IsSucceed) { Errors.AddRange(saveResult.Errors); } else { GlobalConfigurationService.Instance.RefreshConfigurations(_context, _transaction); } result.IsSucceed = result.IsSucceed && saveResult.IsSucceed; } if (Asset.Content != null || Asset.FileStream != null) { var files = FileRepository.Instance.GetWebFiles(AssetFolder); StringBuilder strStyles = new StringBuilder(); foreach (var css in files.Where(f => f.Extension == ".css")) { strStyles.Append($" <link href='{css.FileFolder}/{css.Filename}{css.Extension}' rel='stylesheet'/>"); } StringBuilder strScripts = new StringBuilder(); foreach (var js in files.Where(f => f.Extension == ".js")) { strScripts.Append($" <script src='{js.FileFolder}/{js.Filename}{js.Extension}'></script>"); } var layout = ApiTemplateViewModel.Repository.GetSingleModel( t => t.FileName == "_Layout" && t.FolderType == "Masters" && t.TemplateId == Model.Id , _context, _transaction); layout.Data.Content = layout.Data.Content.Replace("<!--[STYLES]-->" , string.Format(@"{0}" , strStyles)); layout.Data.Content = layout.Data.Content.Replace("<!--[SCRIPTS]-->" , string.Format(@"{0}" , strScripts)); await layout.Data.SaveModelAsync(true, _context, _transaction); } return(result); }
public override void ExpandView(SiocCmsContext _context = null, IDbContextTransaction _transaction = null) { Cultures = CommonRepository.Instance.LoadCultures(Specificulture, _context, _transaction); UrlAlias = ApiUrlAliasViewModel.Repository.GetSingleModel(u => u.Specificulture == Specificulture && u.SourceId == Id.ToString() && u.Type == (int)SWCmsConstants.UrlAliasType.Product).Data; if (UrlAlias == null) { UrlAlias = new ApiUrlAliasViewModel() { Specificulture = Specificulture, Type = SWCmsConstants.UrlAliasType.Product, Alias = SeoName }; } StrNormalPrice = SwCmsHelper.FormatPrice(NormalPrice); StrDealPrice = SwCmsHelper.FormatPrice(DealPrice); StrImportPrice = SwCmsHelper.FormatPrice(ImportPrice); if (!string.IsNullOrEmpty(this.Tags)) { ListTag = JArray.Parse(this.Tags); } Properties = new List <ExtraProperty>(); if (!string.IsNullOrEmpty(ExtraProperties)) { JArray arr = JArray.Parse(ExtraProperties); foreach (JToken item in arr) { Properties.Add(item.ToObject <ExtraProperty>()); } } //Get Templates int themeId = GlobalConfigurationService.Instance.GetLocalInt(SWCmsConstants.ConfigurationKeyword.ThemeId, Specificulture, 0); View = ApiTemplateViewModel.GetTemplateByPath(themeId, Template, SWCmsConstants.TemplateFolder.Products, _context, _transaction); this.View = View ?? Templates.FirstOrDefault(); if (this.View == null) { this.View = new ApiTemplateViewModel(new SiocTemplate() { Extension = SWCmsConstants.Parameters.TemplateExtension, TemplateId = GlobalConfigurationService.Instance.GetLocalInt(SWCmsConstants.ConfigurationKeyword.ThemeId, Specificulture, 0), TemplateName = ActivedTemplate, FolderType = TemplateFolderType, FileFolder = this.TemplateFolder, FileName = SWCmsConstants.Default.DefaultTemplate, ModifiedBy = ModifiedBy, Content = "<div></div>" }); } this.Template = SwCmsHelper.GetFullPath(new string[] { this.View?.FileFolder , this.View?.FileName }); var getCateProduct = CommonRepository.Instance.GetCategoryProductNav(Id, Specificulture, _context, _transaction); if (getCateProduct.IsSucceed) { this.Categories = getCateProduct.Data; this.Categories.ForEach(c => { c.IsActived = NavCategoryProductViewModel.Repository.CheckIsExists(n => n.CategoryId == c.CategoryId && n.ProductId == Id, _context, _transaction); }); } var getModuleProduct = CommonRepository.Instance.GetModuleProductNav(Id, Specificulture, _context, _transaction); if (getModuleProduct.IsSucceed) { this.Modules = getModuleProduct.Data; } var getProductModule = CommonRepository.Instance.GetProductModuleNav(Id, Specificulture, _context, _transaction); if (getProductModule.IsSucceed) { this.ModuleNavs = getProductModule.Data; } var getProductMedia = NavProductMediaViewModel.Repository.GetModelListBy(n => n.ProductId == Id && n.Specificulture == Specificulture, _context, _transaction); if (getProductMedia.IsSucceed) { MediaNavs = getProductMedia.Data.OrderBy(p => p.Priority).ToList(); MediaNavs.ForEach(n => n.IsActived = true); } ProductNavs = GetRelated(_context, _transaction); this.ActivedModules = new List <ApiModuleViewModel>(); foreach (var module in this.ModuleNavs.Where(m => m.IsActived)) { var getModule = ApiModuleViewModel.Repository.GetSingleModel(m => m.Id == module.ModuleId && m.Specificulture == module.Specificulture, _context, _transaction); if (getModule.IsSucceed) { this.ActivedModules.Add(getModule.Data); this.ActivedModules.ForEach(m => m.LoadData(Id)); } } }