public async Task <RepositoryResponse <string> > TranslateUrlAsync(string culture, string type, int id)
        {
            switch (type)
            {
            case "Post":
                var getPost = await Lib.ViewModels.MixPosts.ReadListItemViewModel.Repository.GetSingleModelAsync(
                    a => a.Id == id && a.Specificulture == culture);

                if (getPost.IsSucceed)
                {
                    return(new RepositoryResponse <string>()
                    {
                        IsSucceed = getPost.IsSucceed,
                        Data = MixCmsHelper.GetRouterUrl(new { action = "post", culture = _lang, id = getPost.Data.Id, getPost.Data.SeoName }, Request, Url)
                    });
                }
                else
                {
                    return(new RepositoryResponse <string>()
                    {
                        IsSucceed = getPost.IsSucceed,
                        Data = $"/{culture}"
                    });
                }

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

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

            default:
                return(new RepositoryResponse <string>()
                {
                    IsSucceed = true,
                    Data = $"/{culture}"
                });
            }
        }
        public override void ExpandView(MixCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            var countPost = MixPagePosts.ReadViewModel.Repository.Count(c => c.PageId == Id && c.Specificulture == Specificulture
                                                                        , _context: _context, _transaction: _transaction);

            if (countPost.IsSucceed)
            {
                TotalPost = countPost.Data;
            }

            DetailsUrl = Id > 0
                   ? MixCmsHelper.GetDetailsUrl(Specificulture, $"/{MixService.GetConfig("PageController", Specificulture, "page")}/{Id}/{SeoName}")
                   : null;
        }
Example #3
0
        public override void ExpandView(MixCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            Cultures = LoadCultures(Specificulture, _context, _transaction);

            StrNormalPrice = MixCmsHelper.FormatPrice(NormalPrice);
            StrDealPrice   = MixCmsHelper.FormatPrice(DealPrice);
            StrImportPrice = MixCmsHelper.FormatPrice(ImportPrice);

            if (!string.IsNullOrEmpty(this.Tags))
            {
                ListTag = JArray.Parse(this.Tags);
            }
            Properties = new List <ExtraProperty>();
            if (!string.IsNullOrEmpty(ExtraProperties))
            {
                JArray arr = JArray.Parse(ExtraProperties);
                foreach (JToken item in arr)
                {
                    Properties.Add(item.ToObject <ExtraProperty>());
                }
            }

            //Get Templates
            this.Templates = this.Templates ?? MixTemplates.UpdateViewModel.Repository.GetModelListBy(
                t => t.Theme.Name == ActivedTheme && t.FolderType == this.TemplateFolderType).Data;
            View = MixTemplates.UpdateViewModel.GetTemplateByPath(Template, Specificulture, MixEnums.EnumTemplateFolder.Products, _context, _transaction);

            this.View = View ?? Templates.FirstOrDefault();

            if (this.View == null)
            {
                this.View = MixTemplates.UpdateViewModel.GetDefault(MixEnums.EnumTemplateFolder.Products, Specificulture);
            }

            this.Template = CommonHelper.GetFullPath(new string[]
            {
                this.View?.FileFolder
                , this.View?.FileName
            });

            var getProductMedia = MixProductMedias.ReadViewModel.Repository.GetModelListBy(n => n.ProductId == Id && n.Specificulture == Specificulture, _context, _transaction);

            if (getProductMedia.IsSucceed)
            {
                MediaNavs = getProductMedia.Data.OrderBy(p => p.Priority).ToList();
                MediaNavs.ForEach(n => n.IsActived = true);
            }

            ProductNavs = GetRelated(_context, _transaction);
        }
Example #4
0
        public Site(string culture, IUrlHelper urlHelper)
        {
            Url            = MixService.GetConfig <string>("Domain");
            Title          = MixService.GetConfig <string>("SiteTitle", culture);
            Title          = MixService.GetConfig <string>("SiteTitle", culture);
            Logo           = MixService.GetConfig <string>("SiteLogo", culture);
            Description    = MixService.GetConfig <string>("SiteDescription", culture);
            CoverImage     = MixService.GetConfig <string>("SiteCoverImage", culture);
            IsAllowMembers = MixService.GetConfig <bool>("IsRegistration");

            Navigation          = MixCmsHelper.GetNavigation("navigation", culture, urlHelper);
            SecondaryNavigation = MixCmsHelper.GetNavigation("secondary_navigation", culture, urlHelper);
            SocialNavigation    = MixCmsHelper.GetNavigation("social_navigation", culture, urlHelper);
        }
