Ejemplo n.º 1
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)));
                }
            }
        }
Ejemplo n.º 2
0
        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)));
                }
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <JObject> > GetList(
            [FromBody] RequestPaging request)
        {
            var  query     = HttpUtility.ParseQueryString(request.Query ?? "");
            bool isPage    = int.TryParse(query.Get("page_id"), out int pageId);
            bool isArticle = int.TryParse(query.Get("article_id"), out int articleId);

            ParseRequestPagingDate(request);
            Expression <Func <SioPageArticle, bool> > predicate = model =>
                                                                  model.Specificulture == _lang &&
                                                                  (!isPage || model.CategoryId == pageId) &&
                                                                  (!isArticle || model.ArticleId == articleId) &&
                                                                  (!request.Status.HasValue || model.Status == request.Status.Value) &&
                                                                  (string.IsNullOrWhiteSpace(request.Keyword) ||
                                                                   (model.Description.Contains(request.Keyword)
                                                                   ))
            ;
            string key = $"{request.Key}_{request.Query}_{request.PageSize}_{request.PageIndex}";

            switch (request.Key)
            {
            default:
                var listItemResult = await base.GetListAsync <ReadViewModel>(key, request, predicate);

                listItemResult.Data.Items.ForEach(n => n.IsActived          = true);
                listItemResult.Data.Items.ForEach(n => n.Article.DetailsUrl = SioCmsHelper.GetRouterUrl(
                                                      "article", new { id = n.Article.Id, seoName = n.Article.SeoName }, Request, Url));
                return(JObject.FromObject(listItemResult));
            }
        }
Ejemplo n.º 4
0
        public async Task <RepositoryResponse <PaginationModel <UserInfoViewModel> > > GetList(RequestPaging request)
        {
            Expression <Func <SioCmsUser, bool> > predicate = model =>
                                                              (!request.Status.HasValue || model.Status == request.Status.Value) &&
                                                              (string.IsNullOrWhiteSpace(request.Keyword) ||
                                                               (
                                                                   model.Username.Contains(request.Keyword) ||
                                                                   model.FirstName.Contains(request.Keyword) ||
                                                                   model.LastName.Contains(request.Keyword)
                                                               )
                                                              ) &&
                                                              (!request.FromDate.HasValue ||
                                                               (model.CreatedDateTime >= request.FromDate.Value.ToUniversalTime())
                                                              ) &&
                                                              (!request.ToDate.HasValue ||
                                                               (model.CreatedDateTime <= request.ToDate.Value.ToUniversalTime())
                                                              );

            var data = await UserInfoViewModel.Repository.GetModelListByAsync(predicate, request.OrderBy, request.Direction, request.PageSize, request.PageIndex).ConfigureAwait(false);

            if (data.IsSucceed)
            {
                data.Data.Items.ForEach(a =>
                {
                    a.DetailsUrl = SioCmsHelper.GetRouterUrl(
                        "Profile", new { a.Id }, Request, Url);
                }
                                        );
            }
            return(data);
        }
Ejemplo n.º 5
0
        public async Task <RepositoryResponse <string> > TranslateUrlAsync(string culture, string type, int id)
        {
            switch (type)
            {
            case "Article":
                var getArticle = await Lib.ViewModels.SioArticles.ReadListItemViewModel.Repository.GetSingleModelAsync(
                    a => a.Id == id && a.Specificulture == culture);

                if (getArticle.IsSucceed)
                {
                    return(new RepositoryResponse <string>()
                    {
                        IsSucceed = getArticle.IsSucceed,
                        Data = SioCmsHelper.GetRouterUrl("Article", new { id = getArticle.Data.Id, getArticle.Data.SeoName }, Request, Url)
                    });
                }
                else
                {
                    return(new RepositoryResponse <string>()
                    {
                        IsSucceed = getArticle.IsSucceed,
                        Data = $"/{culture}"
                    });
                }

            case "Page":
                var getPage = await Lib.ViewModels.SioPages.ReadListItemViewModel.Repository.GetSingleModelAsync(
                    a => a.Id == id && a.Specificulture == culture);

                if (getPage.IsSucceed)
                {
                    return(new RepositoryResponse <string>()
                    {
                        IsSucceed = getPage.IsSucceed,
                        Data = SioCmsHelper.GetRouterUrl("Page", new { getPage.Data.SeoName }, Request, Url)
                    });
                }
                else
                {
                    return(new RepositoryResponse <string>()
                    {
                        IsSucceed = true,
                        Data = $"/{culture}"
                    });
                }

            default:
                return(new RepositoryResponse <string>()
                {
                    IsSucceed = true,
                    Data = $"/{culture}"
                });
            }
        }
