Esempio n. 1
0
        /// <summary>显示产品详细内容的页面
        /// </summary>
        /// <param name="id">要显示的产品的ID</param>
        /// <returns>产品详细页面</returns>
        public ActionResult Detail(int id)
        {
            Cart     cart = (User as SolemartUser).Cart;
            CartItem item = cart.CartItems.FirstOrDefault(c => c.ProductID == id);

            if (item != null)
            {
                ViewBag.CartItem = item.Amount;
            }
            else
            {
                ViewBag.CartItem = 0;
            }

            string cacheKey = string.Format("product_{0}", id);
            ProductDetailViewModel model = null;

            if (CacheUtil.Exist(cacheKey))
            {
                model = CacheUtil.Get <ProductDetailViewModel>(cacheKey);
            }
            else
            {
                SaledProductItem        saleInfo = ProductManager.GetSaledProductByID(id);
                ProductItem             product  = ProductManager.GetProductWithBrandByID(id);
                List <ProductImageItem> images   = ProductManager.GetProductNoLogoImage(id);
                int commentCount = ProductManager.GetProductCommentCount(id);

                string remainAmountString = string.Empty;
                if (product.Unit == "斤")
                {
                    remainAmountString = string.Format("{0}", product.StockCount - product.ReserveCount);
                }
                else
                {
                    remainAmountString = string.Format("{0:d}", (int)(product.StockCount - product.ReserveCount));
                }
                model = new ProductDetailViewModel
                {
                    ProductID          = id,
                    ProductName        = product.ProductName,
                    ProductDescription = product.Description,
                    Price            = saleInfo.Price,
                    Unit             = product.Unit,
                    Discount         = saleInfo.Discount,
                    SpecialFlag      = saleInfo.SpecialFlag,
                    RemainAmount     = remainAmountString,
                    BrandDescription = product.Brand.Description,
                    BrandLogo        = product.Brand.BrandLogo,
                    BrandUrl         = product.Brand.BrandUrl,
                    BrandName        = product.Brand.ZhName,
                    CommentCount     = commentCount,
                    Images           = images
                };
                CacheUtil.Add <ProductDetailViewModel>(cacheKey, model, 600);
            }


            return(View(model));
        }
Esempio n. 2
0
        private static int GetDefaultValuesFolderId(string strHomeDocId)
        {
            int    defaultValuesFolderId      = -1;
            string cacheDefaultValuesFolderId = string.Format("SetDefaultValuesOnNew#homeDoc:{0}#defaultValuesFolderId", strHomeDocId);

            if (CacheUtil.Exist(cacheDefaultValuesFolderId))
            {
                defaultValuesFolderId = CacheUtil.Get <int>(cacheDefaultValuesFolderId);
                if (defaultValuesFolderId > -1)
                {
                    return(defaultValuesFolderId);
                }
            }
            else
            {
                log.InfoFormat("Trying to find default values folder for home id: {0}", strHomeDocId);
                Document home = new Document(true, int.Parse(strHomeDocId));
                foreach (Document child in home.Children)
                {
                    log.InfoFormat("Test to see if we have the ConfigurationContainer below home. Current ContentType.Alias: {0}", child.ContentType.Alias);
                    if (child.ContentType.Alias == ConfigurationManager.DocumentTypeAliases.ConfigurationContainer.Value)
                    {
                        foreach (Document grandChild in child.Children)
                        {
                            log.InfoFormat("Test to see if we have the {1} below the ConfigurationContainer. Current ContentType.Alias: {0}", grandChild.ContentType.Alias, ConfigurationManager.DocumentTypeAliases.ConfigurationDefaultValuesContainer.Value);
                            if (grandChild.ContentType.Alias == ConfigurationManager.DocumentTypeAliases.ConfigurationDefaultValuesContainer.Value)
                            {
                                log.InfoFormat("We have found the default values folder id: {0}", grandChild.Id);
                                defaultValuesFolderId = grandChild.Id;
                                CacheUtil.Insert(cacheDefaultValuesFolderId, defaultValuesFolderId, 10, false);
                                return(defaultValuesFolderId);
                            }
                        }
                    }
                }
            }
            return(defaultValuesFolderId);
        }
