Example #1
0
        public async Task <ActionResult <RepositoryResponse <UpdateViewModel> > > DetailsAsync(string viewType, int themeId, string folderType, int?id)
        {
            if (id.HasValue)
            {
                Expression <Func <SioTemplate, bool> > predicate = model => model.Id == id;
                var portalResult = await base.GetSingleAsync <UpdateViewModel>($"{viewType}_{themeId}_{folderType}_{id}", predicate);

                return(Ok(JObject.FromObject(portalResult)));
            }
            else
            {
                var getTheme = await Lib.ViewModels.SioThemes.ReadViewModel.Repository.GetSingleModelAsync(t => t.Id == themeId);

                if (getTheme.IsSucceed)
                {
                    var model = new SioTemplate()
                    {
                        Status     = (int)SioContentStatus.Preview,
                        ThemeId    = themeId,
                        ThemeName  = getTheme.Data.Name,
                        Extension  = SioService.GetConfig <string>("TemplateExtension"),
                        FolderType = folderType
                    };

                    RepositoryResponse <UpdateViewModel> result = await base.GetSingleAsync <UpdateViewModel>($"{viewType}_default", null, model);

                    return(Ok(JObject.FromObject(result)));
                }
                else
                {
                    return(new RepositoryResponse <Lib.ViewModels.SioTemplates.UpdateViewModel>());
                }
            }
        }
Example #2
0
        protected async Task<RepositoryResponse<PaginationModel<TView>>> GetListAsync<TView>(string key, RequestPaging request, Expression<Func<TModel, bool>> predicate = null, TModel model = null)
            where TView : ViewModelBase<TDbContext, TModel, TView>
        {
            var getData = new RepositoryResponse<Lib.ViewModels.SioPages.ReadMvcViewModel>();
            var cacheKey = $"{typeof(TModel).Name}_list_{_lang}_{key}_{request.Status}_{request.Keyword}_{request.OrderBy}_{request.Direction}_{request.PageSize}_{request.PageIndex}_{request.Query}";
            var data = _memoryCache.Get<RepositoryResponse<PaginationModel<TView>>>(cacheKey);
            if (data == null)
            {
                if (predicate != null)
                {
                    data = await DefaultRepository<TDbContext, TModel, TView>.Instance.GetModelListByAsync(predicate, request.OrderBy, request.Direction, request.PageSize, request.PageIndex).ConfigureAwait(false);
                    _memoryCache.Set(cacheKey, data);
                }
                else
                {
                    data = await DefaultRepository<TDbContext, TModel, TView>.Instance.GetModelListAsync(request.OrderBy, request.Direction, request.PageSize, request.PageIndex).ConfigureAwait(false);
                    _memoryCache.Set(cacheKey, data);

                }
                if (!SioConstants.cachedKeys.Contains(cacheKey))
                {
                    SioConstants.cachedKeys.Add(cacheKey);
                }
                AlertAsync("Add Cache", 200, cacheKey);
            }
            data.LastUpdateConfiguration = SioService.GetConfig<DateTime?>("LastUpdateConfiguration");
            //AlertAsync("Get List Page", 200, $"Get {request.Key} list page");
            return data;
        }
Example #3
0
        public async System.Threading.Tasks.Task <IActionResult> Alias(string culture,
                                                                       string alias, int pageIndex, int pageSize = 10)
        {
            string seoName = Request.Query["alias"];

            seoName = seoName ?? alias;
            if (_forbidden)
            {
                return(Redirect($"/error/403"));
            }
            if (SioService.GetConfig <bool>("IsMaintenance"))
            {
                return(Redirect($"/maintenance"));
            }

            if (SioService.GetConfig <bool>("IsInit"))
            {
                //Go to landing page
                return(await AliasAsync(seoName));
            }
            else
            {
                if (string.IsNullOrEmpty(SioService.GetConnectionString(SioConstants.CONST_CMS_CONNECTION)))
                {
                    return(Redirect("Init"));
                }
                else
                {
                    return(Redirect($"/init/step2"));
                }
            }
        }
Example #4
0
        DateTime?PublishArticles()
        {
            var nextSync = SioService.GetConfig <DateTime?>(SioConstants.ConfigurationKeyword.NextSyncContent);

            if (nextSync.HasValue && nextSync.Value <= DateTime.UtcNow)
            {
                var publishedArticles = ReadListItemViewModel.Repository.GetModelListBy(
                    a => a.Status == (int)SioContentStatus.Schedule &&
                    (!a.PublishedDateTime.HasValue || a.PublishedDateTime.Value <= DateTime.UtcNow)
                    );
                publishedArticles.Data.ForEach(a => a.Status = SioContentStatus.Published);
                base.SaveList(publishedArticles.Data, false);
                var next = ReadListItemViewModel.Repository.Min(a => a.Type == (int)SioContentStatus.Schedule,
                                                                a => a.PublishedDateTime);
                nextSync = next.Data;
                SioService.SetConfig(SioConstants.ConfigurationKeyword.NextSyncContent, nextSync);
                SioService.SaveSettings();
                SioService.Reload();
                return(nextSync);
            }
            else
            {
                return(nextSync);
            }
        }
