Ejemplo n.º 1
0
        public ActionResult ProductDetail(int productId)
        {
            ProductModelDetail modelDetail = _productBo.GetByProductId(productId);

            if (modelDetail != null && modelDetail.ProductId > 0 && modelDetail.Status == (int)Enums.ProductStatus.Active)
            {
                #region Redirect Permanent 301

                var    currentUrl  = Request.RawUrl;
                string standardUrl = modelDetail.URL;
                string url301      = standardUrl;

                if (currentUrl.Contains("?utm_source"))
                {
                    string strUtm = currentUrl.Substring(currentUrl.IndexOf("?utm_source"), currentUrl.Length - currentUrl.IndexOf("?utm_source"));
                    url301 = string.Concat(url301, strUtm);
                }
                if (!currentUrl.Equals(url301))
                {
                    return(RedirectPermanent(string.Concat(Const.BaseUrlNoSlash, url301)));
                }

                #endregion

                #region Meta

                string strTitle = modelDetail.Name;
                string seoTitle = !string.IsNullOrEmpty(modelDetail.SEOTitle) ? modelDetail.SEOTitle : modelDetail.Name;
                string seoDesc  = !string.IsNullOrEmpty(modelDetail.SEODescription) ? modelDetail.SEODescription : modelDetail.ShortDescription;
                if (string.IsNullOrEmpty(seoDesc) && seoDesc.Length > 160)
                {
                    seoDesc = StringUtils.TrimText(seoDesc, 160);
                }
                string metaTags = SEO.Instance.BindingMeta(standardUrl, seoTitle, StringUtils.RemoveStrHtmlTags(seoDesc));
                ViewBag.MetaTitle    = seoTitle;
                ViewBag.Meta         = metaTags;
                ViewBag.MetaFacebook = SEO.AddMetaFacebook(modelDetail.Name, "article", seoDesc, Const.BaseUrlNoSlash + standardUrl, BuildLink.CropImage(modelDetail.Avatar, Const.FacebookAvatar));

                #endregion

                ViewBag.CateId = modelDetail.CateId;

                return(View(modelDetail));
            }

            Response.StatusCode = 404;
            return(null);
        }