Beispiel #1
0
        public override void UpdateBeforeSaving(PyramidFinalContext dbContext, RouteItem dbEntity, Entity.RouteItem entity, bool exists)
        {
            //dbEntity.Id = entity.Id;
            dbEntity.TypeEntity     = (int)entity.Type;
            dbEntity.ControllerName = entity.ControllerName;
            dbEntity.ActionName     = entity.ActionName;
            dbEntity.ContentId      = entity.ContentId == 0?(int?)null:entity.ContentId;
            switch (entity.Type)
            {
            case Common.TypeEntityFromRouteEnum.ProductType:
                var friendlyUrlProduct = new ProductRepository(dbContext).GetChainFrendlyUrlByAlias(entity.ContentId);
                if (friendlyUrlProduct != null)
                {
                    dbEntity.FriendlyUrl = friendlyUrlProduct;
                }
                break;

            case Common.TypeEntityFromRouteEnum.CategoryType:
                var friendlyUrlCategory = new CategoryRepository(dbContext).GetChainFrendlyUrlByAlias(entity.ContentId);
                if (friendlyUrlCategory != null)
                {
                    dbEntity.FriendlyUrl = friendlyUrlCategory;
                }
                break;

            case Common.TypeEntityFromRouteEnum.PageType:
                var page = new PageRepository(dbContext).Get(entity.ContentId);
                if (page != null && page.Seo != null)
                {
                    dbEntity.FriendlyUrl = string.Format("/{0}", page.Seo.Alias.Replace("/", ""));
                }
                break;

            case Common.TypeEntityFromRouteEnum.Faq:
                var fq            = new FaqRepository(dbContext).Get(entity.ContentId);
                var globPrefixFaq = new GlobalOptionRepository().Get(Common.Constant.KeyFaq);
                if (fq != null && fq.Seo != null)
                {
                    dbEntity.FriendlyUrl = string.Format("/{0}/{1}", globPrefixFaq.OptionContent, fq.Seo.Alias.Replace("/", ""));
                }
                else
                {
                    if (dbEntity.ActionName == Common.Constant.ValFaqAction &&
                        dbEntity.ControllerName == Common.Constant.ValFaqController &&
                        dbEntity.ContentId == null)
                    {
                        dbEntity.FriendlyUrl = string.Format("/{0}", globPrefixFaq.OptionContent);
                    }
                }
                break;

            case Common.TypeEntityFromRouteEnum.Event:
                var evnt            = new EventRepository(dbContext).Get(entity.ContentId);
                var globPrefixEvent = new GlobalOptionRepository().Get(Common.Constant.KeyEvent);
                if (evnt != null && evnt.Seo != null)
                {
                    dbEntity.FriendlyUrl = string.Format("/{0}/{1}", globPrefixEvent.OptionContent, evnt.Seo.Alias.Replace("/", ""));
                }
                else
                {
                    if (dbEntity.ActionName == Common.Constant.ValEventAction &&
                        dbEntity.ControllerName == Common.Constant.ValEventController &&
                        dbEntity.ContentId == null)
                    {
                        dbEntity.FriendlyUrl = string.Format("/{0}", globPrefixEvent.OptionContent);
                    }
                }
                break;

            case Common.TypeEntityFromRouteEnum.RecommendationType:
                var recommend           = new RecommendationRepository(dbContext).Get(entity.ContentId);
                var globPrefixRecommend = new GlobalOptionRepository().Get(Common.Constant.KeyRecommendation);
                if (recommend != null && recommend.Seo != null)
                {
                    dbEntity.FriendlyUrl = string.Format("/{0}/{1}", globPrefixRecommend.OptionContent, recommend.Seo.Alias.Replace("/", ""));
                }
                else
                {
                    if (dbEntity.ActionName == Common.Constant.ValRecommendationAction &&
                        dbEntity.ControllerName == Common.Constant.ValRecommendationController &&
                        dbEntity.ContentId == null)
                    {
                        dbEntity.FriendlyUrl = string.Format("/{0}", globPrefixRecommend.OptionContent);
                    }
                }
                break;

            default:
                break;
            }
            if (dbEntity.FriendlyUrl == null)
            {
                dbEntity.FriendlyUrl = string.Format("/{0}/{1}/{2}", dbEntity.ControllerName, dbEntity.ActionName, dbEntity.ContentId);
            }
        }
Beispiel #2
0
        protected void ReBuildRelatedFriendlyUrl(PyramidFinalContext dbContext, string url)
        {
            //using (PyramidFinalContext data = new PyramidFinalContext())
            //{
            if (!string.IsNullOrEmpty(url))
            {
                var objects = dbContext.RouteItems.Where(w => w.FriendlyUrl.Contains(url));
                foreach (var item in objects)
                {
                    switch ((Common.TypeEntityFromRouteEnum)item.TypeEntity)
                    {
                    case Common.TypeEntityFromRouteEnum.ProductType:
                        var friendlyUrlProduct = new ProductRepository(dbContext).GetChainFrendlyUrlByAlias(item.ContentId.HasValue ? item.ContentId.Value : 0);
                        if (friendlyUrlProduct != null)
                        {
                            item.FriendlyUrl = friendlyUrlProduct;
                        }
                        break;

                    case Common.TypeEntityFromRouteEnum.CategoryType:
                        var friendlyUrlCategory = new CategoryRepository(dbContext).GetChainFrendlyUrlByAlias(item.ContentId.HasValue ? item.ContentId.Value : 0);
                        if (friendlyUrlCategory != null)
                        {
                            item.FriendlyUrl = friendlyUrlCategory;
                        }
                        break;

                    case Common.TypeEntityFromRouteEnum.PageType:
                        break;

                    case Common.TypeEntityFromRouteEnum.Faq:
                        var fq            = new FaqRepository(dbContext).Get(item.ContentId.HasValue? item.ContentId.Value:0);
                        var globPrefixFaq = new GlobalOptionRepository().Get(Common.Constant.KeyFaq);
                        if (fq != null && fq.Seo != null)
                        {
                            item.FriendlyUrl = string.Format("/{0}/{1}", globPrefixFaq.OptionContent, fq.Seo.Alias.Replace("/", ""));
                        }
                        break;

                    case Common.TypeEntityFromRouteEnum.Event:
                        var evnt            = new EventRepository(dbContext).Get(item.ContentId.HasValue ? item.ContentId.Value : 0);
                        var globPrefixEvent = new GlobalOptionRepository().Get(Common.Constant.KeyEvent);
                        if (evnt != null && evnt.Seo != null)
                        {
                            item.FriendlyUrl = string.Format("/{0}/{1}", globPrefixEvent.OptionContent, evnt.Seo.Alias.Replace("/", ""));
                        }
                        break;

                    case Common.TypeEntityFromRouteEnum.RecommendationType:
                        var recommend           = new RecommendationRepository(dbContext).Get(item.ContentId.HasValue ? item.ContentId.Value : 0);
                        var globPrefixRecommend = new GlobalOptionRepository().Get(Common.Constant.KeyRecommendation);
                        if (recommend != null && recommend.Seo != null)
                        {
                            item.FriendlyUrl = string.Format("/{0}/{1}", globPrefixRecommend.OptionContent, recommend.Seo.Alias.Replace("/", ""));
                        }

                        break;

                    default:
                        break;
                    }
                }
            }
            //}
        }