Example #5
0
        public async Task <ActionResult <JObject> > Details(string viewType, int?id)
        {
            string msg = string.Empty;

            switch (viewType)
            {
            case "portal":
                if (id.HasValue)
                {
                    Expression <Func <SioProduct, bool> > predicate = model => model.Id == id && model.Specificulture == _lang;
                    var portalResult = await base.GetSingleAsync <UpdateViewModel>($"{viewType}_{id}", predicate);

                    if (portalResult.IsSucceed)
                    {
                        portalResult.Data.DetailsUrl = SioCmsHelper.GetRouterUrl("Product", new { portalResult.Data.SeoName }, Request, Url);
                    }

                    return(Ok(JObject.FromObject(portalResult)));
                }
                else
                {
                    var model = new SioProduct()
                    {
                        Specificulture = _lang,
                        Status         = SioService.GetConfig <int>("DefaultStatus"),
                        Priority       = UpdateViewModel.Repository.Max(a => a.Priority).Data + 1
                    };

                    RepositoryResponse <UpdateViewModel> result = await base.GetSingleAsync <UpdateViewModel>($"{viewType}_default", null, model);

                    return(Ok(JObject.FromObject(result)));
                }

            default:
                if (id.HasValue)
                {
                    var beResult = await ReadMvcViewModel.Repository.GetSingleModelAsync(model => model.Id == id && model.Specificulture == _lang).ConfigureAwait(false);

                    if (beResult.IsSucceed)
                    {
                        beResult.Data.DetailsUrl = SioCmsHelper.GetRouterUrl("Product", new { beResult.Data.SeoName }, Request, Url);
                    }
                    return(Ok(JObject.FromObject(beResult)));
                }
                else
                {
                    var model = new SioProduct();
                    RepositoryResponse <ReadMvcViewModel> result = new RepositoryResponse <ReadMvcViewModel>()
                    {
                        IsSucceed = true,
                        Data      = new ReadMvcViewModel(model)
                        {
                            Specificulture = _lang,
                            Status         = SioContentStatus.Preview,
                        }
                    };
                    return(Ok(JObject.FromObject(result)));
                }
            }
        }
        public async Task <ActionResult <JObject> > Details(string viewType, int?pageId, int?articleId)
        {
            string msg = string.Empty;

            switch (viewType)
            {
            default:
                if (pageId.HasValue && articleId.HasValue)
                {
                    Expression <Func <SioPageArticle, bool> > predicate = model => model.CategoryId == pageId && model.ArticleId == articleId && model.Specificulture == _lang;
                    var portalResult = await base.GetSingleAsync <ReadViewModel>($"{viewType}_{pageId}_{articleId}", predicate);

                    if (portalResult.IsSucceed)
                    {
                        portalResult.Data.Article.DetailsUrl = SioCmsHelper.GetRouterUrl("Article", new { portalResult.Data.Article.SeoName }, Request, Url);
                    }

                    return(Ok(JObject.FromObject(portalResult)));
                }
                else
                {
                    var model = new SioPageArticle()
                    {
                        Specificulture = _lang,
                        Status         = SioService.GetConfig <int>("DefaultStatus"),
                        Priority       = ReadViewModel.Repository.Max(a => a.Priority).Data + 1
                    };

                    RepositoryResponse <ReadViewModel> result = await base.GetSingleAsync <ReadViewModel>($"{viewType}_default", null, model);

                    return(Ok(JObject.FromObject(result)));
                }
            }
        }
        public RepositoryResponse <JObject> GetGlobalSettings()
        {
            var cultures = CommonRepository.Instance.LoadCultures();
            var culture  = cultures.FirstOrDefault(c => c.Specificulture == _lang);

            // Get Settings
            GlobalSettingsViewModel configurations = new GlobalSettingsViewModel()
            {
                Lang                    = _lang,
                ThemeId                 = SioService.GetConfig <int>(SioConstants.ConfigurationKeyword.ThemeId, _lang),
                ApiEncryptKey           = SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.ApiEncryptKey),
                ApiEncryptIV            = SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.ApiEncryptIV),
                IsEncryptApi            = SioService.GetConfig <bool>(SioConstants.ConfigurationKeyword.IsEncryptApi),
                Cultures                = cultures,
                PageTypes               = Enum.GetNames(typeof(SioPageType)).ToList(),
                ModuleTypes             = Enum.GetNames(typeof(SioModuleType)).ToList(),
                DataTypes               = Enum.GetNames(typeof(SioDataType)).ToList(),
                Statuses                = Enum.GetNames(typeof(SioContentStatus)).ToList(),
                LastUpdateConfiguration = SioService.GetConfig <DateTime?>("LastUpdateConfiguration")
            };

            configurations.LangIcon = culture?.Icon ?? SioService.GetConfig <string>("Language");
            return(new RepositoryResponse <JObject>()
            {
                IsSucceed = true,
                Data = JObject.FromObject(configurations)
            });
        }
