コード例 #1
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;
                    }
                }
            }
            //}
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        public override Pyramid.Entity.HomeEntity ConvertDbObjectToEntity(PyramidFinalContext context, HomeEntity dbObject)
        {
            var hEntity = new Pyramid.Entity.HomeEntity();

            if (dbObject.BannerWithPoints != null)
            {
                hEntity.BannerWithPoints = new Pyramid.Entity.BannerWithPoints()
                {
                    BannerId = dbObject.BannerWithPoints.BannerId,
                    Images   = dbObject.BannerWithPoints.Images != null ? new Image()
                    {
                        Id               = dbObject.BannerWithPoints.Images.Id,
                        ImgAlt           = dbObject.BannerWithPoints.Images.ImgAlt,
                        PathInFileSystem = dbObject.BannerWithPoints.Images.PathInFileSystem,
                        ServerPathImg    = dbObject.BannerWithPoints.Images.ServerPathImg,
                        Title            = dbObject.BannerWithPoints.Images.Title
                    } : new Image(),
                    PointOnImgs = dbObject.BannerWithPoints.PointOnImgs.Select(p => new Pyramid.Entity.PointOnImg()
                    {
                        CoordX   = p.CoordX,
                        CoordY   = p.CoordY,
                        Id       = p.Id,
                        Products = new Product()
                        {
                            ThumbnailImg = p.Products.ProductImages.FirstOrDefault(f => f.ProductId == p.Products.Id && f.TypeImage == (int)Common.TypeImage.Thumbnail) != null ?
                                           ConvertImageToEntity.Convert(p.Products.ProductImages.FirstOrDefault(f => f.ProductId == p.Products.Id && f.TypeImage == (int)Common.TypeImage.Thumbnail).Images) : new Pyramid.Entity.Image(),
                            Id          = p.Products.Id,
                            Title       = p.Products.Title,
                            Price       = p.Products.Price,
                            TypePrice   = (Common.TypeProductPrice)p.Products.TypePrice,
                            FriendlyUrl = new RouteItemRepository(context).GetFriendlyUrl(p.Products.Id, Common.TypeEntityFromRouteEnum.ProductType)
                        }
                    }).ToList()
                };
            }
            hEntity.CallToAction    = dbObject.CallToAction;
            hEntity.Content         = dbObject.Content;
            hEntity.Id              = dbObject.Id;
            hEntity.LinkYouTobe     = dbObject.LinkYouTobe;
            hEntity.Title           = dbObject.Title;
            hEntity.TitleVideoGuide = dbObject.TitleVideoGuide;

            hEntity.Categories = dbObject.Categories.Select(s => new Pyramid.Entity.Category()
            {
                Id          = s.Id,
                Title       = s.Title,
                FriendlyUrl = new RouteItemRepository(context).GetFriendlyUrl(s.Id, Common.TypeEntityFromRouteEnum.CategoryType)
            }).ToList();

            hEntity.Images = ConvertImageToEntity.Convert(dbObject.Images);

            hEntity.Products = dbObject.Products.Select(p => new Pyramid.Entity.Product()
            {
                ThumbnailImg = p.ProductImages.FirstOrDefault(f => f.ProductId == p.Id && f.TypeImage == (int)Common.TypeImage.Thumbnail) != null ?
                               ConvertImageToEntity.Convert(p.ProductImages.FirstOrDefault(f => f.ProductId == p.Id && f.TypeImage == (int)Common.TypeImage.Thumbnail).Images) : new Pyramid.Entity.Image(),
                Id                = p.Id,
                Title             = p.Title,
                Price             = p.Price,
                TypePrice         = (Common.TypeProductPrice)p.TypePrice,
                TypeStatusProduct = (Common.TypeStatusProduct)p.TypeStatusProduct,
                FriendlyUrl       = new RouteItemRepository(context).GetFriendlyUrl(p.Id, Common.TypeEntityFromRouteEnum.ProductType)
            }).ToList();

            if (dbObject.Faq != null)
            {
                var faq = new FaqRepository(context).Get(dbObject.Faq.Id);
                hEntity.Faq = faq;
                // new FAQ()
                //{
                //    Id = dbObject.Faq.Id,
                //    Title = dbObject.Faq.Title,
                //    FriendlyUrl
                //    QuestionAnswer = dbObject.Faq.QuestionAnswer.Select(s => new Pyramid.Entity.QuestionAnswer()
                //    {
                //        Id = s.Id,
                //        Answer = s.Answer,
                //        Question = s.Question

                //    }).ToList()
                //};
            }



            return(hEntity);
        }