Example #5
0
 public override void ExpandView(MixCmsContext _context = null, IDbContextTransaction _transaction = null)
 {
     this.View = MixTemplates.ReadListItemViewModel.GetTemplateByPath(Template, Specificulture, _context, _transaction).Data;
     if (View != null)
     {
         GetSubModules(_context, _transaction);
     }
     LoadAttributes(_context, _transaction);
     UrlAliases = GetAliases(_context, _transaction);
     DetailsUrl = UrlAliases.Count > 0
       ? MixCmsHelper.GetDetailsUrl(Specificulture, $"/{UrlAliases[0].Alias}")
       : Id > 0
           ? MixCmsHelper.GetDetailsUrl(Specificulture, $"/{SeoName}")
           : null;
 }
Example #6
0
 public override MixCmsUser ParseModel(MixCmsContext _context = null, IDbContextTransaction _transaction = null)
 {
     if (MediaFile.FileStream != null)
     {
         MediaFile.FileFolder = MixCmsHelper.GetUploadFolder(Specificulture);
         var isSaved = MixFileRepository.Instance.SaveWebFile(MediaFile);
         if (isSaved)
         {
             Avatar = MediaFile.FullPath;
         }
         else
         {
             IsValid = false;
         }
     }
     return(base.ParseModel(_context, _transaction));
 }
Example #7
0
        public override void ExpandView(MixCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            UrlAliases = GetAliases(_context, _transaction);

            var countPost = MixPagePosts.ReadViewModel.Repository.Count(c => c.PageId == Id && c.Specificulture == Specificulture
                                                                        , _context: _context, _transaction: _transaction);

            if (countPost.IsSucceed)
            {
                TotalPost = countPost.Data;
            }

            DetailsUrl = UrlAliases.Count > 0
             ? MixCmsHelper.GetDetailsUrl(Specificulture, $"/{UrlAliases[0].Alias}")
             : Id > 0
                 ? MixCmsHelper.GetDetailsUrl(Specificulture, $"/{SeoName}")
                 : null;
        }
Example #8
0
        public override void ExpandView(MixCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            Cultures = Helper.LoadCultures(Id, Specificulture, _context, _transaction);
            if (!string.IsNullOrEmpty(this.Tags))
            {
                ListTag = JArray.Parse(this.Tags);
            }

            // Load page views
            this.Templates = MixTemplates.UpdateViewModel.Repository.GetModelListBy(
                t => t.Theme.Id == ActivedTheme && t.FolderType == this.TemplateFolderType, _context, _transaction).Data;
            var templateName = Template?.Substring(Template.LastIndexOf('/') + 1) ?? MixConstants.DefaultTemplate.Page;

            this.View = Templates.FirstOrDefault(t => !string.IsNullOrEmpty(templateName) && templateName.Equals($"{t.FileName}{t.Extension}"));
            if (this.View == null)
            {
                this.View = Templates.FirstOrDefault(t => MixConstants.DefaultTemplate.Module.Equals($"{t.FileName}{t.Extension}"));
            }
            this.View?.SetMediator(this);
            this.Template = $"{View?.FileFolder}/{View?.FileName}{View.Extension}";
            // Load Attributes
            // Load master views
            this.Masters = MixTemplates.UpdateViewModel.Repository.GetModelListBy(
                t => t.Theme.Id == ActivedTheme && t.FolderType == MixTemplateFolders.Masters.ToString(), _context, _transaction).Data;
            var masterName = Layout?.Substring(Layout.LastIndexOf('/') + 1) ?? MixConstants.DefaultTemplate.Master;

            this.Master = Masters.FirstOrDefault(t => !string.IsNullOrEmpty(masterName) && masterName.Equals($"{t.FileName}{t.Extension}"));
            if (this.Master == null)
            {
                this.Master = Masters.FirstOrDefault(t => MixConstants.DefaultTemplate.Master.Equals($"{t.FileName}{t.Extension}"));
            }
            this.Layout = $"{Master?.FileFolder}/{Master?.FileName}{Master?.Extension}";

            this.ModuleNavs = GetModuleNavs(_context, _transaction);
            this.UrlAliases = GetAliases(_context, _transaction);

            DetailsUrl = Id > 0
                   ? MixCmsHelper.GetDetailsUrl(Specificulture, $"/{MixService.GetConfig("PageController", Specificulture, "page")}/{Id}/{SeoName}")
                   : null;
        }