Example #8
0
        public async Task <ActionResult <JObject> > Details(string viewType, int?id)
        {
            string msg = string.Empty;

            if (id.HasValue)
            {
                Expression <Func <SioUrlAlias, bool> > predicate = model => model.Id == id;
                var portalResult = await base.GetSingleAsync <UpdateViewModel>($"{viewType}_{id}", predicate);

                return(Ok(JObject.FromObject(portalResult)));
            }
            else
            {
                var model = new SioUrlAlias()
                {
                    Status = SioService.GetConfig <int>("DefaultStatus")
                    ,
                    Priority = UpdateViewModel.Repository.Max(a => a.Priority).Data + 1
                };

                RepositoryResponse <UpdateViewModel> result = await base.GetSingleAsync <UpdateViewModel>($"{viewType}_default", null, model);

                return(Ok(JObject.FromObject(result)));
            }
        }
Example #9
0
 protected void ConfigRoutes(IApplicationBuilder app)
 {
     app.UseMvc(routes =>
     {
         routes.MapRoute(
             name: "default",
             template: "{controller=Home}/{action=Index}/{id?}");
         routes.MapRoute(
             name: "areaRoute",
             template: "{culture=" + SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.DefaultCulture) + "}/{area:exists}/{controller=Portal}/{action=Init}");
         routes.MapRoute(
             name: "alias",
             template: "{culture=" + SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.DefaultCulture) + "}/{seoName}");
         routes.MapRoute(
             name: "page",
             template: "{culture=" + SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.DefaultCulture) + "}/{seoName}");
         routes.MapRoute(
             name: "file",
             template: "{culture=" + SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.DefaultCulture) + "}/portal/file");
         routes.MapRoute(
             name: "article",
             template: "{culture=" + SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.DefaultCulture) + "}/article/{seoName}");
         routes.MapRoute(
             name: "product",
             template: @"{culture=" + SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.DefaultCulture) + @"}/product/{seoName}");
     });
 }
Example #10
0
        protected async Task<RepositoryResponse<TView>> GetSingleAsync<TView>(string key, Expression<Func<TModel, bool>> predicate = null, TModel model = null)
            where TView : ViewModelBase<TDbContext, TModel, TView>
        {
            var getPage = new RepositoryResponse<Lib.ViewModels.SioPages.ReadMvcViewModel>();
            var cacheKey = $"{typeof(TModel).Name}_details_{_lang}_{key}";

            if (!_memoryCache.TryGetValue<RepositoryResponse<TView>>(cacheKey, out RepositoryResponse<TView> data))
            {

                if (predicate != null)
                {
                    data = await DefaultRepository<TDbContext, TModel, TView>.Instance.GetSingleModelAsync(predicate);
                    _memoryCache.Set(cacheKey, data);
                }
                else
                {
                    data = new RepositoryResponse<TView>()
                    {
                        IsSucceed = true,
                        Data = DefaultRepository<TDbContext, TModel, TView>.Instance.ParseView(model)
                    };

                }
                if (!SioConstants.cachedKeys.Contains(cacheKey))
                {
                    SioConstants.cachedKeys.Add(cacheKey);
                }
                AlertAsync("Add Cache", 200, cacheKey);
            }
            data.LastUpdateConfiguration = SioService.GetConfig<DateTime?>("LastUpdateConfiguration");
            return data;
        }
Example #11
0
        public async System.Threading.Tasks.Task <IActionResult> Page(
            string culture, string seoName)
        {
            if (_forbidden)
            {
                return(Redirect($"/error/403"));
            }
            if (SioService.GetConfig <bool>("IsMaintenance"))
            {
                return(Redirect($"/maintenance"));
            }

            if (SioService.GetConfig <bool>("IsInit"))
            {
                //Go to landing page
                return(await PageAsync(seoName));
            }
            else
            {
                if (string.IsNullOrEmpty(SioService.GetConnectionString(SioConstants.CONST_CMS_CONNECTION)))
                {
                    return(Redirect("Init"));
                }
                else
                {
                    return(Redirect($"/init/step2"));
                }
            }
        }