Esempio n. 3
0
        public static void SetDefaultValuesOnNew(Document newDocument, umbraco.cms.businesslogic.NewEventArgs e)
        {
            log.Info("SetDefaultValuesOnNew Startet");
            log.InfoFormat("Document id: {1} - Document Type Alias: {0}", newDocument.ContentType.Alias, newDocument.Id);
            // We wrap it in a try since this part should not break for the user in umbraco
            try
            {
                string path = newDocument.Path;
                if (string.IsNullOrEmpty(path))
                {
                    StopWithError("Path on new document not found!");
                    return;
                }

                string[] strings      = StringUtil.Split(path, ",", true);
                string   strHomeDocId = strings[1];

                // Now we have the doc home id, lets see if the default value document based on document type alias exists
                string cacheKeyDefaultValueDocumentTypeAlias = string.Format("SetDefaultValuesOnNew#homeDoc:{0}#DefaultValueDocumentTypeAlias:{1}", strHomeDocId, newDocument.ContentType.Alias);
                int    defaultValueDocId = -1;
                if (CacheUtil.Exist(cacheKeyDefaultValueDocumentTypeAlias))
                {
                    defaultValueDocId = CacheUtil.Get <int>(cacheKeyDefaultValueDocumentTypeAlias);
                }
                else
                {
                    // Does not exist in the cache, lets try to look it up
                    int defaultValuesFolderDocId = GetDefaultValuesFolderId(strHomeDocId);
                    if (defaultValuesFolderDocId == -1)
                    {
                        StopWithError("Could not load default values folder id!");
                        return;
                    }

                    // For speed we use the published node factory
                    Node node = UmbracoUtil.GetNode(defaultValuesFolderDocId);
                    if (node == null)
                    {
                        StopWithError(string.Format("Could not load published node for default values folder id: {0}!", defaultValuesFolderDocId));
                        return;
                    }

                    Node defaultValueNode = node.GetDescendantViaDocumentTypePath(newDocument.ContentType.Alias);
                    if (defaultValueNode != null)
                    {
                        defaultValueDocId = defaultValueNode.Id;
                        CacheUtil.Insert(cacheKeyDefaultValueDocumentTypeAlias, defaultValueDocId, 10, false);
                    }
                    else
                    {
                        log.DebugFormat("No default node for document type alias: {0}", newDocument.ContentType.Alias);
                    }
                }

                if (defaultValueDocId > -1)
                {
                    Document defaultValueDocument = new Document(true, defaultValueDocId);

                    log.DebugFormat("ContentType {0} match. Let's start copying", newDocument.ContentType.Alias);

                    umbraco.cms.businesslogic.property.Properties newDocumentProperties  = newDocument.GenericProperties;
                    umbraco.cms.businesslogic.property.Properties defaultValueProperties = defaultValueDocument.GenericProperties;

                    for (int i = 0; i < newDocumentProperties.Count; i++)
                    {
                        umbraco.cms.businesslogic.property.Property newDocumentProperty     = newDocumentProperties[i];
                        umbraco.cms.businesslogic.property.Property defaultDocumentProperty = defaultValueProperties[i];

                        if (newDocumentProperty.Value != defaultDocumentProperty.Value)
                        {
                            log.DebugFormat("Set value on property alias {0}", newDocumentProperty.PropertyType.Alias);
                            newDocumentProperty.Value = defaultDocumentProperty.Value;
                        }
                    }
                }
                log.Info("SetDefaultValuesOnNew Ended");
            }
            catch (Exception ex)
            {
                log.Error("Could not complete SetDefaultValuesOnNew - stopped with exception", ex);
            }
        }