Example #9
0
        protected void GeneratePageDetailsUrls(Lib.ViewModels.MixPages.ReadMvcViewModel page)
        {
            page.DetailsUrl = MixCmsHelper.GetRouterUrl(
                new { culture = culture, seoName = page.SeoName }, Request, Url);
            if (page.Posts != null)
            {
                foreach (var postNav in page.Posts.Items)
                {
                    if (postNav.Post != null)
                    {
                        postNav.Post.DetailsUrl = GenerateDetailsUrl(new { action = "post", culture = culture, id = postNav.PostId, seoName = postNav.Post.SeoName });
                    }
                }
            }

            if (page.Modules != null)
            {
                foreach (var nav in page.Modules)
                {
                    GeneratePageDetailsUrls(nav.Module);
                }
            }
        }
Example #10
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 <MixPage, bool> > predicate = model =>
                                                           model.Specificulture == _lang &&
                                                           (!request.Status.HasValue || model.Status == request.Status.Value) &&
                                                           (!isLevel || model.Level == level) &&
                                                           (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 = MixCmsHelper.GetRouterUrl(
                            "page", 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 = MixCmsHelper.GetRouterUrl(
                            "page", 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 = MixCmsHelper.GetRouterUrl(
                            "page", new { seoName = a.SeoName }, Request, Url);
                        a.Childs.ForEach((Action <Lib.ViewModels.MixPagePages.ReadViewModel>)(c =>
                        {
                            c.Page.DetailsUrl = MixCmsHelper.GetRouterUrl(
                                "page", new { seoName = c.Page.SeoName }, Request, Url);
                        }));
                    }));
                }

                return(JObject.FromObject(listItemResult));
            }
        }
Example #11
0
        public async Task <ActionResult <JObject> > Details(string name)
        {
            var result = await MixCmsHelper.GetNavigation(name, _lang, Url);

            return(Ok(result));
        }
Example #12
0
        public override MixPost ParseModel(MixCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            if (Id == 0)
            {
                Id = Repository.Max(c => c.Id, _context, _transaction).Data + 1;
                CreatedDateTime = DateTime.UtcNow;
            }
            LastModified      = DateTime.UtcNow;
            PublishedDateTime = PublishedDateTime?.ToUniversalTime();

            //  Parsing Extra Fields to json string
            var arrField = Columns != null?JArray.Parse(
                Newtonsoft.Json.JsonConvert.SerializeObject(Columns.OrderBy(c => c.Priority).Where(
                                                                c => !string.IsNullOrEmpty(c.Name)))) : new JArray();

            ExtraFields = arrField.ToString(Newtonsoft.Json.Formatting.None);

            // Parsing Extra Properties value
            if (Properties != null && Properties.Count > 0)
            {
                JArray arrProperties = new JArray();
                foreach (var p in Properties.Where(p => !string.IsNullOrEmpty(p.Value) && !string.IsNullOrEmpty(p.Name)))
                {
                    arrProperties.Add(JObject.FromObject(p));
                }
                ExtraProperties = arrProperties.ToString(Formatting.None)?.Trim();
            }

            Template = View != null?string.Format(@"{0}/{1}{2}", View.FolderType, View.FileName, View.Extension) : Template;

            if (ThumbnailFileStream != null)
            {
                string folder        = MixCmsHelper.GetUploadFolder(Specificulture);
                string filename      = MixCommonHelper.GetRandomName(ThumbnailFileStream.Name);
                bool   saveThumbnail = MixCommonHelper.SaveFileBase64(folder, filename, ThumbnailFileStream.Base64);
                if (saveThumbnail)
                {
                    MixCommonHelper.RemoveFile(Thumbnail);
                    Thumbnail = $"{folder}/{filename}";
                }
            }
            if (ImageFileStream != null)
            {
                string folder    = MixCmsHelper.GetUploadFolder(Specificulture);
                string filename  = MixCommonHelper.GetRandomName(ImageFileStream.Name);
                bool   saveImage = MixCommonHelper.SaveFileBase64(folder, filename, ImageFileStream.Base64);
                if (saveImage)
                {
                    MixCommonHelper.RemoveFile(Image);
                    Image = $"{folder}/{filename}";
                }
            }

            if (!string.IsNullOrEmpty(Image) && Image[0] == '/')
            {
                Image = Image.Substring(1);
            }
            if (!string.IsNullOrEmpty(Thumbnail) && Thumbnail[0] == '/')
            {
                Thumbnail = Thumbnail.Substring(1);
            }
            Tags = ListTag.ToString(Newtonsoft.Json.Formatting.None);
            GenerateSEO();

            return(base.ParseModel(_context, _transaction));
        }