Example #12
0
        public async Task <ActionResult <JObject> > Details(string viewType, int?id)
        {
            string msg = string.Empty;

            switch (viewType)
            {
            case "portal":
                if (id.HasValue)
                {
                    Expression <Func <SioTheme, bool> > predicate = model => model.Id == id;
                    var portalResult = await base.GetSingleAsync <UpdateViewModel>($"{viewType}_{id}", predicate);

                    if (portalResult.IsSucceed)
                    {
                        portalResult.Data.IsActived = SioService.GetConfig <int>(SioConstants.ConfigurationKeyword.ThemeId, _lang) == portalResult.Data.Id;
                    }
                    return(Ok(JObject.FromObject(portalResult)));
                }
                else
                {
                    var model = new SioTheme()
                    {
                        Status = SioService.GetConfig <int>("DefaultStatus")
                        ,
                        Priority = UpdateViewModel.Repository.Max(a => a.Priority).Data + 1
                    };

                    RepositoryResponse <UpdateViewModel> result = await base.GetSingleAsync <UpdateViewModel>($"{viewType}_default", null, model);

                    return(Ok(JObject.FromObject(result)));
                }

            default:
                if (id.HasValue)
                {
                    Expression <Func <SioTheme, bool> > predicate = model => model.Id == id;
                    var result = await base.GetSingleAsync <ReadViewModel>($"{viewType}_{id}", predicate);

                    if (result.IsSucceed)
                    {
                        result.Data.IsActived = SioService.GetConfig <int>(SioConstants.ConfigurationKeyword.ThemeId, _lang) == result.Data.Id;
                    }
                    return(Ok(JObject.FromObject(result)));
                }
                else
                {
                    var model = new SioTheme()
                    {
                        Status = SioService.GetConfig <int>("DefaultStatus")
                        ,
                        Priority = ReadViewModel.Repository.Max(a => a.Priority).Data + 1
                    };

                    RepositoryResponse <ReadViewModel> result = await base.GetSingleAsync <ReadViewModel>($"{viewType}_default", null, model);

                    return(Ok(JObject.FromObject(result)));
                }
            }
        }
Example #13
0
        async System.Threading.Tasks.Task <IActionResult> ArticleViewAsync(int id)
        {
            var getArticle = new RepositoryResponse <Lib.ViewModels.SioArticles.ReadMvcViewModel>();

            var cacheKey = $"article_{_culture}_{id}";

            var data = _memoryCache.Get <Lib.ViewModels.SioArticles.ReadMvcViewModel>(cacheKey);

            if (data != null && SioService.GetConfig <bool>("IsCache"))
            {
                getArticle.IsSucceed = true;
                getArticle.Data      = data;
            }
            else
            {
                Expression <Func <SioArticle, bool> > predicate;

                predicate = p =>
                            p.Id == id &&
                            p.Status == (int)SioContentStatus.Published &&
                            p.Specificulture == _culture;

                getArticle = await Lib.ViewModels.SioArticles.ReadMvcViewModel.Repository.GetSingleModelAsync(predicate);

                if (getArticle.IsSucceed)
                {
                    getArticle.Data.DetailsUrl = GenerateDetailsUrl("Article", new { id = getArticle.Data.Id, seoName = getArticle.Data.SeoName });
                    //Generate details url for related articles
                    if (getArticle.Data.ArticleNavs != null && getArticle.Data.ArticleNavs.Count > 0)
                    {
                        getArticle.Data.ArticleNavs.ForEach(n => n.RelatedArticle.DetailsUrl = GenerateDetailsUrl("Article", new { id = n.RelatedArticle.Id, seoName = n.RelatedArticle.SeoName }));
                    }
                    _memoryCache.Set(cacheKey, getArticle.Data);
                }
                if (!SioConstants.cachedKeys.Contains(cacheKey))
                {
                    SioConstants.cachedKeys.Add(cacheKey);
                }
            }

            if (getArticle.IsSucceed)
            {
                ViewData["TopPages"]    = GetCategory(CatePosition.Nav, getArticle.Data.SeoName);
                ViewData["HeaderPages"] = GetCategory(CatePosition.Top, getArticle.Data.SeoName);
                ViewData["FooterPages"] = GetCategory(CatePosition.Footer, getArticle.Data.SeoName);
                ViewData["LeftPages"]   = GetCategory(CatePosition.Left, getArticle.Data.SeoName);

                ViewData["Title"]                  = getArticle.Data.SeoTitle;
                ViewData["Description"]            = getArticle.Data.SeoDescription;
                ViewData["Keywords"]               = getArticle.Data.SeoKeywords;
                ViewData["Image"]                  = getArticle.Data.ImageUrl;
                getArticle.LastUpdateConfiguration = SioService.GetConfig <DateTime?>("LastUpdateConfiguration");
                return(View(getArticle.Data));
            }
            else
            {
                return(Redirect($"/error/404"));
            }
        }
Example #14
0
        List <Lib.ViewModels.SioPages.ReadListItemViewModel> GetCategory(SioEnums.CatePosition position, string seoName)
        {
            var result   = new List <Lib.ViewModels.SioPages.ReadListItemViewModel>();
            var cacheKey = $"page_position_{position}";

            var data = _memoryCache.Get <List <Lib.ViewModels.SioPages.ReadListItemViewModel> >(cacheKey);

            if (data != null && SioService.GetConfig <bool>("IsCache"))
            {
                result = data;
            }
            else
            {
                var getTopCates = Lib.ViewModels.SioPages.ReadListItemViewModel.Repository.GetModelListBy
                                      (c => c.Specificulture == _culture && c.SioPagePosition.Any(
                                          p => p.PositionId == (int)position)
                                      );

                result = getTopCates.Data ?? new List <Lib.ViewModels.SioPages.ReadListItemViewModel>();
                foreach (var cate in result)
                {
                    switch (cate.Type)
                    {
                    case SioPageType.Blank:
                        foreach (var child in cate.Childs)
                        {
                            child.Page.DetailsUrl = GenerateDetailsUrl("Page", new { seoName = child.Page.SeoName });
                        }
                        break;

                    case SioPageType.StaticUrl:
                        cate.DetailsUrl = cate.StaticUrl;
                        break;

                    case SioPageType.Home:
                    case SioPageType.ListArticle:
                    case SioPageType.Article:
                    case SioPageType.Modules:
                    default:
                        cate.DetailsUrl = GenerateDetailsUrl("Page", new { seoName = cate.SeoName });
                        break;
                    }
                }
            }

            foreach (var cate in result)
            {
                cate.IsActived = (cate.SeoName == seoName ||
                                  (cate.Type == SioPageType.Home && string.IsNullOrEmpty(seoName)));
                cate.Childs.ForEach((Action <Lib.ViewModels.SioPagePages.ReadViewModel>)(c =>
                {
                    c.IsActived = (
                        c.Page.SeoName == seoName);
                    cate.IsActived = cate.IsActived || c.IsActived;
                }));
            }
            return(result);
        }