Ejemplo n.º 6
0
        public async Task <ActionResult <JObject> > GetList(
            [FromBody] RequestPaging request)
        {
            var  parsed  = HttpUtility.ParseQueryString(request.Query ?? "");
            bool isLevel = int.TryParse(parsed.Get("level"), out int level);

            ParseRequestPagingDate(request);
            Expression <Func <SioProduct, bool> > predicate = model =>
                                                              model.Specificulture == _lang &&
                                                              (!request.Status.HasValue || model.Status == request.Status.Value) &&
                                                              (string.IsNullOrWhiteSpace(request.Keyword) ||
                                                               (model.Title.Contains(request.Keyword) ||
                                                                model.Excerpt.Contains(request.Keyword))) &&
                                                              (!request.FromDate.HasValue ||
                                                               (model.CreatedDateTime >= request.FromDate.Value)
                                                              ) &&
                                                              (!request.ToDate.HasValue ||
                                                               (model.CreatedDateTime <= request.ToDate.Value)
                                                              );
            string key = $"{request.Key}_{request.PageSize}_{request.PageIndex}";

            switch (request.Key)
            {
            case "mvc":
                var mvcResult = await base.GetListAsync <ReadMvcViewModel>(key, request, predicate);

                if (mvcResult.IsSucceed)
                {
                    mvcResult.Data.Items.ForEach(a =>
                    {
                        a.DetailsUrl = SioCmsHelper.GetRouterUrl(
                            "product", new { seoName = a.SeoName }, Request, Url);
                    });
                }

                return(Ok(JObject.FromObject(mvcResult)));

            case "portal":
                var portalResult = await base.GetListAsync <UpdateViewModel>(key, request, predicate);

                if (portalResult.IsSucceed)
                {
                    portalResult.Data.Items.ForEach(a =>
                    {
                        a.DetailsUrl = SioCmsHelper.GetRouterUrl(
                            "product", new { seoName = a.SeoName }, Request, Url);
                    });
                }

                return(Ok(JObject.FromObject(portalResult)));

            default:

                var listItemResult = await base.GetListAsync <ReadListItemViewModel>(key, request, predicate);

                if (listItemResult.IsSucceed)
                {
                    listItemResult.Data.Items.ForEach((Action <ReadListItemViewModel>)(a =>
                    {
                        a.DetailsUrl = SioCmsHelper.GetRouterUrl(
                            "product", new { seoName = a.SeoName }, Request, Url);
                    }));
                }

                return(JObject.FromObject(listItemResult));
            }
        }
Ejemplo n.º 7
0
 string GenerateDetailsUrl(string type, object routeValues)
 {
     return(SioCmsHelper.GetRouterUrl(type, routeValues, Request, Url));
 }
Ejemplo n.º 8
0
        public async Task <ActionResult <JObject> > GetList(
            [FromBody] RequestPaging request)
        {
            var  query       = HttpUtility.ParseQueryString(request.Query ?? "");
            bool isPage      = int.TryParse(query.Get("page_id"), out int pageId);
            bool isNotPage   = int.TryParse(query.Get("not_page_id"), out int notPageId);
            bool isModule    = int.TryParse(query.Get("module_id"), out int moduleId);
            bool isNotModule = int.TryParse(query.Get("not_module_id"), out int notModuleId);

            ParseRequestPagingDate(request);
            Expression <Func <SioArticle, bool> > predicate = model =>
                                                              model.Specificulture == _lang &&
                                                              (!request.Status.HasValue || model.Status == request.Status.Value) &&
                                                              (!isPage || model.SioPageArticle.Any(nav => nav.CategoryId == pageId && nav.ArticleId == model.Id && nav.Specificulture == _lang)) &&
                                                              (!isNotPage || !model.SioPageArticle.Any(nav => nav.CategoryId == notPageId && nav.ArticleId == model.Id && nav.Specificulture == _lang)) &&
                                                              (!isModule || model.SioModuleArticle.Any(nav => nav.ModuleId == moduleId && nav.ArticleId == model.Id)) &&
                                                              (!isNotModule || !model.SioModuleArticle.Any(nav => nav.ModuleId == notModuleId && nav.ArticleId == model.Id)) &&
                                                              (string.IsNullOrWhiteSpace(request.Keyword) ||
                                                               (model.Title.Contains(request.Keyword) ||
                                                                model.Excerpt.Contains(request.Keyword))) &&
                                                              (!request.FromDate.HasValue ||
                                                               (model.CreatedDateTime >= request.FromDate.Value)
                                                              ) &&
                                                              (!request.ToDate.HasValue ||
                                                               (model.CreatedDateTime <= request.ToDate.Value)
                                                              );

            var    nextSync = PublishArticles();
            string key      = $"{nextSync}_{request.Key}_{request.Query}_{request.PageSize}_{request.PageIndex}";

            switch (request.Key)
            {
            case "mvc":
                var mvcResult = await base.GetListAsync <ReadMvcViewModel>(key, request, predicate);

                if (mvcResult.IsSucceed)
                {
                    mvcResult.Data.Items.ForEach(a =>
                    {
                        a.DetailsUrl = SioCmsHelper.GetRouterUrl(
                            "Article", new { id = a.Id, seoName = a.SeoName }, Request, Url);
                    });
                }

                return(Ok(JObject.FromObject(mvcResult)));

            case "portal":
                var portalResult = await base.GetListAsync <UpdateViewModel>(key, request, predicate);

                if (portalResult.IsSucceed)
                {
                    portalResult.Data.Items.ForEach(a =>
                    {
                        a.DetailsUrl = SioCmsHelper.GetRouterUrl(
                            "Article", new { id = a.Id, seoName = a.SeoName }, Request, Url);
                    });
                }

                return(Ok(JObject.FromObject(portalResult)));

            default:

                var listItemResult = await base.GetListAsync <ReadListItemViewModel>(key, request, predicate);

                if (listItemResult.IsSucceed)
                {
                    listItemResult.Data.Items.ForEach((Action <ReadListItemViewModel>)(a =>
                    {
                        a.DetailsUrl = SioCmsHelper.GetRouterUrl(
                            "Article", new { id = a.Id, seoName = a.SeoName }, Request, Url);
                    }));
                }

                return(JObject.FromObject(listItemResult));
            }
        }
