protected bool InitPositions(SioCmsContext context, IDbContextTransaction transaction) { bool isSucceed = true; var count = context.SioPortalPage.Count(); if (count == 0) { var p = new SioPosition() { Description = nameof(SioEnums.CatePosition.Nav) }; context.Entry(p).State = EntityState.Added; p = new SioPosition() { Description = nameof(SioEnums.CatePosition.Top) }; context.Entry(p).State = EntityState.Added; p = new SioPosition() { Description = nameof(SioEnums.CatePosition.Left) }; context.Entry(p).State = EntityState.Added; p = new SioPosition() { Description = nameof(SioEnums.CatePosition.Footer) }; context.Entry(p).State = EntityState.Added; context.SaveChanges(); } return(isSucceed); }
protected void InitPages(string culture, SioCmsContext context, IDbContextTransaction transaction) { /* Init Languages */ var pages = FileRepository.Instance.GetFile(SioConstants.CONST_FILE_PAGES, "data", true, "{}"); var obj = JObject.Parse(pages.Content); var arrPage = obj["data"].ToObject <List <SioPage> >(); foreach (var page in arrPage) { page.Specificulture = culture; page.SeoTitle = page.Title.ToLower(); page.SeoName = SeoHelper.GetSEOString(page.Title); page.SeoDescription = page.Title.ToLower(); page.SeoKeywords = page.Title.ToLower(); page.CreatedDateTime = DateTime.UtcNow; page.CreatedBy = "SuperAdmin"; context.Entry(page).State = EntityState.Added; var alias = new SioUrlAlias() { Id = page.Id, SourceId = page.Id.ToString(), Type = (int)UrlAliasType.Page, Specificulture = culture, CreatedDateTime = DateTime.UtcNow, Alias = page.Title.ToLower(), Status = (int)SioContentStatus.Published }; context.Entry(alias).State = EntityState.Added; } }
protected bool InitCultures(InitCulture culture, SioCmsContext context, IDbContextTransaction transaction) { bool isSucceed = true; try { if (context.SioCulture.Count() == 0) { // EN-US var enCulture = new SioCulture() { Specificulture = culture.Specificulture, FullName = culture.FullName, Description = culture.Description, Icon = culture.Icon, Alias = culture.Alias, Status = (int)SioEnums.SioContentStatus.Published }; context.Entry(enCulture).State = EntityState.Added; context.SaveChanges(); } } catch { isSucceed = false; } return(isSucceed); }
public async Task <RepositoryResponse <bool> > InitCms(InitCulture culture) { RepositoryResponse <bool> result = new RepositoryResponse <bool>(); SioCmsContext context = null; SioCmsAccountContext accountContext = null; IDbContextTransaction transaction = null; IDbContextTransaction accTransaction = null; bool isSucceed = true; try { if (!string.IsNullOrEmpty(SioService.GetConnectionString(SioConstants.CONST_CMS_CONNECTION))) { context = new SioCmsContext(); accountContext = new SioCmsAccountContext(); await context.Database.MigrateAsync(); await accountContext.Database.MigrateAsync(); transaction = context.Database.BeginTransaction(); var countCulture = context.SioCulture.Count(); var isInit = countCulture > 0; if (!isInit) { isSucceed = InitCultures(culture, context, transaction); isSucceed = isSucceed && InitPositions(context, transaction); isSucceed = isSucceed && InitThemes(context, transaction); isSucceed = isSucceed && await InitConfigurationsAsync(culture, context, transaction); isSucceed = isSucceed && await InitLanguagesAsync(culture, context, transaction); } else { isSucceed = true; } if (isSucceed && context.SioPage.Count() == 0) { var cate = new SioPage() { Id = 1, Level = 0, Title = "Home", Specificulture = culture.Specificulture, Template = "Pages/_Home.cshtml", Type = (int)SioPageType.Home, CreatedBy = "Admin", CreatedDateTime = DateTime.UtcNow, Status = (int)PageStatus.Published }; context.Entry(cate).State = EntityState.Added; var alias = new SioUrlAlias() { Id = 1, SourceId = "1", Type = (int)UrlAliasType.Page, Specificulture = culture.Specificulture, CreatedDateTime = DateTime.UtcNow, Alias = cate.Title.ToLower() }; context.Entry(alias).State = EntityState.Added; var createVNHome = await context.SaveChangesAsync().ConfigureAwait(false); isSucceed = createVNHome > 0; var cate404 = new SioPage() { Id = 2, Title = "404", Level = 0, Specificulture = culture.Specificulture, Template = "Pages/_404.cshtml", Type = (int)SioPageType.Article, CreatedBy = "Admin", CreatedDateTime = DateTime.UtcNow, Status = (int)PageStatus.Published }; var alias404 = new SioUrlAlias() { Id = 2, SourceId = "2", Type = (int)UrlAliasType.Page, Specificulture = culture.Specificulture, CreatedDateTime = DateTime.UtcNow, Alias = cate404.Title.ToLower() }; context.Entry(cate404).State = EntityState.Added; context.Entry(alias404).State = EntityState.Added; var create404 = await context.SaveChangesAsync().ConfigureAwait(false); isSucceed = create404 > 0; } 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(); } }