public async Task <JObject> BEDetails(string viewType, int?id) { switch (viewType) { case "be": if (id.HasValue) { var beResult = await BECategoryViewModel.Repository.GetSingleModelAsync(model => model.Id == id && model.Specificulture == _lang).ConfigureAwait(false); if (beResult.IsSucceed) { beResult.Data.DetailsUrl = SwCmsHelper.GetRouterUrl("Page", new { beResult.Data.SeoName }, Request, Url); } return(JObject.FromObject(beResult)); } else { var model = new SiocCategory() { Specificulture = _lang, Status = (int)SWStatus.Preview }; RepositoryResponse <BECategoryViewModel> result = new RepositoryResponse <BECategoryViewModel>() { IsSucceed = true, Data = await BECategoryViewModel.InitAsync(model) }; return(JObject.FromObject(result)); } default: if (id.HasValue) { var beResult = await FECategoryViewModel.Repository.GetSingleModelAsync(model => model.Id == id && model.Specificulture == _lang).ConfigureAwait(false); if (beResult.IsSucceed) { beResult.Data.DetailsUrl = SwCmsHelper.GetRouterUrl("Page", new { beResult.Data.SeoName }, Request, Url); } return(JObject.FromObject(beResult)); } else { var model = new SiocCategory(); RepositoryResponse <FECategoryViewModel> result = new RepositoryResponse <FECategoryViewModel>() { IsSucceed = true, Data = new FECategoryViewModel(model) { Specificulture = _lang, Status = SWStatus.Preview } }; return(JObject.FromObject(result)); } } }
public async Task <ActionResult <JObject> > Details(string viewType, int?id) { switch (viewType) { case "be": if (id.HasValue) { var beResult = await ApiCategoryViewModel.Repository.GetSingleModelAsync(model => model.Id == id && model.Specificulture == _lang).ConfigureAwait(false); if (beResult.IsSucceed) { beResult.Data.DetailsUrl = SwCmsHelper.GetRouterUrl("Alias", new { beResult.Data.SeoName }, Request, Url); } return(Ok(JObject.FromObject(beResult))); } else { var model = new SiocCategory() { Specificulture = _lang, Status = GlobalConfigurationService.Instance.CmsConfigurations.DefaultStatus, PageSize = 20 , Priority = ApiCategoryViewModel.Repository.Max(a => a.Priority).Data + 1 }; RepositoryResponse <ApiCategoryViewModel> result = new RepositoryResponse <ApiCategoryViewModel>() { IsSucceed = true, Data = await ApiCategoryViewModel.InitViewAsync(model) }; return(JObject.FromObject(result)); } default: if (id.HasValue) { var beResult = await FECategoryViewModel.Repository.GetSingleModelAsync(model => model.Id == id && model.Specificulture == _lang).ConfigureAwait(false); if (beResult.IsSucceed) { beResult.Data.DetailsUrl = SwCmsHelper.GetRouterUrl("Alias", new { beResult.Data.SeoName }, Request, Url); } return(JObject.FromObject(beResult)); } else { var model = new SiocCategory(); RepositoryResponse <FECategoryViewModel> result = new RepositoryResponse <FECategoryViewModel>() { IsSucceed = true, Data = new FECategoryViewModel(model) { Specificulture = _lang, Status = SWStatus.Preview, PageSize = 20 } }; return(JObject.FromObject(result)); } } }
public override async Task <RepositoryResponse <bool> > SaveSubModelsAsync(SiocCulture parent, SiocCmsContext _context = null, IDbContextTransaction _transaction = null) { var result = new RepositoryResponse <bool>() { IsSucceed = true }; if (Id == 0) { var getPages = await InfoCategoryViewModel.Repository.GetModelListByAsync(c => c.Specificulture == GlobalConfigurationService.Instance.CmsConfigurations.Language, _context, _transaction); if (getPages.IsSucceed) { foreach (var p in getPages.Data) { var page = new SiocCategory() { Specificulture = Specificulture, Id = p.Id, Content = p.Content, CreatedBy = p.CreatedBy, CreatedDateTime = DateTime.UtcNow, Layout = p.Layout, CssClass = p.CssClass, Excerpt = p.Specificulture, Icon = p.Specificulture, Image = p.Specificulture, Level = p.Level, ModifiedBy = p.ModifiedBy, PageSize = p.PageSize, Priority = p.Priority.HasValue ? p.Priority.Value : 0, SeoDescription = p.SeoDescription, SeoKeywords = p.SeoKeywords, SeoName = p.SeoName, SeoTitle = p.SeoTitle, StaticUrl = p.StaticUrl, Status = (int)p.Status, Tags = p.Tags, Template = p.Template, Title = p.Title, Type = (int)p.Type, }; if (p.UrlAlias != null) { var alias = new SiocUrlAlias() { Id = p.UrlAlias.Id, Specificulture = Specificulture, CreatedDateTime = DateTime.UtcNow, SourceId = p.Id.ToString(), Alias = p.UrlAlias.Alias, Description = p.UrlAlias.Description, Status = (int)p.UrlAlias.Status, Type = (int)p.UrlAlias.Type }; _context.Entry(alias).State = Microsoft.EntityFrameworkCore.EntityState.Added; } _context.Entry(page).State = Microsoft.EntityFrameworkCore.EntityState.Added; } } var getConfigurations = await ApiConfigurationViewModel.Repository.GetModelListByAsync(c => c.Specificulture == GlobalConfigurationService.Instance.CmsConfigurations.Language, _context, _transaction); if (getConfigurations.IsSucceed) { foreach (var c in getConfigurations.Data) { var cnf = new SiocConfiguration() { Keyword = c.Keyword, Specificulture = Specificulture, Category = c.Category, DataType = (int)c.DataType, Description = c.Description, Priority = c.Priority.HasValue ? c.Priority.Value : 0, Status = (int)c.Status, Value = c.Value }; _context.Entry(cnf).State = Microsoft.EntityFrameworkCore.EntityState.Added; } } var getLanguages = await ApiLanguageViewModel.Repository.GetModelListByAsync(c => c.Specificulture == GlobalConfigurationService.Instance.CmsConfigurations.Language, _context, _transaction); if (getLanguages.IsSucceed) { foreach (var c in getLanguages.Data) { var cnf = new SiocLanguage() { Keyword = c.Keyword, Specificulture = Specificulture, Category = c.Category, DataType = (int)c.DataType, Description = c.Description, Priority = c.Priority.HasValue ? c.Priority.Value : 0, Status = (int)c.Status, DefaultValue = c.DefaultValue }; _context.Entry(cnf).State = Microsoft.EntityFrameworkCore.EntityState.Added; } } _context.SaveChanges(); } return(result); }
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) { var cate = new SiocCategory() { Id = 1, Level = 0, Title = "Home", Specificulture = culture.Specificulture, Template = "Pages/_Home.cshtml", Type = (int)SWCmsConstants.CateType.Home, CreatedBy = "Admin", CreatedDateTime = DateTime.UtcNow, Status = (int)SWStatus.Published }; context.Entry(cate).State = EntityState.Added; var alias = new SiocUrlAlias() { Id = 1, SourceId = "1", Type = (int)SWCmsConstants.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 SiocCategory() { Id = 2, Title = "404", Level = 0, Specificulture = culture.Specificulture, Template = "Pages/_404.cshtml", Type = (int)SWCmsConstants.CateType.Article, CreatedBy = "Admin", CreatedDateTime = DateTime.UtcNow, Status = (int)SWStatus.Published }; var alias404 = new SiocUrlAlias() { Id = 2, SourceId = "2", Type = (int)SWCmsConstants.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(); } }