Example #13
0
 public T Property <T>(string fieldName)
 {
     return(MixCmsHelper.Property <T>(AttributeData?.Data?.Obj, fieldName));
 }
Example #14
0
 public static string ToMoney(this double value)
 {
     return(MixCmsHelper.FormatPrice(value));
 }
Example #15
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 <MixPost, bool> > predicate = model =>
                                                           model.Specificulture == _lang &&
                                                           (!request.Status.HasValue || model.Status == request.Status.Value) &&
                                                           (!isPage || model.MixPagePost.Any(nav => nav.PageId == pageId && nav.PostId == model.Id && nav.Specificulture == _lang)) &&
                                                           (!isNotPage || !model.MixPagePost.Any(nav => nav.PageId == notPageId && nav.PostId == model.Id && nav.Specificulture == _lang)) &&
                                                           (!isModule || model.MixModulePost.Any(nav => nav.ModuleId == moduleId && nav.PostId == model.Id)) &&
                                                           (!isNotModule || !model.MixModulePost.Any(nav => nav.ModuleId == notModuleId && nav.PostId == 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 = PublishPosts();

            switch (request.Key)
            {
            case "service.store":
                var srvResult = await base.GetListAsync <Lib.ViewModels.Services.Store.PostViewModel>(request, predicate);

                if (srvResult.IsSucceed)
                {
                    srvResult.Data.Items.ForEach(a =>
                    {
                        a.DetailsUrl = MixCmsHelper.GetRouterUrl(
                            new { action = "post", culture = _lang, id = a.Id, seoName = a.SeoName }, Request, Url);
                    });
                }
                return(Ok(JObject.FromObject(srvResult)));

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

                if (mvcResult.IsSucceed)
                {
                    mvcResult.Data.Items.ForEach(a =>
                    {
                        a.DetailsUrl = MixCmsHelper.GetRouterUrl(
                            new { action = "post", culture = _lang, id = a.Id, seoName = a.SeoName }, Request, Url);
                    });
                }
                return(Ok(JObject.FromObject(mvcResult)));

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

                if (portalResult.IsSucceed)
                {
                    portalResult.Data.Items.ForEach(a =>
                    {
                        a.DetailsUrl = MixCmsHelper.GetRouterUrl(
                            new { action = "post", culture = _lang, id = a.Id, seoName = a.SeoName }, Request, Url);
                    });
                }
                return(Ok(JObject.FromObject(portalResult)));

            default:

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

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

                return(JObject.FromObject(listItemResult));
            }
        }
Example #16
0
        public RepositoryResponse <FileViewModel> SiteMap()
        {
            try
            {
                XNamespace aw            = "http://www.sitemaps.org/schemas/sitemap/0.9";
                var        root          = new XElement(aw + "urlset");
                var        pages         = Lib.ViewModels.MixPages.ReadListItemViewModel.Repository.GetModelList();
                List <int> handledPageId = new List <int>();
                foreach (var page in pages.Data)
                {
                    page.DetailsUrl = MixCmsHelper.GetRouterUrl(
                        new { culture = page.Specificulture, seoName = page.SeoName }, 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     = MixCmsHelper.GetRouterUrl(
                                new { culture = item.Specificulture, seoName = page.SeoName }, Request, Url)
                        });
                    }

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

                var posts = Lib.ViewModels.MixPosts.ReadListItemViewModel.Repository.GetModelList();
                foreach (var post in posts.Data)
                {
                    post.DetailsUrl = MixCmsHelper.GetRouterUrl(
                        new { culture = post.Specificulture, action = "post", id = post.Id, seoName = post.SeoName }, Request, Url);
                    var otherLanguages = pages.Data.Where(p => p.Id == post.Id && p.Specificulture != post.Specificulture);
                    var lstOther       = new List <SitemapLanguage>();
                    foreach (var item in otherLanguages)
                    {
                        lstOther.Add(new SitemapLanguage()
                        {
                            HrefLang = item.Specificulture,
                            Href     = MixCmsHelper.GetRouterUrl(
                                new { culture = item.Specificulture, seoName = post.SeoName }, Request, Url)
                        });
                    }
                    var sitemap = new SiteMap()
                    {
                        ChangeFreq     = "monthly",
                        LastMod        = DateTime.UtcNow,
                        Loc            = post.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
                });
            }
        }
