public ActionResult Single(long?id, string title, bool isJson = false)
        {
            if (!id.HasValue)
            {
                return(Content(CreatePageMissingTemplate().Render()));
            }
            // if store disabled then hide the product
            if (!IsStoreEnabled && !sessionid.HasValue)
            {
                return(RedirectToAction("Index", "login"));
            }

            LiquidTemplate template;

            using (var repo = new TradelrRepository())
            {
                repo.SetIsolationToNoLock();
                var p = repo.GetProduct(id.Value, subdomainid.Value);

                if (p == null)
                {
                    return(Content(CreatePageMissingTemplate().Render()));
                }
                var liquidmodel = p.ToLiquidModel(sessionid, "");

                if (isJson)
                {
                    return(Json(liquidmodel, JsonRequestBehavior.AllowGet));
                }

                if (p.hits.HasValue)
                {
                    p.hits += 1;
                }
                else
                {
                    p.hits = 1;
                }
                repo.Save();

                template = CreateLiquidTemplate("product", p.title);

                // opengraph
                var opengraph = MASTERdomain.organisation.ToOpenGraph(p, null);
                template.AddHeaderContent(this.RenderViewToString("~/Views/store/liquid/defaultHeader.ascx", opengraph));
                template.InitContentTemplate("templates/product.liquid");
                template.AddParameters("product", liquidmodel);
            }
            return(Content(template.Render()));
        }
Exemple #2
0
        /// <summary>
        /// generates a thumbnail given the path of the original images
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="suffix"></param>
        /// <param name="desiredWidth"></param>
        /// <param name="desiredHeight"></param>
        /// <returns></returns>
        private static string thumbnail(string filePath, string suffix, float desiredWidth, float desiredHeight, Imgsize type)
        {
            string thumb = filePath;
            string file  = filePath;
            string ext   = thumb.Substring(thumb.LastIndexOf(".") + 1);

            thumb = thumb.Substring(0, thumb.LastIndexOf(".")) + "_" + suffix + "." + ext;
#if AZURE
            file  = file.Substring(file.LastIndexOf("/") + 1);
            thumb = thumb.Substring(thumb.LastIndexOf("/") + 1);
            bool exists = photoContainer.DoesBlobItemExists(file);
#else
            bool exists = File.Exists(GeneralConstants.APP_ROOT_DIR + file);
#endif
            if (!exists)
            {
                // delete from db
                new Thread(() =>
                {
                    Syslog.Write(String.Concat("Cannot find file: ", GeneralConstants.APP_ROOT_DIR + file));
                    using (var db = new tradelrDataContext())
                    {
                        var repository = new TradelrRepository(db);
                        repository.SetIsolationToNoLock();
                        repository.DeleteImage(file);
                    }
                }).Start();

                return("");
            }
            // These are the ratio calculations
#if AZURE
            Image img = Image.FromStream(photoContainer.GetBlobContentStream(file));
#else
            Image img = Image.FromFile(GeneralConstants.APP_ROOT_DIR + file);
#endif
            int width  = img.Width;
            int height = img.Height;

            img.Dispose();

            float factor = 0;
            if (width > 0 && height > 0)
            {
                float wfactor = desiredWidth / width;
                float hfactor = desiredHeight / height;
                factor = wfactor < hfactor ? wfactor : hfactor;
            }
            if (factor > 0)
            {
                int twidth  = Convert.ToInt32(Math.Floor(factor * width));
                int theight = Convert.ToInt32(Math.Floor(factor * height));
                convert(file, thumb, twidth, theight, type);
            }
            else
            {
#if AZURE
                photoContainer.DeleteBlobItem(thumb);
                photoContainer.CopyContent(file, thumb);
#else
                if (File.Exists(GeneralConstants.APP_ROOT_DIR + thumb))
                {
                    File.Delete(GeneralConstants.APP_ROOT_DIR + thumb);
                }
                File.Copy(GeneralConstants.APP_ROOT_DIR + file, GeneralConstants.APP_ROOT_DIR + thumb);
#endif
            }
            return(thumb);
        }