Example #15
0
        async System.Threading.Tasks.Task <IActionResult> ProductViewAsync(string seoName)
        {
            ViewData["TopPages"]    = GetCategory(CatePosition.Nav, seoName);
            ViewData["HeaderPages"] = GetCategory(CatePosition.Top, seoName);
            ViewData["FooterPages"] = GetCategory(CatePosition.Footer, seoName);
            ViewData["LeftPages"]   = GetCategory(CatePosition.Left, seoName);
            var getProduct = new RepositoryResponse <Lib.ViewModels.SioProducts.ReadMvcViewModel>();

            var cacheKey = $"product_{_culture}_{seoName}";

            var data = _memoryCache.Get <Lib.ViewModels.SioProducts.ReadMvcViewModel>(cacheKey);

            if (data != null && SioService.GetConfig <bool>("IsCache"))
            {
                getProduct.IsSucceed = true;
                getProduct.Data      = data;
            }
            else
            {
                Expression <Func <SioProduct, bool> > predicate;
                if (string.IsNullOrEmpty(seoName))
                {
                    predicate = p =>
                                p.Type == (int)SioPageType.Home &&
                                p.Status == (int)SioContentStatus.Published && p.Specificulture == _culture;
                }
                else
                {
                    predicate = p =>
                                p.SeoName == seoName &&
                                p.Status == (int)SioContentStatus.Published && p.Specificulture == _culture;
                }

                getProduct = await Lib.ViewModels.SioProducts.ReadMvcViewModel.Repository.GetSingleModelAsync(predicate);

                _memoryCache.Set(cacheKey, getProduct.Data);
                if (!SioConstants.cachedKeys.Contains(cacheKey))
                {
                    SioConstants.cachedKeys.Add(cacheKey);
                }
            }

            if (getProduct.IsSucceed)
            {
                ViewData["Title"]                  = getProduct.Data.SeoTitle;
                ViewData["Description"]            = getProduct.Data.SeoDescription;
                ViewData["Keywords"]               = getProduct.Data.SeoKeywords;
                ViewData["Image"]                  = getProduct.Data.ImageUrl;
                getProduct.LastUpdateConfiguration = SioService.GetConfig <DateTime?>("LastUpdateConfiguration");
                return(View(getProduct.Data));
            }
            else
            {
                return(RedirectToAction("PageNotFound", "Home"));
            }
        }