Example #17
0
 protected string GenerateDetailsUrl(object routeValues)
 {
     return(MixCmsHelper.GetRouterUrl(routeValues, Request, Url));
 }
Example #18
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 <MixOrder, bool> > predicate = model =>
                                                            model.Specificulture == _lang &&
                                                            (!request.Status.HasValue || model.Status == request.Status.Value) &&
                                                            (string.IsNullOrWhiteSpace(request.Keyword)
                                                            ) &&
                                                            (!request.FromDate.HasValue ||
                                                             (model.CreatedDateTime >= request.FromDate.Value)
                                                            ) &&
                                                            (!request.ToDate.HasValue ||
                                                             (model.CreatedDateTime <= request.ToDate.Value)
                                                            );

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

                if (mvcResult.IsSucceed)
                {
                    mvcResult.Data.Items.ForEach(a =>
                    {
                        a.DetailsUrl = MixCmsHelper.GetRouterUrl(
                            new { culture = _lang, action = "order", seoName = a.Id }, Request, Url);
                    });
                }

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

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

                if (portalResult.IsSucceed)
                {
                    portalResult.Data.Items.ForEach(a =>
                    {
                        a.DetailsUrl = MixCmsHelper.GetRouterUrl(
                            new { culture = _lang, action = "order", seoName = a.Id }, Request, Url);
                    });
                }

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

            default:

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

                if (listItemResult.IsSucceed)
                {
                    listItemResult.Data.Items.ForEach((Action <ReadListItemViewModel>)(a =>
                    {
                        a.DetailsUrl = MixCmsHelper.GetRouterUrl(
                            new { culture = _lang, action = "order", seoName = a.Id }, Request, Url);
                    }));
                }

                return(JObject.FromObject(listItemResult));
            }
        }
