示例#1
0
        public ActionResult AddProduct(AddProductModel model)
        {
            if (AdminProducts.AdminGetProductIdByName(model.ProductName) > 0)
                ModelState.AddModelError("ProductName", "名称已经存在");

            if (ModelState.IsValid)
            {
                ProductInfo productInfo = new ProductInfo()
                {
                    PSN = model.PSN ?? "",
                    CateId = model.CateId,
                    BrandId = model.BrandId,
                    StoreId = WorkContext.StoreId,
                    StoreCid = model.StoreCid,
                    StoreSTid = model.StoreSTid,
                    SKUGid = 0,
                    Name = model.ProductName,
                    ShopPrice = model.ShopPrice,
                    MarketPrice = model.MarketPrice,
                    CostPrice = model.CostPrice,
                    State = model.State,
                    IsBest = model.IsBest == true ? 1 : 0,
                    IsHot = model.IsHot == true ? 1 : 0,
                    IsNew = model.IsNew == true ? 1 : 0,
                    DisplayOrder = model.DisplayOrder,
                    Weight = model.Weight,
                    ShowImg = "",
                    Description = model.Description ?? "",
                    AddTime = DateTime.Now,
                };

                //属性处理
                List<ProductAttributeInfo> productAttributeList = new List<ProductAttributeInfo>();
                if (model.AttrValueIdList != null && model.AttrValueIdList.Length > 0)
                {
                    for (int i = 0; i < model.AttrValueIdList.Length; i++)
                    {
                        int attrId = model.AttrIdList[i];//属性id
                        int attrValueId = model.AttrValueIdList[i];//属性值id
                        string inputValue = model.AttrInputValueList[i];//属性输入值
                        if (attrId > 0 && attrValueId > 0)
                        {
                            productAttributeList.Add(new ProductAttributeInfo
                            {
                                AttrId = attrId,
                                AttrValueId = attrValueId,
                                InputValue = inputValue ?? ""
                            });
                        }
                    }
                }

                AdminProducts.AddProduct(productInfo, model.StockNumber, model.StockLimit, productAttributeList);
                AddStoreAdminLog("添加普通商品", "添加普通商品,商品为:" + model.ProductName);

                string backUrl = null;
                if (productInfo.State == (int)ProductState.OnSale)
                    backUrl = Url.Action("onsaleproductlist");
                else
                    backUrl = Url.Action("outsaleproductlist");
                return PromptView(backUrl, "普通商品添加成功");
            }
            LoadStore();
            ViewData["referer"] = MallUtils.GetStoreAdminRefererCookie();
            return View(model);
        }
示例#2
0
 public ActionResult AddProduct()
 {
     AddProductModel model = new AddProductModel();
     LoadStore();
     string backUrl = MallUtils.GetStoreAdminRefererCookie();
     if (backUrl.Length == 0 || backUrl == "/storeadmin/home/storeruninfo")
     {
         backUrl = Url.Action("onsaleproductlist");
         MallUtils.SetAdminRefererCookie(backUrl);
     }
     ViewData["referer"] = backUrl;
     return View(model);
 }