Example #16
0
        public void LoadDataByTag(string tagName
                                  , string orderBy, int orderDirection
                                  , int?pageSize           = null, int?pageIndex = null
                                  , SioCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            UnitOfWorkHelper <SioCmsContext> .InitTransaction(_context, _transaction, out SioCmsContext context, out IDbContextTransaction transaction, out bool isRoot);

            try
            {
                pageSize  = pageSize > 0 ? pageSize : PageSize;
                pageIndex = pageIndex ?? 0;
                Expression <Func <SioArticle, bool> > articleExp = null;
                JObject obj = new JObject(new JProperty("text", tagName));

                articleExp = n => n.Tags.Contains(obj.ToString(Newtonsoft.Json.Formatting.None)) && n.Specificulture == Specificulture;

                if (articleExp != null)
                {
                    var getArticles = SioArticles.ReadListItemViewModel.Repository
                                      .GetModelListBy(articleExp
                                                      , SioService.GetConfig <string>(orderBy), 0
                                                      , pageSize, pageIndex
                                                      , _context: context, _transaction: transaction);
                    if (getArticles.IsSucceed)
                    {
                        Articles.Items      = new List <SioPageArticles.ReadViewModel>();
                        Articles.PageIndex  = getArticles.Data.PageIndex;
                        Articles.PageSize   = getArticles.Data.PageSize;
                        Articles.TotalItems = getArticles.Data.TotalItems;
                        Articles.TotalPage  = getArticles.Data.TotalPage;
                        foreach (var article in getArticles.Data.Items)
                        {
                            Articles.Items.Add(new SioPageArticles.ReadViewModel()
                            {
                                CategoryId = Id,
                                ArticleId  = article.Id,
                                Article    = article
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                UnitOfWorkHelper <SioCmsContext> .HandleException <PaginationModel <ReadMvcViewModel> >(ex, isRoot, transaction);
            }
            finally
            {
                if (isRoot)
                {
                    //if current Context is Root
                    context.Dispose();
                }
            }
        }
Example #17
0
        public static UpdateViewModel GetTemplateByPath(string path, string specificulture, SioEnums.EnumTemplateFolder folderType, SioCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            string templateName = path?.Split('/')[1];
            int    themeId      = SioService.GetConfig <int>(SioConstants.ConfigurationKeyword.ThemeId, specificulture);
            string themeName    = SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.ThemeName, specificulture);
            var    getView      = UpdateViewModel.Repository.GetSingleModel(t =>
                                                                            t.ThemeId == themeId && t.FolderType == folderType.ToString() &&
                                                                            !string.IsNullOrEmpty(templateName) && templateName.Equals($"{t.FileName}{t.Extension}"), _context, _transaction);

            return(getView.Data ?? GetDefault(folderType, specificulture));
        }
Example #18
0
        async System.Threading.Tasks.Task <IActionResult> AliasAsync(string seoName)
        {
            // Home Page
            int.TryParse(Request.Query["pageSize"], out int pageSize);
            int.TryParse(Request.Query["pageIndex"], out int pageIndex);
            var getAlias = new RepositoryResponse <Lib.ViewModels.SioUrlAliases.UpdateViewModel>();
            var cacheKey = $"alias_{_culture}_{seoName}_{pageSize}_{pageIndex}";

            var data = _memoryCache.Get <Lib.ViewModels.SioUrlAliases.UpdateViewModel>(cacheKey);

            if (data != null && SioService.GetConfig <bool>("IsCache"))
            {
                getAlias.IsSucceed = true;
                getAlias.Data      = data;
            }
            else
            {
                Expression <Func <SioUrlAlias, bool> > predicate;

                predicate = p =>
                            p.Alias == seoName &&
                            p.Status == (int)SioContentStatus.Published && p.Specificulture == _culture;

                getAlias = await Lib.ViewModels.SioUrlAliases.UpdateViewModel.Repository.GetSingleModelAsync(predicate);

                _memoryCache.Set(cacheKey, getAlias.Data);
                if (!SioConstants.cachedKeys.Contains(cacheKey))
                {
                    SioConstants.cachedKeys.Add(cacheKey);
                }
            }

            if (getAlias.IsSucceed)// && getPage.Data.View != null
            {
                switch (getAlias.Data.Type)
                {
                case UrlAliasType.Page:
                    return(await PageAsync(int.Parse(getAlias.Data.SourceId)));

                case UrlAliasType.Article:
                    return(await ArticleViewAsync(int.Parse(getAlias.Data.SourceId)));

                case UrlAliasType.Product:
                case UrlAliasType.Module:
                case UrlAliasType.ModuleData:
                default:
                    return(await PageError());
                }
            }
            else
            {
                return(await PageAsync(seoName));
            }
        }
Example #19
0
 public IActionResult Init(string page)
 {
     if (string.IsNullOrEmpty(page) && SioService.GetConfig <bool>("IsInit"))
     {
         return(Redirect($"/init/login"));
     }
     else
     {
         return(View());
     }
 }
Example #20
0
        private RepositoryResponse <JObject> getAllSettings()
        {
            var cultures = CommonRepository.Instance.LoadCultures();
            var culture  = cultures.FirstOrDefault(c => c.Specificulture == _lang);

            // Get Settings
            GlobalSettingsViewModel configurations = new GlobalSettingsViewModel()
            {
                Domain                  = SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.Domain),
                Lang                    = _lang,
                ThemeId                 = SioService.GetConfig <int>(SioConstants.ConfigurationKeyword.ThemeId, _lang),
                ApiEncryptKey           = SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.ApiEncryptKey),
                ApiEncryptIV            = SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.ApiEncryptIV),
                IsEncryptApi            = SioService.GetConfig <bool>(SioConstants.ConfigurationKeyword.IsEncryptApi),
                Cultures                = cultures,
                PageTypes               = Enum.GetNames(typeof(SioPageType)).ToList(),
                ModuleTypes             = Enum.GetNames(typeof(SioModuleType)).ToList(),
                DataTypes               = Enum.GetNames(typeof(SioDataType)).ToList(),
                Statuses                = Enum.GetNames(typeof(SioContentStatus)).ToList(),
                LastUpdateConfiguration = SioService.GetConfig <DateTime?>("LastUpdateConfiguration")
            };

            configurations.LangIcon = culture?.Icon ?? SioService.GetConfig <string>("Language");

            // Get translator
            var translator = new JObject()
            {
                new JProperty("lang", _lang),
                new JProperty("data", SioService.GetTranslator(_lang))
            };

            // Get Configurations
            var settings = new JObject()
            {
                new JProperty("lang", _lang),
                new JProperty("langIcon", configurations.LangIcon),

                new JProperty("data", SioService.GetLocalSettings(_lang))
            };
            JObject result = new JObject()
            {
                new JProperty("globalSettings", JObject.FromObject(configurations)),
                new JProperty("translator", translator),
                new JProperty("settings", JObject.FromObject(settings))
            };

            return(new RepositoryResponse <JObject>()
            {
                IsSucceed = true,
                Data = result
            });
        }
Example #21
0
        public async Task <ActionResult <JObject> > Details(string viewType, string keyword)
        {
            string msg = string.Empty;

            switch (viewType)
            {
            case "portal":
                if (!string.IsNullOrEmpty(keyword))
                {
                    Expression <Func <SioConfiguration, bool> > predicate = model => model.Keyword == keyword && model.Specificulture == _lang;
                    var portalResult = await base.GetSingleAsync <UpdateViewModel>($"{viewType}_{keyword}", predicate);

                    return(Ok(JObject.FromObject(portalResult)));
                }
                else
                {
                    var model = new SioConfiguration()
                    {
                        Specificulture = _lang,
                        Category       = "Site",
                        Status         = SioService.GetConfig <int>("DefaultStatus"),
                        Priority       = UpdateViewModel.Repository.Max(a => a.Priority).Data + 1
                    };

                    RepositoryResponse <UpdateViewModel> result = await base.GetSingleAsync <UpdateViewModel>($"{viewType}_default", null, model);

                    return(Ok(JObject.FromObject(result)));
                }

            default:
                if (!string.IsNullOrEmpty(keyword))
                {
                    var beResult = await ReadMvcViewModel.Repository.GetSingleModelAsync(model => model.Keyword == keyword && model.Specificulture == _lang).ConfigureAwait(false);

                    return(Ok(JObject.FromObject(beResult)));
                }
                else
                {
                    var model = new SioConfiguration();
                    RepositoryResponse <ReadMvcViewModel> result = new RepositoryResponse <ReadMvcViewModel>()
                    {
                        IsSucceed = true,
                        Data      = new ReadMvcViewModel(model)
                        {
                            Specificulture = _lang,
                            Status         = SioContentStatus.Preview,
                        }
                    };
                    return(Ok(JObject.FromObject(result)));
                }
            }
        }
 public static ReadListItemViewModel GetDefault(string activedTemplate, string folderType, string folder, string specificulture)
 {
     return(new ReadListItemViewModel(new SioTemplate()
     {
         Extension = SioService.GetConfig <string>("TemplateExtension"),
         ThemeId = SioService.GetConfig <int>(SioConstants.ConfigurationKeyword.ThemeId, specificulture),
         ThemeName = activedTemplate,
         FolderType = folderType,
         FileFolder = folder,
         FileName = SioService.GetConfig <string>("DefaultTemplate"),
         Content = "<div></div>"
     }));
 }
 public override void ExpandView(SioCmsContext _context = null, IDbContextTransaction _transaction = null)
 {
     Domain = SioService.GetConfig <string>("Domain", Specificulture) ?? "/";
     if (Image != null && (Image.IndexOf("http") == -1 && Image[0] != '/'))
     {
         ImageUrl = CommonHelper.GetFullPath(new string[] {
             Domain, Image
         });
     }
     else
     {
         ImageUrl = Image;
     }
 }
Example #24
0
        protected void ConfigRoutes(IApplicationBuilder app)
        {
            if (SioService.GetConfig <bool>("IsRewrite"))
            {
                using (StreamReader apacheModRewriteStreamReader =
                           File.OpenText("ApacheModRewrite.txt"))
                    using (StreamReader iisUrlRewriteStreamReader =
                               File.OpenText("IISUrlRewrite.xml"))
                    {
                        var options = new RewriteOptions()
                                      .AddRedirect("redirect-rule/(.*)", "redirected/$1")
                                      .AddRewrite(@"^rewrite-rule/(\d+)/(\d+)", "rewritten?var1=$1&var2=$2",
                                                  skipRemainingRules: true)
                                      .AddApacheModRewrite(apacheModRewriteStreamReader)
                                      .AddIISUrlRewrite(iisUrlRewriteStreamReader)
                                      .Add(MethodRules.RedirectXMLRequests);
                        //.Add(new RedirectImageRequests(".png", "/png-images"))
                        //.Add(new RedirectImageRequests(".jpg", "/jpg-images"));

                        app.UseRewriter(options);
                    }
                //    app.Run(context => context.Response.WriteAsync(
                //$"Rewritten or Redirected Url: " +
                //$"{context.Request.Path + context.Request.QueryString}"));
            }
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
                routes.MapRoute(
                    name: "areaRoute",
                    template: "{culture=" + SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.DefaultCulture) + "}/{area:exists}/{controller=Portal}/{action=Init}");
                routes.MapRoute(
                    name: "alias",
                    template: "{culture=" + SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.DefaultCulture) + "}/{seoName}");
                routes.MapRoute(
                    name: "page",
                    template: "{culture=" + SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.DefaultCulture) + "}/{seoName}");
                routes.MapRoute(
                    name: "file",
                    template: "{culture=" + SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.DefaultCulture) + "}/portal/file");
                routes.MapRoute(
                    name: "article",
                    template: "{culture=" + SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.DefaultCulture) + "}/article/{id}/{seoName}");
                routes.MapRoute(
                    name: "product",
                    template: @"{culture=" + SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.DefaultCulture) + @"}/product/{seoName}");
            });
        }
