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 <RepositoryResponse <BECategoryViewModel> > Post([FromBody] BECategoryViewModel model) { if (model != null) { var result = await model.SaveModelAsync(true).ConfigureAwait(false); return(result); } return(new RepositoryResponse <BECategoryViewModel>()); }
public IActionResult Create() { //ViewData["Specificulture"] = new SelectList(_context.TtsCulture, "Specificulture", "Specificulture"); var ttsMenu = new BECategoryViewModel(new SiocCategory() { Specificulture = CurrentLanguage, CreatedBy = User.Identity.Name, //CreatedDate = DateTime.UtcNow }); return(View(ttsMenu)); }
public async Task <RepositoryResponse <BECategoryViewModel> > Post([FromBody] BECategoryViewModel model) { if (model != null) { var result = await model.SaveModelAsync(true).ConfigureAwait(false); if (result.IsSucceed) { result.Data.Domain = this._domain; } return(result); } return(new RepositoryResponse <BECategoryViewModel>()); }
public async Task <IActionResult> Create(BECategoryViewModel menu) { if (ModelState.IsValid) { var result = await menu.SaveModelAsync(true).ConfigureAwait(false); if (result.IsSucceed) { return(RedirectToAction("Index")); } else { return(View(menu)); } } return(View(menu)); }
public async Task <IActionResult> Edit(int id, BECategoryViewModel ttsMenu) { if (id != ttsMenu.Id) { return(NotFound()); } if (ModelState.IsValid) { try { var result = await ttsMenu.SaveModelAsync(true).ConfigureAwait(false); if (result.IsSucceed) { return(RedirectToAction("Index")); } else { ModelState.AddModelError(string.Empty, result.Exception.Message); return(View(ttsMenu)); } } catch (DbUpdateConcurrencyException) { if (!BECategoryViewModel.Repository.CheckIsExists( m => m.Id == ttsMenu.Id)) { return(NotFound()); } else { throw; } } //return RedirectToAction("Index"); } ViewData["Action"] = "Edit"; ViewData["Controller"] = "Pages"; return(View(ttsMenu)); }
public void InitSWCms() { SiocCmsContext context = null; SiocCmsAccountContext accountContext = null; IDbContextTransaction transaction = null; try { if (InitConnectionString()) { context = new SiocCmsContext(); accountContext = new SiocCmsAccountContext(); context.Database.Migrate(); accountContext.Database.Migrate(); transaction = context.Database.BeginTransaction(); bool isSucceed = true; //var getConnectionString = BEParameterViewModel.Repository.GetSingleModel( // c => c.Name == SWCmsConstants.ConfigurationKeyword.ConnectionString, // _context: context, _transaction: transaction); //if (!getConnectionString.IsSucceed) //{ // BEParameterViewModel cnn = new BEParameterViewModel() // { // Name = SWCmsConstants.ConfigurationKeyword.ConnectionString, // Value = ConnectionString, // Description = SWCmsConstants.ConfigurationType.System // }; // cnn.SaveModel(_context: context, _transaction: transaction); //} // EN-US var getCulture = BECultureViewModel.Repository.GetSingleModel( c => c.Specificulture == "en-us", _context: context, _transaction: transaction); if (!getCulture.IsSucceed) { BECultureViewModel cultureViewModel = new BECultureViewModel() { Specificulture = "en-us", FullName = "United States", Description = "United States", Icon = "flag-icon-us", Alias = "US" }; isSucceed = isSucceed && cultureViewModel.SaveModel(_context: context, _transaction: transaction).IsSucceed; } // VI-VN getCulture = BECultureViewModel.Repository.GetSingleModel( c => c.Specificulture == "vi-vn", _context: context, _transaction: transaction); if (!getCulture.IsSucceed) { BECultureViewModel cultureViewModel = new BECultureViewModel() { Specificulture = "vi-vn", FullName = "Vietnam", Description = "Việt Nam", Icon = "flag-icon-vn", Alias = "VN" }; isSucceed = isSucceed && cultureViewModel.SaveModel(_context: context, _transaction: transaction).IsSucceed; } var getPosition = BEPositionViewModel.Repository.GetModelList(_context: context, _transaction: transaction); if (isSucceed && (!getPosition.IsSucceed || getPosition.Data.Count == 0)) { BEPositionViewModel p = new BEPositionViewModel() { Description = nameof(SWCmsConstants.CatePosition.Nav) }; isSucceed = isSucceed && p.SaveModel(_context: context, _transaction: transaction).IsSucceed; p = new BEPositionViewModel() { Description = nameof(SWCmsConstants.CatePosition.Top) }; isSucceed = isSucceed && p.SaveModel(_context: context, _transaction: transaction).IsSucceed; p = new BEPositionViewModel() { Description = nameof(SWCmsConstants.CatePosition.Left) }; isSucceed = isSucceed && p.SaveModel(_context: context, _transaction: transaction).IsSucceed; p = new BEPositionViewModel() { Description = nameof(SWCmsConstants.CatePosition.Footer) }; isSucceed = isSucceed && p.SaveModel(_context: context, _transaction: transaction).IsSucceed; } var getThemes = BEThemeViewModel.Repository.GetModelList(_context: context, _transaction: transaction); if (isSucceed && getThemes.IsSucceed) { if (getThemes.Data.Count == 0) { BEThemeViewModel theme = new BEThemeViewModel(new SiocTheme() { Name = "Default", CreatedBy = "Admin" }) { IsActived = true, Specificulture = "vi-vn" }; isSucceed = isSucceed && theme.SaveModel(true, context, transaction).IsSucceed; if (isSucceed) { ConfigurationViewModel config = (ConfigurationViewModel.Repository.GetSingleModel( c => c.Keyword == SWCmsConstants.ConfigurationKeyword.Theme && c.Specificulture == "vi-vn", context, transaction)).Data; if (config == null) { config = new ConfigurationViewModel() { Keyword = SWCmsConstants.ConfigurationKeyword.Theme, Specificulture = "vi-vn", Category = SWCmsConstants.ConfigurationType.User, DataType = SWCmsConstants.DataType.String, Description = "Cms Theme", Value = "" }; } else { config.Value = theme.Name; } isSucceed = isSucceed && config.SaveModel(false, context, transaction).IsSucceed; } if (isSucceed) { ConfigurationViewModel config = (ConfigurationViewModel.Repository.GetSingleModel( c => c.Keyword == SWCmsConstants.ConfigurationKeyword.ThemeId && c.Specificulture == "vi-vn", context, transaction)).Data; if (config == null) { config = new ConfigurationViewModel() { Keyword = SWCmsConstants.ConfigurationKeyword.Theme, Specificulture = "vi-vn", Category = SWCmsConstants.ConfigurationType.User, DataType = SWCmsConstants.DataType.String, Description = "Cms Theme", Value = theme.Model.Id.ToString() }; } else { config.Value = theme.Model.Id.ToString(); } isSucceed = isSucceed && config.SaveModel(false, context, transaction).IsSucceed; } if (isSucceed) { ConfigurationViewModel config = (ConfigurationViewModel.Repository.GetSingleModel( c => c.Keyword == SWCmsConstants.ConfigurationKeyword.Theme && c.Specificulture == "en-us", context, transaction)).Data; if (config == null) { config = new ConfigurationViewModel() { Keyword = SWCmsConstants.ConfigurationKeyword.Theme, Specificulture = "en-us", Category = SWCmsConstants.ConfigurationType.User, DataType = SWCmsConstants.DataType.String, Description = "Cms Theme", Value = theme.Name }; } else { config.Value = Name; } isSucceed = isSucceed && config.SaveModel(false, context, transaction).IsSucceed; } if (isSucceed) { ConfigurationViewModel config = (ConfigurationViewModel.Repository.GetSingleModel( c => c.Keyword == SWCmsConstants.ConfigurationKeyword.ThemeId && c.Specificulture == "en-us", context, transaction)).Data; if (config == null) { config = new ConfigurationViewModel() { Keyword = SWCmsConstants.ConfigurationKeyword.ThemeId, Specificulture = "en-us", Category = SWCmsConstants.ConfigurationType.User, DataType = SWCmsConstants.DataType.String, Description = "Cms Theme", Value = theme.Model.Id.ToString() }; } else { config.Value = theme.Model.Id.ToString(); } isSucceed = isSucceed && config.SaveModel(false, context, transaction).IsSucceed; } if (isSucceed) { InitConfigurations(context, transaction); } } else { foreach (var theme in getThemes.Data) { string folderPath = CommonHelper.GetFullPath(new string[] { SWCmsConstants.Parameters.TemplatesFolder, theme.Name }); var delFolder = FileRepository.Instance.DeleteFolder(folderPath); foreach (var item in theme.Templates) { try { isSucceed = isSucceed && item.SaveModel(true, _context: context, _transaction: transaction).IsSucceed; } catch { } } } } } if (isSucceed) { BECategoryViewModel cate = new BECategoryViewModel(new SiocCategory() { Title = "Home", Specificulture = "vi-vn", Template = "_Home", Type = (int)SWCmsConstants.CateType.Home, CreatedBy = "Admin" }); isSucceed = isSucceed && cate.SaveModel(false, context, transaction).IsSucceed; BECategoryViewModel uscate = new BECategoryViewModel(new SiocCategory() { Title = "Home", Specificulture = "en-us", Template = "_Home", Type = (int)SWCmsConstants.CateType.Home, CreatedBy = "Admin" }); isSucceed = isSucceed && uscate.SaveModel(false, context, transaction).IsSucceed; } if (isSucceed) { GlobalLanguageService.Instance.RefreshCultures(context, transaction); transaction.Commit(); IsInit = true; } else { transaction.Rollback(); IsInit = false; } } } catch (Exception ex) // TODO: Add more specific exeption types instead of Exception only { IsInit = false; transaction?.Rollback(); throw ex; } finally { context?.Dispose(); accountContext?.Dispose(); } }
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) { BECategoryViewModel cate = new BECategoryViewModel(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); isSucceed = createVNHome.IsSucceed; //BECategoryViewModel uscate = new BECategoryViewModel(new SiocCategory() //{ // Id = cate.Model.Id, // Title = "Home", // Specificulture = "en-us", // Template = "_Home", // Type = (int)SWCmsConstants.CateType.Home, // CreatedBy = "Admin", // CreatedDateTime = DateTime.UtcNow, //}, context, transaction); //var createUSHome = await uscate.SaveModelAsync(false, context, transaction).ConfigureAwait(false); //isSucceed = createUSHome.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(); } }
public async Task <RepositoryResponse <bool> > InitSWCms(UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager) { 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 getCulture = await BECultureViewModel.Repository.GetModelListAsync(_context : context, _transaction : transaction); var isInit = getCulture.IsSucceed && getCulture.Data.Count > 0; if (!isInit) { isSucceed = InitCultures(context, transaction); isSucceed = isSucceed && InitPositions(context, transaction); isSucceed = isSucceed && InitThemes(context, transaction); isSucceed = isSucceed && InitConfigurations(context, transaction); } else { isSucceed = true; } if (isSucceed && BECategoryViewModel.Repository.Count(context, transaction).Data == 0) { BECategoryViewModel cate = new BECategoryViewModel(new SiocCategory() { Title = "Home", Specificulture = "vi-vn", Template = "_Home", Type = (int)SWCmsConstants.CateType.Home, CreatedBy = "Admin" }, context, transaction); isSucceed = cate.SaveModel(false, context, transaction).IsSucceed; BECategoryViewModel uscate = new BECategoryViewModel(new SiocCategory() { Title = "Home", Specificulture = "en-us", Template = "_Home", Type = (int)SWCmsConstants.CateType.Home, CreatedBy = "Admin", }, context, transaction); isSucceed = isSucceed && uscate.SaveModel(false, context, transaction).IsSucceed; } if (isSucceed) { GlobalConfigurationService.Instance.RefreshAll(context, transaction); 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(); } }