Example #19
0
        public override MixProduct ParseModel(MixCmsContext _context = null, IDbContextTransaction _transaction = null)
        {
            if (Id == 0)
            {
                Id = Repository.Max(c => c.Id, _context, _transaction).Data + 1;
                CreatedDateTime = DateTime.UtcNow;
            }
            LastModified = DateTime.UtcNow;
            if (Properties != null && Properties.Count > 0)
            {
                JArray arrProperties = new JArray();
                foreach (var p in Properties.Where(p => !string.IsNullOrEmpty(p.Value) && !string.IsNullOrEmpty(p.Name)).OrderBy(p => p.Priority))
                {
                    arrProperties.Add(JObject.FromObject(p));
                }
                ExtraProperties = arrProperties.ToString(Formatting.None);
            }

            Template = View != null?string.Format(@"{0}/{1}{2}", View.FolderType, View.FileName, View.Extension) : Template;

            if (ThumbnailFileStream != null)
            {
                string folder = CommonHelper.GetFullPath(new string[]
                {
                    MixConstants.Folder.UploadFolder, "Products", DateTime.UtcNow.ToString("dd-MM-yyyy")
                });
                string filename      = CommonHelper.GetRandomName(ThumbnailFileStream.Name);
                bool   saveThumbnail = CommonHelper.SaveFileBase64(folder, filename, ThumbnailFileStream.Base64);
                if (saveThumbnail)
                {
                    CommonHelper.RemoveFile(Thumbnail);
                    Thumbnail = CommonHelper.GetFullPath(new string[] { folder, filename });
                }
            }
            if (ImageFileStream != null)
            {
                string folder = CommonHelper.GetFullPath(new string[]
                {
                    MixConstants.Folder.UploadFolder, "Products", DateTime.UtcNow.ToString("dd-MM-yyyy")
                });
                string filename  = CommonHelper.GetRandomName(ImageFileStream.Name);
                bool   saveImage = CommonHelper.SaveFileBase64(folder, filename, ImageFileStream.Base64);
                if (saveImage)
                {
                    CommonHelper.RemoveFile(Image);
                    Image = CommonHelper.GetFullPath(new string[] { folder, filename });
                }
            }
            if (Image[0] == '/')
            {
                Image = Image.Substring(1);
            }
            if (Thumbnail[0] == '/')
            {
                Thumbnail = Thumbnail.Substring(1);
            }
            Tags        = ListTag.ToString(Newtonsoft.Json.Formatting.None);
            NormalPrice = MixCmsHelper.ReversePrice(StrNormalPrice);
            DealPrice   = MixCmsHelper.ReversePrice(StrDealPrice);
            ImportPrice = MixCmsHelper.ReversePrice(StrImportPrice);

            GenerateSEO();

            return(base.ParseModel(_context, _transaction));
        }
Example #20
0
 string GenerateDetailsUrl(string type, object routeValues)
 {
     return(MixCmsHelper.GetRouterUrl(type, routeValues, Request, Url));
 }
Example #21
0
 public T Property <T>(string fieldName)
 {
     return(MixCmsHelper.Property <T>(AdditionalData?.Data?.Obj, fieldName));
 }
Example #22
0
        public async Task <ActionResult <JObject> > Details(string viewType, int?id)
        {
            string msg = string.Empty;

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

                    if (portalResult.IsSucceed)
                    {
                        portalResult.Data.DetailsUrl = MixCmsHelper.GetRouterUrl(
                            new { action = "post", culture = _lang, id = portalResult.Data.Id, SeoName = portalResult.Data.SeoName }, Request, Url);
                    }

                    return(Ok(JObject.FromObject(portalResult)));
                }
                else
                {
                    var model = new MixPost()
                    {
                        Specificulture = _lang,
                        Status         = MixService.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 = MixCmsHelper.GetRouterUrl(
                            new { action = "post", culture = _lang, id = beResult.Data.Id, beResult.Data.SeoName }, Request, Url);
                    }
                    return(Ok(JObject.FromObject(beResult)));
                }
                else
                {
                    var model = new MixPost();
                    RepositoryResponse <ReadMvcViewModel> result = new RepositoryResponse <ReadMvcViewModel>()
                    {
                        IsSucceed = true,
                        Data      = new ReadMvcViewModel(model)
                        {
                            Specificulture = _lang,
                            Status         = MixContentStatus.Preview,
                        }
                    };
                    return(Ok(JObject.FromObject(result)));
                }
            }
        }
        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 isModule = int.TryParse(query.Get("module_id"), out int moduleId);

            ParseRequestPagingDate(request);
            Expression <Func <MixArticle, bool> > predicate = model =>
                                                              model.Specificulture == _lang &&
                                                              (!request.Status.HasValue || model.Status == request.Status.Value) &&
                                                              (!isPage || model.MixPageArticle.Any(nav => nav.CategoryId == pageId && nav.ArticleId == model.Id && nav.Specificulture == _lang)) &&
                                                              (!isModule || model.MixModuleArticle.Any(nav => nav.ModuleId == moduleId && 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)
                                                              );
            string key = $"{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 = MixCmsHelper.GetRouterUrl(
                            "article", 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 = MixCmsHelper.GetRouterUrl(
                            "article", 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 = MixCmsHelper.GetRouterUrl(
                            "article", new { seoName = a.SeoName }, Request, Url);
                    }));
                }

                return(JObject.FromObject(listItemResult));
            }
        }