Ejemplo n.º 9
0
        public RepositoryResponse <FileViewModel> SiteMap()
        {
            try
            {
                var root = new XElement("urlset",
                                        new XAttribute("xlmns", @"http://www.sitemaps.org/schemas/sitemap/0.9")
                                        );
                var        pages         = Lib.ViewModels.SioPages.ReadListItemViewModel.Repository.GetModelList();
                List <int> handledPageId = new List <int>();
                foreach (var page in pages.Data)
                {
                    page.DetailsUrl = SioCmsHelper.GetRouterUrl(
                        "page", new { seoName = page.SeoName, culture = page.Specificulture }, Request, Url);
                    var otherLanguages = pages.Data.Where(p => p.Id == page.Id && p.Specificulture != page.Specificulture);
                    var lstOther       = new List <SitemapLanguage>();
                    foreach (var item in otherLanguages)
                    {
                        lstOther.Add(new SitemapLanguage()
                        {
                            HrefLang = item.Specificulture,
                            Href     = SioCmsHelper.GetRouterUrl(
                                "page", new { seoName = page.SeoName, culture = item.Specificulture }, Request, Url)
                        });
                    }

                    var sitemap = new SiteMap()
                    {
                        ChangeFreq     = "monthly",
                        LastMod        = DateTime.UtcNow,
                        Loc            = page.DetailsUrl,
                        Priority       = 0.3,
                        OtherLanguages = lstOther
                    };
                    root.Add(sitemap.ParseXElement());
                }

                var articles = Lib.ViewModels.SioArticles.ReadListItemViewModel.Repository.GetModelList();
                foreach (var article in articles.Data)
                {
                    article.DetailsUrl = SioCmsHelper.GetRouterUrl(
                        "article", new { seoName = article.SeoName, culture = article.Specificulture }, Request, Url);
                    var otherLanguages = pages.Data.Where(p => p.Id == article.Id && p.Specificulture != article.Specificulture);
                    var lstOther       = new List <SitemapLanguage>();
                    foreach (var item in otherLanguages)
                    {
                        lstOther.Add(new SitemapLanguage()
                        {
                            HrefLang = item.Specificulture,
                            Href     = SioCmsHelper.GetRouterUrl(
                                "page", new { seoName = article.SeoName, culture = item.Specificulture }, Request, Url)
                        });
                    }
                    var sitemap = new SiteMap()
                    {
                        ChangeFreq     = "monthly",
                        LastMod        = DateTime.UtcNow,
                        Loc            = article.DetailsUrl,
                        OtherLanguages = lstOther,
                        Priority       = 0.3
                    };
                    root.Add(sitemap.ParseXElement());
                }

                string folder = $"Sitemaps";
                FileRepository.Instance.CreateDirectoryIfNotExist(folder);
                string filename = $"sitemap";
                string filePath = $"wwwroot/{folder}/{filename}.xml";
                root.Save(filePath);
                return(new RepositoryResponse <FileViewModel>()
                {
                    IsSucceed = true,
                    Data = new FileViewModel()
                    {
                        Extension = ".xml",
                        Filename = filename,
                        FileFolder = folder
                    }
                });
            }
            catch (Exception ex)
            {
                return(new RepositoryResponse <FileViewModel>()
                {
                    Exception = ex
                });
            }
        }