Ejemplo n.º 1
0
 public ActionResult Detail(int id, string viewName = "Detail")
 {
     Func<Maticsoft.Model.Shop.Products.CategoryInfo, bool> predicate = null;
     ProductModel model = new ProductModel {
         ProductInfo = this.productManage.GetModel((long) id)
     };
     model.ProductImages = new Maticsoft.BLL.Shop.Products.ProductImage().ProductImagesList((long) id);
     model.ProductSkus = this.skuBll.GetProductSkuInfo((long) id);
     Maticsoft.BLL.Shop.Products.BrandInfo info = new Maticsoft.BLL.Shop.Products.BrandInfo();
     if (model.ProductInfo == null)
     {
         return base.RedirectToAction("Index", "Home");
     }
     Maticsoft.Model.Shop.Products.BrandInfo modelByCache = info.GetModelByCache(model.ProductInfo.BrandId);
     if (modelByCache != null)
     {
         ((dynamic) base.ViewBag).BrandName = modelByCache.BrandName;
     }
     Maticsoft.Model.Shop.Products.ProductCategories categoryModel = new Maticsoft.BLL.Shop.Products.ProductCategories().GetModel((long) id);
     if (categoryModel != null)
     {
         List<Maticsoft.Model.Shop.Products.CategoryInfo> allCateList = Maticsoft.BLL.Shop.Products.CategoryInfo.GetAllCateList();
         if (predicate == null)
         {
             predicate = c => c.CategoryId == categoryModel.CategoryId;
         }
         Maticsoft.Model.Shop.Products.CategoryInfo info3 = allCateList.FirstOrDefault<Maticsoft.Model.Shop.Products.CategoryInfo>(predicate);
         if (info3 != null)
         {
             string[] cateIds = info3.Path.Split(new char[] { '|' });
             List<Maticsoft.Model.Shop.Products.CategoryInfo> list2 = (from c in allCateList
                 where cateIds.Contains<string>(c.CategoryId.ToString())
                 orderby c.Depth
                 select c).ToList<Maticsoft.Model.Shop.Products.CategoryInfo>();
             StringBuilder builder = new StringBuilder();
             StringBuilder builder2 = new StringBuilder();
             if ((list2 != null) && (list2.Count > 0))
             {
                 foreach (Maticsoft.Model.Shop.Products.CategoryInfo info4 in list2)
                 {
                     builder2.AppendFormat("<a href='/Product/" + info4.CategoryId + "'>{0}</a> > ", info4.Name);
                 }
             }
             ((dynamic) base.ViewBag).Cid = categoryModel.CategoryId;
             ((dynamic) base.ViewBag).PathInfo = builder.ToString();
             ((dynamic) base.ViewBag).CategoryStr = builder2.ToString();
         }
     }
     PageSetting setting = PageSetting.GetProductSetting(model.ProductInfo, "Product", ApplicationKeyType.Shop);
     ((dynamic) base.ViewBag).Title = setting.Title;
     ((dynamic) base.ViewBag).Keywords = setting.Keywords;
     ((dynamic) base.ViewBag).Description = setting.Description;
     ((dynamic) base.ViewBag).ConsultCount = this.conBll.GetRecordCount("Status=1 and ProductId=" + id);
     ((dynamic) base.ViewBag).CommentCount = this.reviewsBll.GetRecordCount("Status=1 and ProductId=" + id);
     return base.View(viewName, model);
 }
Ejemplo n.º 2
0
 public ActionResult AddCart(string sku, int count = 1, string viewName = "AddCart")
 {
     if (string.IsNullOrWhiteSpace(sku))
     {
         return base.RedirectToAction("Index", "Home");
     }
     int userId = (base.currentUser == null) ? -1 : base.currentUser.UserID;
     ShoppingCartHelper helper = new ShoppingCartHelper(userId);
     ShoppingCartItem cartItem = new ShoppingCartItem();
     ProductModel model = new ProductModel();
     Maticsoft.Model.Shop.Products.SKUInfo modelBySKU = this.skuBll.GetModelBySKU(sku);
     if (modelBySKU == null)
     {
         return base.Content("NOSKU");
     }
     List<Maticsoft.Model.Shop.Products.SKUInfo> list2 = new List<Maticsoft.Model.Shop.Products.SKUInfo> {
         modelBySKU
     };
     model.ProductSkus = list2;
     model.ProductInfo = this.productBll.GetModelByCache(modelBySKU.ProductId);
     if ((model.ProductInfo != null) && (model.ProductSkus != null))
     {
         cartItem.Name = model.ProductInfo.ProductName;
         cartItem.Quantity = count;
         cartItem.SKU = model.ProductSkus[0].SKU;
         cartItem.ProductId = model.ProductInfo.ProductId;
         cartItem.UserId = userId;
         List<Maticsoft.Model.Shop.Products.SKUItem> sKUItemsBySkuId = this.skuBll.GetSKUItemsBySkuId(modelBySKU.SkuId);
         if ((sKUItemsBySkuId != null) && (sKUItemsBySkuId.Count > 0))
         {
             cartItem.SkuValues = new string[sKUItemsBySkuId.Count];
             int index = 0;
             sKUItemsBySkuId.ForEach(delegate (Maticsoft.Model.Shop.Products.SKUItem xx) {
                 cartItem.SkuValues[index++] = xx.ValueStr;
                 if (!string.IsNullOrWhiteSpace(xx.ImageUrl))
                 {
                     cartItem.SkuImageUrl = xx.ImageUrl;
                 }
             });
         }
         cartItem.ThumbnailsUrl = model.ProductInfo.ThumbnailUrl1;
         cartItem.CostPrice = model.ProductSkus[0].CostPrice.HasValue ? model.ProductSkus[0].CostPrice.Value : 0M;
         cartItem.MarketPrice = model.ProductInfo.MarketPrice.HasValue ? model.ProductInfo.MarketPrice.Value : 0M;
         cartItem.SellPrice = cartItem.AdjustedPrice = model.ProductSkus[0].SalePrice;
         cartItem.Weight = model.ProductSkus[0].Weight.HasValue ? model.ProductSkus[0].Weight.Value : 0;
         helper.AddItem(cartItem);
         ShoppingCartInfo shoppingCart = helper.GetShoppingCart();
         ((dynamic) base.ViewBag).TotalPrice = shoppingCart.TotalSellPrice;
         ((dynamic) base.ViewBag).ItemCount = shoppingCart.Quantity;
     }
     ((dynamic) base.ViewBag).Title = "添加购物车";
     return base.RedirectToAction("CartInfo");
 }