public override async Task <RepositoryResponse <bool> > SaveSubModelsAsync(MixPage parent, MixCmsContext _context = null, IDbContextTransaction _transaction = null) { var result = new RepositoryResponse <bool> { IsSucceed = true }; var saveTemplate = await View.SaveModelAsync(true, _context, _transaction); ViewModelHelper.HandleResult(saveTemplate, ref result); if (result.IsSucceed && Master != null) { var saveLayout = Master.SaveModel(true, _context, _transaction); ViewModelHelper.HandleResult(saveLayout, ref result); } if (result.IsSucceed && UrlAliases != null) { foreach (var item in UrlAliases) { if (result.IsSucceed) { item.SourceId = parent.Id.ToString(); item.Type = UrlAliasType.Page; item.Specificulture = Specificulture; var saveResult = await item.SaveModelAsync(false, _context, _transaction); ViewModelHelper.HandleResult(saveResult, ref result); } else { break; } } } if (result.IsSucceed) { foreach (var item in ModuleNavs) { item.PageId = parent.Id; if (item.IsActived) { var saveResult = await item.SaveModelAsync(false, _context, _transaction); ViewModelHelper.HandleResult(saveResult, ref result); } else { var saveResult = await item.RemoveModelAsync(false, _context, _transaction); ViewModelHelper.HandleResult(saveResult, ref result); } } } //if (result.IsSucceed) //{ // foreach (var item in ParentNavs) // { // item.Id = parent.Id; // if (item.IsActived) // { // var saveResult = await item.SaveModelAsync(false, _context, _transaction); // ViewModelHelper.HandleResult(saveResult, ref result); // } // else // { // var saveResult = await item.RemoveModelAsync(false, _context, _transaction); // ViewModelHelper.HandleResult(saveResult, ref result); // } // } //} if (result.IsSucceed) { // Save Attributes result = await SaveAttributeAsync(parent.Id, _context, _transaction); } //if (result.IsSucceed) //{ // foreach (var item in ChildNavs) // { // item.ParentId = parent.Id; // if (item.IsActived) // { // var saveResult = await item.SaveModelAsync(false, _context, _transaction); // ViewModelHelper.HandleResult(saveResult, ref result); // } // else // { // var saveResult = await item.RemoveModelAsync(false, _context, _transaction); // ViewModelHelper.HandleResult(saveResult, ref result); // } // } //} return(result); }
public override async Task <RepositoryResponse <bool> > SaveSubModelsAsync(MixCulture parent, MixCmsContext _context = null, IDbContextTransaction _transaction = null) { var result = new RepositoryResponse <bool>() { IsSucceed = true }; // Clone Configurations if (result.IsSucceed) { var cloneResult = await CloneConfigurationsAsync(parent, _context, _transaction); ViewModelHelper.HandleResult(cloneResult, ref result); } if (result.IsSucceed) { var cloneResult = await CloneLanguagesAsync(parent, _context, _transaction); ViewModelHelper.HandleResult(cloneResult, ref result); } if (result.IsSucceed) { var cloneResult = await CloneMediasAsync(parent, _context, _transaction); ViewModelHelper.HandleResult(cloneResult, ref result); } if (result.IsSucceed) { var cloneResult = await CloneModulesAsync(parent, _context, _transaction); ViewModelHelper.HandleResult(cloneResult, ref result); } // Clone Pages if (result.IsSucceed) { var cloneResult = await ClonePagesAsync(parent, _context, _transaction); ViewModelHelper.HandleResult(cloneResult, ref result); } // Clone Post from Default culture if (result.IsSucceed) { var cloneResult = await ClonePostsAsync(parent, _context, _transaction); ViewModelHelper.HandleResult(cloneResult, ref result); } // Clone ModuleData from Default culture if (result.IsSucceed) { var cloneResult = await CloneModuleDatasAsync(parent, _context, _transaction); ViewModelHelper.HandleResult(cloneResult, ref result); } // Clone PageModules from Default culture if (result.IsSucceed) { var cloneResult = await ClonePageModulesAsync(parent, _context, _transaction); ViewModelHelper.HandleResult(cloneResult, ref result); } // Clone PagePosition from Default culture if (result.IsSucceed) { var cloneResult = await ClonePagePositionsAsync(parent, _context, _transaction); ViewModelHelper.HandleResult(cloneResult, ref result); } // Clone PagePost from Default culture if (result.IsSucceed) { var cloneResult = await ClonePagePostsAsync(parent, _context, _transaction); ViewModelHelper.HandleResult(cloneResult, ref result); } // Clone ModulePost from Default culture if (result.IsSucceed) { var cloneResult = await CloneModulePostsAsync(parent, _context, _transaction); ViewModelHelper.HandleResult(cloneResult, ref result); } // Clone PostPost from Default culture if (result.IsSucceed) { var cloneResult = await ClonePostPostsAsync(parent, _context, _transaction); ViewModelHelper.HandleResult(cloneResult, ref result); } // Clone PostMedia from Default culture if (result.IsSucceed) { var cloneResult = await ClonePostMediasAsync(parent, _context, _transaction); ViewModelHelper.HandleResult(cloneResult, ref result); } // Clone PostMedia from Default culture if (result.IsSucceed) { var cloneResult = await CloneUrlAliasAsync(parent, _context, _transaction); ViewModelHelper.HandleResult(cloneResult, ref result); } return(result); }
public override async Task <RepositoryResponse <bool> > RemoveRelatedModelsAsync(DeleteViewModel view, MixCmsContext _context = null, IDbContextTransaction _transaction = null) { RepositoryResponse <bool> result = new RepositoryResponse <bool>() { IsSucceed = true }; if (result.IsSucceed) { var navCate = await _context.MixPagePost.Where(n => n.PostId == Id && n.Specificulture == Specificulture).ToListAsync(); foreach (var item in navCate) { _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; } } if (result.IsSucceed) { var navModule = await _context.MixModulePost.Where(n => n.PostId == Id && n.Specificulture == Specificulture).ToListAsync(); foreach (var item in navModule) { _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; } } if (result.IsSucceed) { var navMedia = await _context.MixPostMedia.Where(n => n.PostId == Id && n.Specificulture == Specificulture).ToListAsync(); foreach (var item in navMedia) { _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; } } if (result.IsSucceed) { var navModule = await _context.MixPostModule.Where(n => n.PostId == Id && n.Specificulture == Specificulture).ToListAsync(); foreach (var item in navModule) { _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; } } if (result.IsSucceed) { var navRelated = await _context.MixPostMedia.Where(n => n.PostId == Id && n.Specificulture == Specificulture).ToListAsync(); foreach (var item in navRelated) { _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; } } if (result.IsSucceed) { var navs = await _context.MixUrlAlias.Where(n => n.SourceId == Id.ToString() && n.Type == (int)MixUrlAliasType.Post && n.Specificulture == Specificulture).ToListAsync(); foreach (var item in navs) { _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; } } if (result.IsSucceed) { var navs = await _context.MixRelatedPost.Where(n => (n.Id == Id || n.DestinationId == Id) && n.Specificulture == Specificulture).ToListAsync(); foreach (var item in navs) { _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; } } if (result.IsSucceed) { var navs = await _context.MixRelatedAttributeData.Where(n => n.ParentId == Id.ToString() && n.ParentType == MixDatabaseParentType.Post && n.Specificulture == Specificulture).ToListAsync(); foreach (var item in navs) { _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; } } await _context.SaveChangesAsync(); var removeRelatedData = await MixRelatedAttributeDatas.Helper.RemoveRelatedDataAsync( Id.ToString(), MixDatabaseParentType.Post , Specificulture , _context, _transaction); ViewModelHelper.HandleResult(removeRelatedData, ref result); return(result); }
private async Task <RepositoryResponse <bool> > ActivedThemeAsync(MixCmsContext _context = null, IDbContextTransaction _transaction = null) { var result = new RepositoryResponse <bool>() { IsSucceed = true }; SystemConfigurationViewModel config = (await SystemConfigurationViewModel.Repository.GetSingleModelAsync( c => c.Keyword == MixAppSettingKeywords.ThemeName && c.Specificulture == Specificulture , _context, _transaction)).Data; if (config == null) { config = new SystemConfigurationViewModel() { Keyword = MixAppSettingKeywords.ThemeName, Specificulture = Specificulture, Category = "Site", DataType = MixDataType.Text, Description = "Cms Theme", Value = Name }; } else { config.Value = Name; } var saveConfigResult = await config.SaveModelAsync(false, _context, _transaction); if (saveConfigResult.IsSucceed) { SystemConfigurationViewModel configFolder = (await SystemConfigurationViewModel.Repository.GetSingleModelAsync( c => c.Keyword == MixAppSettingKeywords.ThemeFolder && c.Specificulture == Specificulture , _context, _transaction)).Data; configFolder.Value = Name; saveConfigResult = await configFolder.SaveModelAsync(false, _context, _transaction); } ViewModelHelper.HandleResult(saveConfigResult, ref result); if (result.IsSucceed) { SystemConfigurationViewModel configId = (await SystemConfigurationViewModel.Repository.GetSingleModelAsync( c => c.Keyword == MixAppSettingKeywords.ThemeId && c.Specificulture == Specificulture, _context, _transaction)).Data; if (configId == null) { configId = new SystemConfigurationViewModel() { Keyword = MixAppSettingKeywords.ThemeId, Specificulture = Specificulture, Category = "Site", DataType = MixDataType.Text, Description = "Cms Theme Id", Value = Model.Id.ToString() }; } else { configId.Value = Model.Id.ToString(); } var saveResult = await configId.SaveModelAsync(false, _context, _transaction); ViewModelHelper.HandleResult(saveResult, ref result); } return(result); }
public override async Task <RepositoryResponse <bool> > SaveSubModelsAsync(MixPage parent, MixCmsContext _context = null, IDbContextTransaction _transaction = null) { var result = new RepositoryResponse <bool> { IsSucceed = true }; // Save Alias //foreach (var item in UrlAliases) //{ // item.SourceId = parent.Id.ToString(); // item.Type = UrlAliasType.Page; // item.Specificulture = parent.Specificulture; // var saveResult = await item.SaveModelAsync(false, _context, _transaction); // ViewModelHelper.HandleResult(saveResult, ref result); // if (!result.IsSucceed) // { // break; // } //} // End Save Alias //Save Module Navigations if (result.IsSucceed) { foreach (var item in ModuleNavs) { if (!MixModules.ImportViewModel.Repository.CheckIsExists(m => m.Name == item.Module.Name && m.Specificulture == parent.Specificulture, _context, _transaction)) { // Force to create new module item.Module.Id = 0; item.Module.Specificulture = parent.Specificulture; var saveModule = await item.Module.SaveModelAsync(true, _context, _transaction); ViewModelHelper.HandleResult(saveModule, ref result); if (!result.IsSucceed) { break; } else // Save Module Success { item.CategoryId = parent.Id; item.ModuleId = saveModule.Data.Id; item.Specificulture = parent.Specificulture; item.Description = saveModule.Data.Title; var saveResult = await item.SaveModelAsync(false, _context, _transaction); ViewModelHelper.HandleResult(saveResult, ref result); if (!result.IsSucceed) { break; } } } } } // End Save Module Navigations /* * // Save Parents Pages * if (result.IsSucceed) * { * foreach (var item in ParentNavs) * { * item.Id = parent.Id; * * var saveResult = await item.SaveModelAsync(false, _context, _transaction); * ViewModelHelper.HandleResult(saveResult, ref result); * * } * } * // End Save Parents Pages * * // Save Children Pages * if (result.IsSucceed) * { * foreach (var item in ChildNavs) * { * item.ParentId = parent.Id; * var saveResult = await item.SaveModelAsync(false, _context, _transaction); * ViewModelHelper.HandleResult(saveResult, ref result); * } * } * // End Save Children Pages*/ return(result); }
public override RepositoryResponse <bool> SaveSubModels( MixPost parent , MixCmsContext _context = null, IDbContextTransaction _transaction = null) { var result = new RepositoryResponse <bool>() { IsSucceed = true }; try { // Save Template var saveTemplate = View.SaveModel(true, _context, _transaction); result.IsSucceed = result.IsSucceed && saveTemplate.IsSucceed; ViewModelHelper.HandleResult(saveTemplate, ref result); if (result.IsSucceed) { // Save Alias result = SaveUrlAlias(parent.Id, _context, _transaction); } if (result.IsSucceed) { // Save Medias result = SaveMedias(parent.Id, _context, _transaction); } //if (result.IsSucceed) //{ // // Save Sub Modules // result = SaveSubModules(parent.Id, _context, _transaction); //} if (result.IsSucceed) { // Save Attributes result = SaveAttribute(parent.Id, _context, _transaction); } if (result.IsSucceed) { // Save related posts result = SaveRelatedPost(parent.Id, _context, _transaction); } if (result.IsSucceed) { // Save Parent Category result = SaveParentPages(parent.Id, _context, _transaction); } if (result.IsSucceed) { // Save Parent Modules result = SaveParentModules(parent.Id, _context, _transaction); } return(result); } catch (Exception ex) // TODO: Add more specific exeption types instead of Exception only { result.IsSucceed = false; result.Exception = ex; return(result); } }
public override async Task <RepositoryResponse <bool> > SaveSubModelsAsync(MixPage parent, MixCmsContext _context = null, IDbContextTransaction _transaction = null) { var result = new RepositoryResponse <bool> { IsSucceed = true }; // Save Alias //foreach (var item in UrlAliases) //{ // item.SourceId = parent.Id.ToString(); // item.Type = UrlAliasType.Page; // item.Specificulture = parent.Specificulture; // var saveResult = await item.SaveModelAsync(false, _context, _transaction); // ViewModelHelper.HandleResult(saveResult, ref result); // if (!result.IsSucceed) // { // break; // } //} // End Save Alias //Save Module Navigations if (result.IsSucceed && ModuleNavs != null) { var startId = MixPageModules.ImportViewModel.Repository.Max(m => m.Id).Data; foreach (var item in ModuleNavs) { if (!MixModules.ImportViewModel.Repository.CheckIsExists(m => m.Name == item.Module.Name && m.Specificulture == parent.Specificulture, _context, _transaction)) { // Force to create new module item.Module.Specificulture = parent.Specificulture; if (!string.IsNullOrEmpty(item.Image)) { item.Image = item.Image.Replace($"content/templates/{ThemeName}", $"content/templates/{MixService.GetConfig<string>("ThemeFolder", parent.Specificulture)}"); } if (!string.IsNullOrEmpty(item.Module.Image)) { item.Module.Image = item.Module.Image.Replace($"content/templates/{ThemeName}", $"content/templates/{MixService.GetConfig<string>("ThemeFolder", parent.Specificulture)}"); } if (!string.IsNullOrEmpty(item.Module.Thumbnail)) { item.Module.Thumbnail = item.Module.Thumbnail.Replace("content/templates/default", $"content/templates/{MixService.GetConfig<string>("ThemeFolder", parent.Specificulture)}"); } var saveModule = await item.Module.SaveModelAsync(true, _context, _transaction); ViewModelHelper.HandleResult(saveModule, ref result); if (!result.IsSucceed) { break; } else // Save Module Success { startId++; item.Id = startId; item.PageId = parent.Id; item.ModuleId = saveModule.Data.Id; item.Specificulture = parent.Specificulture; item.Description = saveModule.Data.Title; item.CreatedDateTime = DateTime.UtcNow; item.CreatedBy = CreatedBy; var saveResult = await item.SaveModelAsync(false, _context, _transaction); ViewModelHelper.HandleResult(saveResult, ref result); if (!result.IsSucceed) { break; } } } } } // End Save Module Navigations /* * // Save Parents Pages * if (result.IsSucceed) * { * foreach (var item in ParentNavs) * { * item.Id = parent.Id; * * var saveResult = await item.SaveModelAsync(false, _context, _transaction); * ViewModelHelper.HandleResult(saveResult, ref result); * } * } * // End Save Parents Pages * * // Save Children Pages * if (result.IsSucceed) * { * foreach (var item in ChildNavs) * { * item.ParentId = parent.Id; * var saveResult = await item.SaveModelAsync(false, _context, _transaction); * ViewModelHelper.HandleResult(saveResult, ref result); * } * } * // End Save Children Pages*/ return(result); }
public override async Task <RepositoryResponse <bool> > RemoveRelatedModelsAsync(UpdateViewModel view, MixCmsContext _context = null, IDbContextTransaction _transaction = null) { string parentId = Id.ToString(); RepositoryResponse <bool> result = new RepositoryResponse <bool>() { IsSucceed = true }; if (result.IsSucceed) { var removeAdditionalData = await MixDatabaseDataAssociations.UpdateViewModel.Repository.RemoveListModelAsync( true, m => m.ParentId == parentId && m.MixDatabaseName == MixDatabaseNames.ADDITIONAL_COLUMN_POST && m.ParentType == MixDatabaseParentType.Post && m.Specificulture == Specificulture, _context, _transaction); ViewModelHelper.HandleResult(removeAdditionalData, ref result); } if (result.IsSucceed) { var navCate = await _context.MixPagePost.Where(n => n.PostId == Id && n.Specificulture == Specificulture).ToListAsync(); foreach (var item in navCate) { _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; } } if (result.IsSucceed) { var navModule = await _context.MixModulePost.Where(n => n.PostId == Id && n.Specificulture == Specificulture).ToListAsync(); foreach (var item in navModule) { _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; } } if (result.IsSucceed) { var navMedia = await _context.MixPostMedia.Where(n => n.PostId == Id && n.Specificulture == Specificulture).ToListAsync(); foreach (var item in navMedia) { _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; } } if (result.IsSucceed) { var navModule = await _context.MixPostModule.Where(n => n.PostId == Id && n.Specificulture == Specificulture).ToListAsync(); foreach (var item in navModule) { _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; } } if (result.IsSucceed) { var navRelated = await _context.MixPostMedia.Where(n => n.PostId == Id && n.Specificulture == Specificulture).ToListAsync(); foreach (var item in navRelated) { _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; } } if (result.IsSucceed) { var navs = await _context.MixUrlAlias.Where(n => n.SourceId == Id.ToString() && n.Type == (int)MixUrlAliasType.Post && n.Specificulture == Specificulture).ToListAsync(); foreach (var item in navs) { _context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; } } await _context.SaveChangesAsync(); return(result); }
public override async Task <RepositoryResponse <bool> > SaveSubModelsAsync( MixPost parent , MixCmsContext _context = null, IDbContextTransaction _transaction = null) { var result = new RepositoryResponse <bool>() { IsSucceed = true }; try { // Save Template if (View.Id == 0) { var saveTemplate = await View.SaveModelAsync(true, _context, _transaction); ViewModelHelper.HandleResult(saveTemplate, ref result); } if (result.IsSucceed) { // Save Alias result = await SaveUrlAliasAsync(parent.Id, _context, _transaction); } if (result.IsSucceed && MediaNavs != null) { // Save Medias result = await SaveMediasAsync(parent.Id, _context, _transaction); } //if (result.IsSucceed) //{ // // Save Sub Modules // result = await SaveSubModulesAsync(parent.Id, _context, _transaction); //} if (result.IsSucceed) { // Save Attributes result = await SaveAttributeAsync(parent.Id, _context, _transaction); } if (result.IsSucceed && PostNavs != null) { // Save related posts result = await SaveRelatedPostAsync(parent.Id, _context, _transaction); } if (result.IsSucceed && Pages != null) { // Save Parent Category result = await SaveParentPagesAsync(parent.Id, _context, _transaction); } if (result.IsSucceed && Modules != null) { // Save Parent Modules result = await SaveParentModulesAsync(parent.Id, _context, _transaction); } return(result); } catch (Exception ex) // TODO: Add more specific exeption types instead of Exception only { result.IsSucceed = false; result.Exception = ex; return(result); } }