public override void ExpandView(SiocCmsContext _context = null, IDbContextTransaction _transaction = null) { UrlAlias = ApiUrlAliasViewModel.Repository.GetSingleModel(u => u.Specificulture == Specificulture && u.SourceId == Id.ToString()).Data; if (UrlAlias == null) { UrlAlias = new ApiUrlAliasViewModel() { Specificulture = Specificulture, Alias = SeoName }; } this.View = FETemplateViewModel.GetTemplateByPath(Template, Specificulture, _context, _transaction).Data; if (View != null) { switch (Type) { case CateType.Home: GetSubModules(_context, _transaction); break; case CateType.Blank: break; case CateType.Article: break; case CateType.Modules: GetSubModules(_context, _transaction); break; case CateType.List: GetSubArticles(_context, _transaction); break; case CateType.ListProduct: GetSubProducts(_context, _transaction); break; default: break; } } }
public async Task <RepositoryResponse <bool> > InitSWCms(InitCulture culture) { RepositoryResponse <bool> result = new RepositoryResponse <bool>(); SiocCmsContext context = null; SiocCmsAccountContext accountContext = null; IDbContextTransaction transaction = null; IDbContextTransaction accTransaction = null; bool isSucceed = true; try { if (!string.IsNullOrEmpty(CmsConfigurations.CmsConnectionString)) { context = new SiocCmsContext(); accountContext = new SiocCmsAccountContext(); await context.Database.MigrateAsync(); await accountContext.Database.MigrateAsync(); transaction = context.Database.BeginTransaction(); var countCulture = context.SiocCulture.Count(); var isInit = countCulture > 0; if (!isInit) { isSucceed = InitCultures(culture, context, transaction); isSucceed = isSucceed && InitPositions(context, transaction); isSucceed = isSucceed && InitThemes(context, transaction); isSucceed = isSucceed && InitConfigurations(culture, context, transaction); } else { isSucceed = true; } if (isSucceed && BECategoryViewModel.Repository.Count(context, transaction).Data == 0) { ApiCategoryViewModel cate = new ApiCategoryViewModel(new SiocCategory() { Title = "Home", Specificulture = culture.Specificulture, Template = "_Home", Type = (int)SWCmsConstants.CateType.Home, CreatedBy = "Admin" }, context, transaction); var createVNHome = await cate.SaveModelAsync(false, context, transaction).ConfigureAwait(false); ApiUrlAliasViewModel UrlAlias = new ApiUrlAliasViewModel(new SiocUrlAlias() { Specificulture = culture.Specificulture, Alias = cate.SeoName, SourceId = createVNHome.Data.Model.Id.ToString() }); var createAlias = await UrlAlias.SaveModelAsync(false, context, transaction).ConfigureAwait(false); isSucceed = createVNHome.IsSucceed && createAlias.IsSucceed; } if (isSucceed) { transaction.Commit(); } else { transaction.Rollback(); } } result.IsSucceed = isSucceed; return(result); } catch (Exception ex) // TODO: Add more specific exeption types instead of Exception only { transaction?.Rollback(); accTransaction?.Rollback(); result.IsSucceed = false; result.Exception = ex; return(result); } finally { context?.Dispose(); accountContext?.Dispose(); } }