예제 #1
0
        public ActionResult EditProduct(int pid = -1)
        {
            ProductInfo productInfo = AdminProducts.AdminGetProductById(pid);

            if (productInfo == null)
            {
                return(PromptView("商品不存在"));
            }

            CategoryInfo vCategoryInfo = AdminCategories.GetCategoryById(productInfo.CateId);
            string       vCateName     = "";

            if (vCategoryInfo != null)
            {
                vCateName = vCategoryInfo.Name;
            }


            EditProductModel model = new EditProductModel();

            model.PSN          = productInfo.PSN;
            model.CateId       = productInfo.CateId;
            model.CategoryName = vCateName;
            model.BrandId      = productInfo.BrandId;
            model.ProductName  = productInfo.Name;
            model.ShopPrice    = productInfo.ShopPrice;
            model.MarketPrice  = productInfo.MarketPrice;
            model.CostPrice    = productInfo.CostPrice;
            model.State        = productInfo.State;
            model.IsBest       = productInfo.IsBest == 1 ? true : false;
            model.IsHot        = productInfo.IsHot == 1 ? true : false;
            model.IsNew        = productInfo.IsNew == 1 ? true : false;
            model.DisplayOrder = productInfo.DisplayOrder;
            model.Weight       = productInfo.Weight;
            model.Description  = productInfo.Description;

            model.BrandName = AdminBrands.GetBrandById(productInfo.BrandId).Name;


            //库存信息
            ProductStockInfo productStockInfo = AdminProducts.GetProductStockByPid(pid);

            model.StockNumber = productStockInfo.Number;
            model.StockLimit  = productStockInfo.Limit;

            //商品属性列表
            List <ProductAttributeInfo> productAttributeList = Products.GetProductAttributeList(pid);

            //商品sku项列表
            DataTable productSKUItemList = AdminProducts.GetProductSKUItemList(productInfo.Pid);

            ViewData["pid"]                  = productInfo.Pid;
            ViewData["cateId"]               = productInfo.CateId;
            ViewData["categoryName"]         = vCateName;
            ViewData["productAttributeList"] = productAttributeList;
            ViewData["productSKUItemList"]   = productSKUItemList;
            ViewData["referer"]              = ShopUtils.GetAdminRefererCookie();

            return(View(model));
        }
예제 #2
0
        public ActionResult EditProduct(EditProductModel model, int pid = -1)
        {
            ProductInfo productInfo = AdminProducts.AdminGetProductById(pid);

            if (productInfo == null)
            {
                return(PromptView("商品不存在"));
            }

            int pid2 = AdminProducts.AdminGetProductIdByName(model.ProductName);

            if (pid2 > 0 && pid2 != pid)
            {
                ModelState.AddModelError("ProductName", "名称已经存在");
            }

            if (ModelState.IsValid)
            {
                productInfo.PSN          = model.PSN ?? "";
                productInfo.BrandId      = model.BrandId;
                productInfo.StoreCid     = model.StoreCid;
                productInfo.StoreSTid    = model.StoreSTid;
                productInfo.Name         = model.ProductName;
                productInfo.ShopPrice    = model.ShopPrice;
                productInfo.MarketPrice  = model.MarketPrice;
                productInfo.CostPrice    = model.CostPrice;
                productInfo.State        = model.State;
                productInfo.IsBest       = model.IsBest == true ? 1 : 0;
                productInfo.IsHot        = model.IsHot == true ? 1 : 0;
                productInfo.IsNew        = model.IsNew == true ? 1 : 0;
                productInfo.DisplayOrder = model.DisplayOrder;
                productInfo.Weight       = model.Weight;
                productInfo.Description  = model.Description ?? "";
                productInfo.Spec         = model.Spec ?? "";

                AdminProducts.UpdateProduct(productInfo, model.StockNumber, model.StockLimit);
                AddMallAdminLog("修改商品", "修改商品,商品ID为:" + pid);
                return(PromptView("商品修改成功"));
            }


            //商品属性列表
            List <ProductAttributeInfo> productAttributeList = Products.GetProductAttributeList(pid);

            //商品sku项列表
            DataTable productSKUItemList = AdminProducts.GetProductSKUItemList(productInfo.Pid);

            ViewData["pid"]                  = productInfo.Pid;
            ViewData["storeId"]              = productInfo.StoreId;
            ViewData["storeName"]            = AdminStores.GetStoreById(productInfo.StoreId).Name;
            ViewData["cateId"]               = productInfo.CateId;
            ViewData["categoryName"]         = AdminCategories.GetCategoryById(productInfo.CateId).Name;
            ViewData["productAttributeList"] = productAttributeList;
            ViewData["productSKUItemList"]   = productSKUItemList;
            ViewData["referer"]              = MallUtils.GetMallAdminRefererCookie();

            return(View(model));
        }