Example #25
0
        private void GetSubProducts(SioCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            var getProducts = SioPageProducts.ReadViewModel.Repository.GetModelListBy(
                m => m.CategoryId == Id && m.Specificulture == Specificulture
                , SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.OrderBy), 0
                , PageSize, 0
                , _context: _context, _transaction: _transaction
                );

            if (getProducts.IsSucceed)
            {
                Products = getProducts.Data;
            }
        }
Example #26
0
        private void GetSubArticles(SioCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            var getArticles = SioPageArticles.ReadViewModel.Repository.GetModelListBy(
                n => n.CategoryId == Id && n.Specificulture == Specificulture,
                SioService.GetConfig <string>(SioConstants.ConfigurationKeyword.OrderBy), 0
                , 4, 0
                , _context: _context, _transaction: _transaction
                );

            if (getArticles.IsSucceed)
            {
                Articles = getArticles.Data;
            }
        }
Example #27
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app)
        {
            if (_env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }
            if (SioService.GetConfig <bool>("IsHttps"))
            {
                app.UseHttpsRedirection();
            }
            app.UseCors(opt =>
            {
                opt.AllowAnyOrigin();
                opt.AllowAnyHeader();
                opt.AllowAnyMethod();
            });

            var cachePeriod = _env.IsDevelopment() ? "600" : "604800";

            app.UseStaticFiles(new StaticFileOptions
            {
                OnPrepareResponse = ctx =>
                {
                    // Requires the following import:
                    // using Microsoft.AspNetCore.Http;
                    ctx.Context.Response.Headers.Append("Cache-Control", $"public, max-age={cachePeriod}");
                }
            });
            app.UseCookiePolicy();
            app.UseSignalR(route =>
            {
                route.MapHub <PortalHub>("/portalhub");
                route.MapHub <SioChatHub>("/SioChatHub");
            });

            app.UseAuthentication();
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Sio API V1");
            });

            ConfigRoutes(app);
        }
Example #28
0
        private async Task <RepositoryResponse <bool> > CreateDefaultThemeTemplatesAsync(SioCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            var result = new RepositoryResponse <bool>()
            {
                IsSucceed = true
            };
            string defaultFolder = $"{SioService.GetConfig<string>(SioConstants.ConfigurationKeyword.DefaultBlankTemplateFolder) }";

            //CommonHelper.GetFullPath(new string[] {
            //    SioConstants.Folder.TemplatesFolder,
            //    SioService.GetConfig<string>(SioConstants.ConfigurationKeyword.DefaultTemplateFolder) });
            bool copyResult = FileRepository.Instance.CopyDirectory(defaultFolder, TemplateFolder);

            var files = FileRepository.Instance.GetFilesWithContent(TemplateFolder);
            var id    = _context.SioTemplate.Count() + 1;

            //TODO: Create default asset
            foreach (var file in files)
            {
                SioTemplates.InitViewModel template = new SioTemplates.InitViewModel(
                    new SioTemplate()
                {
                    Id              = id,
                    FileFolder      = file.FileFolder,
                    FileName        = file.Filename,
                    Content         = file.Content,
                    Extension       = file.Extension,
                    CreatedDateTime = DateTime.UtcNow,
                    LastModified    = DateTime.UtcNow,
                    ThemeId         = Model.Id,
                    ThemeName       = Model.Name,
                    FolderType      = file.FolderName,
                    ModifiedBy      = CreatedBy
                }, _context, _transaction);
                var saveResult = await template.SaveModelAsync(true, _context, _transaction);

                ViewModelHelper.HandleResult(saveResult, ref result);
                if (!result.IsSucceed)
                {
                    break;
                }
                else
                {
                    id += 1;
                }
            }
            return(result);
        }
Example #29
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            string cnn = SioService.GetConnectionString(SioConstants.CONST_CMS_CONNECTION);

            if (!string.IsNullOrEmpty(cnn))
            {
                if (SioService.GetConfig <int>(SioConstants.CONST_SETTING_DATABASE_PROVIDER) == (int)SioEnums.DatabaseProvider.MySQL)
                {
                    optionsBuilder.UseMySQL(cnn);
                }
                else
                {
                    optionsBuilder.UseSqlServer(cnn);
                }
            }
        }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            string cnn = SioService.GetConnectionString(SioConstants.CONST_CMS_CONNECTION);

            if (!string.IsNullOrEmpty(cnn))
            {
                if (SioService.GetConfig <bool>("IsSqlite"))
                {
                    optionsBuilder.UseSqlite(cnn);
                }
                else
                {
                    optionsBuilder.UseSqlServer(cnn);
                }
            }
        }