public void GetTotalCost_1A1B1C()
        {
            List <ProductObj> listofProducts = new List <ProductObj>();
            int count = 0;

            for (int i = 0; i < 3; i++)
            {
                string skuType = string.Empty;
                if (count == 0)
                {
                    skuType = "A";
                }
                else if (count == 1)
                {
                    skuType = "B";
                }
                else if (count == 2)
                {
                    skuType = "c";
                }

                ProductObj product = objProducts.getProduct(skuType.ToUpper());
                listofProducts.Add(product);
                count++;
            }

            int TotalCost = priceCalculator.GetTotalPrice(listofProducts);

            Assert.AreEqual(TotalCost, 100);
        }
Beispiel #2
0
        public IActionResult Minus([FromBody] ProductObj productId)
        {
            string  sessionId = HttpContext.Request.Cookies["sessionId"];
            Session session   = db.Sessions.FirstOrDefault(x => x.Id.ToString() == sessionId);
            string  userId    = session.UserId;

            ShoppingCartDetail shoppingCartDetail;

            if (session.UserId != null)
            {
                shoppingCartDetail = db.ShoppingCart.FirstOrDefault(x => x.UserId == userId && x.ProductId == productId.ProductId);
            }
            else
            {
                shoppingCartDetail = db.ShoppingCart.FirstOrDefault(x => x.SessionId == sessionId && x.ProductId == productId.ProductId);
            }

            if (shoppingCartDetail.Quantity == 0)
            {
                shoppingCartDetail.Quantity = 0;
            }
            else
            {
                shoppingCartDetail.Quantity -= 1;
            }

            db.SaveChanges();

            return(Json(new
            {
                status = "success",
                quantity = shoppingCartDetail.Quantity
            }));
        }
Beispiel #3
0
        public IActionResult Plus([FromBody] ProductObj productId)
        {
            string  sessionId = HttpContext.Request.Cookies["sessionId"];
            Session session   = db.Sessions.FirstOrDefault(x => x.Id.ToString() == sessionId);
            string  userId    = session.UserId;

            ShoppingCartDetail shoppingCartDetail;

            if (session.UserId != null)
            {
                shoppingCartDetail = db.ShoppingCart.FirstOrDefault(x => x.UserId == userId && x.ProductId == productId.ProductId);
            }
            else
            {
                shoppingCartDetail = db.ShoppingCart.FirstOrDefault(x => x.SessionId == sessionId && x.ProductId == productId.ProductId);
            }

            if (shoppingCartDetail.Quantity == 20)
            {
                shoppingCartDetail.Quantity = 20; //setting a limit of maximum 20 in quantity per product, per transaction
            }
            else
            {
                shoppingCartDetail.Quantity += 1;
            }

            db.SaveChanges();

            return(Json(new
            {
                status = "success",
                quantity = shoppingCartDetail.Quantity
            }));
        }
Beispiel #4
0
        public IActionResult Remove([FromBody] ProductObj productId)
        {
            string  sessionId = HttpContext.Request.Cookies["sessionId"];
            Session session   = db.Sessions.FirstOrDefault(x => x.Id.ToString() == sessionId);

            ShoppingCartDetail shoppingCartDetail;

            if (session.User != null)
            {
                shoppingCartDetail = db.ShoppingCart.FirstOrDefault(x => x.UserId == session.UserId && x.ProductId == productId.ProductId);
            }
            else
            {
                shoppingCartDetail = db.ShoppingCart.FirstOrDefault(x => x.SessionId == sessionId && x.ProductId == productId.ProductId);
            }

            db.ShoppingCart.Remove(shoppingCartDetail);
            db.SaveChanges();

            List <ShoppingCartDetail> list = db.ShoppingCart.Where(x => x.UserId == session.UserId).ToList();

            return(Json(new
            {
                status = "success",
                id = shoppingCartDetail.ProductId,
                count = list.Count,
                url = "/ShoppingCart/Index"
            }));
        }
        public void getProductPrice()
        {
            string     Id      = "a";
            ProductObj product = objProducts.getProduct(Id.ToUpper());

            Assert.AreEqual(50, product.price);
        }
        public void GetTotalCost_3A5B1C1D()
        {
            List <ProductObj> listofProducts = new List <ProductObj>();
            int count = 0;

            for (int i = 0; i < 10; i++)
            {
                string skuType = string.Empty;
                if (count == 0 || count < 3)
                {
                    skuType = "A";
                }
                else if (count >= 3 && count <= 7)
                {
                    skuType = "B";
                }
                else if (count == 8)
                {
                    skuType = "c";
                }
                else if (count == 9)
                {
                    skuType = "d";
                }

                ProductObj product = objProducts.getProduct(skuType.ToUpper());
                listofProducts.Add(product);
                count++;
            }

            int TotalCost = priceCalculator.GetTotalPrice(listofProducts);

            Assert.AreEqual(TotalCost, 280);
        }
Beispiel #7
0
        public async Task <ActionResult <ProductRegRespObj> > AddUpdateProductAsync([FromBody] ProductObj entity)
        {
            try
            {
                var isDone = false;
                var user   = await _identityServer.UserDataAsync();

                var createdBy = user.UserName;
                entity.CreatedBy = createdBy;
                entity.UpdatedBy = createdBy;

                var product = _repo.AddUpdateProduct(entity);

                if (product != null)
                {
                    isDone = true;
                    var allAllowableCollaterals = await _allowableCollateralRepository.GetAllowableCollateralByProductIdAsync(product.ProductId);

                    if (allAllowableCollaterals != null)
                    {
                        await _allowableCollateralRepository.DeleteListAllowableCollateralByProductIdAsync(product.ProductId);
                    }
                    var listOfAallowableCollateral = new List <AllowableCollateralObj>();
                    if (entity.AllowableCollaterals != null)
                    {
                        foreach (var id in entity.AllowableCollaterals)
                        {
                            listOfAallowableCollateral.Add(new AllowableCollateralObj {
                                CollateralTypeId = id, ProductId = product.ProductId
                            });
                        }

                        await _allowableCollateralRepository.AddAllowableCollateral(listOfAallowableCollateral);
                    }
                }
                return(new ProductRegRespObj
                {
                    Products = product,
                    Status = new APIResponseStatus {
                        IsSuccessful = isDone ? true : false, Message = new APIResponseMessage {
                            FriendlyMessage = isDone ? "Successful" : "Unsuccessful"
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                var errorCode = ErrorID.Generate(5);
                _logger.Error($"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}");
                return(new ProductRegRespObj
                {
                    Status = new APIResponseStatus {
                        IsSuccessful = false, Message = new APIResponseMessage {
                            FriendlyMessage = "Error Occurred", TechnicalMessage = ex?.Message, MessageId = errorCode
                        }
                    }
                });
            }
        }
Beispiel #8
0
        public ActionResult GetProductByID(int id)
        {
            ProductBLL productBLL = new ProductBLL();
            ProductObj result     = productBLL.GetProduct(id);

            if (result != null)
            {
                return(Json(new { success = true, data = result }));
            }
            else
            {
                return(Json(new { success = false, msg = "该商品不存在" }));
            }
        }
Beispiel #9
0
        public ActionResult ModiftProductStatus(int id)
        {
            if (!AppData.IsManagerLogin)
            {
                return(Json(new { success = false, msg = "您未登录后台或会话已过期" }));
            }
            if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 404))
            {
                return(Json(new { success = false, msg = "您没有执行该操作的权限" }));
            }

            ProductBLL productBLL = new ProductBLL();

            ProductObj productObj = productBLL.GetProduct(id);
            int        status     = productObj.Status == 1 ? 0 : 1;

            productBLL.ModifyProduct(id, status);

            return(Json(new { success = true }));
        }
Beispiel #10
0
        public ActionResult DeleteProduct(int id)
        {
            if (!AppData.IsManagerLogin)
            {
                return(Json(new { success = false, msg = "您未登录后台或会话已过期" }));
            }
            if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 403))
            {
                return(Json(new { success = false, msg = "您没有执行该操作的权限" }));
            }

            ProductBLL productBLL = new ProductBLL();

            ProductObj productObj = productBLL.GetProduct(id);

            DeletePics(productObj.ProductPictures);
            DeletePics(productObj.Colors);

            productBLL.DeleteProduct(id);

            return(Json(new { success = true }));
        }
Beispiel #11
0
 public void ModifyProduct(ProductObj productObj)
 {
     dal.ModifyProduct(productObj);
 }
Beispiel #12
0
 public void AddProduct(ProductObj productObj)
 {
     dal.AddProduct(productObj);
 }
Beispiel #13
0
        public ActionResult Product(int id)
        {
            ProductBLL productBLL                    = new ProductBLL();
            ProductObj productObj                    = productBLL.GetProduct(id);
            Dictionary <int, string> cates           = new Dictionary <int, string>();
            ProductCateObj           productCateObj  = productBLL.GetProductCateByCateID(productObj.CategoryID);
            IList <ProductCateObj>   productCateList = new List <ProductCateObj>();

            ViewBag.allCates = productBLL.GetProductCates();

            int total;

            productBLL.GetComments(id, 1, 1, out total);

            ViewBag.commentCount = total;
            productBLL.GetMessages(id, 1, 1, out total);
            ViewBag.messageCount = total;

            while (productCateObj != null)
            {
                productCateList.Add(productCateObj);
                productCateObj = productBLL.GetProductCateByCateID(productCateObj.ParentID);
            }
            StringBuilder sb = new StringBuilder();

            for (int i = productCateList.Count - 1; i >= 0; i--)
            {
                sb.Append("&gt;")
                .Append("<a href='/list/")
                .Append(productCateList[i].CategoryID)
                .Append(".html'>")
                .Append(productCateList[i].CategoryName)
                .Append("</a>");
            }
            ViewBag.current = new MvcHtmlString(sb.ToString());
            ViewBag.product = productObj;

            //int totalRecommends;
            //ViewBag.recommends = productBLL.GetProducts(0, null, 0, 0, -1, -1, 1, -1, 1, 10, out  totalRecommends);

            ExpressBLL expressBLL = new ExpressBLL();

            ViewBag.express = expressBLL.GetExpress();

            HttpCookie cookie = Request.Cookies["phistory"];

            if (cookie == null || string.IsNullOrEmpty(cookie.Value))
            {
                cookie             = new HttpCookie("phistory", id.ToString());
                cookie.Expires     = DateTime.Now.AddDays(30);
                ViewBag.recommends = productBLL.GetProducts(new List <int> {
                    id
                });
            }
            else
            {
                string[]    values = cookie.Value.Split(',');
                bool        flag   = false;
                IList <int> hst    = new List <int>();
                for (int i = 0; i < values.Length; i++)
                {
                    hst.Add(int.Parse(values[i]));
                    if (int.Parse(values[i]) == id)
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    hst.Insert(0, id);
                    cookie.Value = "";
                    for (int i = 0; i < hst.Count && i < 10; i++)
                    {
                        if (i != 0)
                        {
                            cookie.Value += ",";
                        }
                        cookie.Value += hst[i].ToString();
                    }
                }
                ViewBag.recommends = productBLL.GetProducts(hst);

                cookie.Expires = DateTime.Now.AddDays(30);
            }
            Response.SetCookie(cookie);

            return(View());
        }
Beispiel #14
0
        public IActionResult Add([FromBody] ProductObj productObj)
        {
            string  sessionId = HttpContext.Request.Cookies["sessionId"];
            Session session   = db.Sessions.FirstOrDefault(x => x.Id.ToString() == sessionId);
            string  userId;
            string  productId = productObj.ProductId;

            if (session == null)
            {
                Session GuestSession = new Session
                {
                    Id                = Guid.NewGuid(),
                    Timestamp         = DateTimeOffset.Now.ToUnixTimeSeconds(),
                    UserId            = null,
                    IsLogin           = false,
                    IsReadyToCheckOut = false
                };

                db.Sessions.Add(GuestSession);
                db.SaveChanges();

                Response.Cookies.Append("sessionId", GuestSession.Id.ToString());

                userId  = GuestSession.UserId;
                session = GuestSession;
            }
            else
            {
                userId = session.UserId;
            }

            //searching for previous records in shoppingcart table
            ShoppingCartDetail cartDetail;

            if (session.User != null)
            {
                cartDetail = db.ShoppingCart.FirstOrDefault(x => x.UserId == userId && x.ProductId == productId);
            }
            else
            {
                cartDetail = db.ShoppingCart.FirstOrDefault(x => x.SessionId == sessionId && x.ProductId == productId);
            }

            if (cartDetail == null)
            {
                ShoppingCartDetail cart = new ShoppingCartDetail()
                {
                    Id        = Guid.NewGuid().ToString(),
                    SessionId = session.Id.ToString(),
                    UserId    = userId,
                    ProductId = productId,
                    Quantity  = 1
                };

                db.ShoppingCart.Add(cart);
            }
            else
            {
                cartDetail.Quantity++;
            }

            db.SaveChanges();

            return(Json(new
            {
                status = "success",
                url = "/ShoppingCart/Index"
            }));
        }
Beispiel #15
0
        public ActionResult ModifyProduct()
        {
            if (!AppData.IsManagerLogin)
            {
                return(Json(new { success = false, msg = "您未登录后台或会话已过期" }));
            }
            if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 402))
            {
                return(Json(new { success = false, msg = "您没有执行该操作的权限" }));
            }

            Validation validation = new Validation();
            ProductBLL productBLL = new ProductBLL();

            int        productId   = validation.GetInt("id");
            string     sCategories = validation.Get("categoryIds", false, "请选择商品类别", @"^\d+(\,\d+)*$", "请选择商品类别");
            ProductObj productObj  = productBLL.GetProduct(productId);

            if (productObj == null)
            {
                return(Json(new { success = false, msg = "您要修改的商品不存在!" }));
            }

            productObj.Name                   = validation.Get("name", false, "请填写商品名称");
            productObj.Type                   = validation.Get("type");
            productObj.Serial                 = validation.Get("serial");
            productObj.Model                  = validation.Get("model");
            productObj.Code                   = validation.Get("code");
            productObj.Material               = validation.Get("material");
            productObj.Weight                 = validation.Get("weight");
            productObj.Characteristic         = validation.Get("characteristic");
            productObj.Designer               = validation.Get("designer");
            productObj.Price                  = validation.GetDecimal("price");
            productObj.SpecialPrice           = validation.GetDecimal("specialPrice");
            productObj.IsNew                  = validation.GetBool("isNew");
            productObj.IsRecommend            = validation.GetBool("IsRecommend");
            productObj.IsOnSale               = validation.GetBool("IsOnSale");
            productObj.CanPurchasedSeparately = validation.GetBool("canPurchasedSeparately");
            productObj.Description            = HttpUtility.UrlDecode(validation.Get("description", false, "请填写商品描述"), Encoding.UTF8);
            productObj.Freight                = validation.GetDecimal("freight");
            productObj.Freight1               = validation.GetDecimal("freight1");
            int quantity = validation.GetInt("quantity");

            productObj.Points    = validation.GetInt("points");
            productObj.Quantity  = quantity;
            productObj.Inventory = productObj.Inventory + quantity - productObj.Quantity;
            string strPics = validation.Get("pics", false, "请上传商品图片", @"\d+(,\d+)*", "参数错误");

            productObj.FreightModels = new List <int>();
            string freightModels = validation.Get("freightModels");
            var    fms           = freightModels.Split(',');

            for (int i = 0; i < fms.Length; i++)
            {
                if (!string.IsNullOrEmpty(fms[i]))
                {
                    productObj.FreightModels.Add(int.Parse(fms[i]));
                }
            }

            if (string.IsNullOrEmpty(strPics))
            {
                return(Json(new { success = false, msg = "请上传商品图片!" }));
            }

            if (validation.HasError)
            {
                return(Json(new { success = false, msg = "参数错误!" }));
            }

            string[] cates = sCategories.Split(',');
            productObj.Categories = new List <int>();
            for (var i = 0; i < cates.Length; i++)
            {
                productObj.Categories.Add(int.Parse(cates[i]));
            }

            string[]          pics = strPics.Split(',');
            ProductPictureObj productPictureObj;

            productObj.ProductPictures = new List <ProductPictureObj>();
            for (int i = 0; i < pics.Length; i++)
            {
                productPictureObj           = new ProductPictureObj();
                productPictureObj.PictureID = int.Parse(pics[i]);
                productObj.ProductPictures.Add(productPictureObj);
            }

            productBLL.ModifyProduct(productObj);

            return(Json(new { success = true }));
        }
Beispiel #16
0
        public IList <Tuple <ExchangeInfo, OrderObj, ProductObj, ProductObj> > GetExchange(int userID, int?orderID = null)
        {
            using (dbc = new SqlHelper())
            {
                string sql = "select a.ExchangeID,a.OrderID,a.AddTime,a.Mobile,a.Phone,a.Address,a.RegionID,a.Zip,a.ReturnProductID,a.ReturnQty,a.ExchangeProductID,a.ExchangeQty,a.Reason,b.OrderCode,b.Receiver,c.Name as ExchangeProductName,c.Price as ExchangeProductPrice,c.IsOnSale as ExchangeProductIsOnSale,c.SpecialPrice as ExchangeProductSpecialPrice,d.Name as ReturnProductName,d.Price as ReturnProductPrice,d.IsOnSale as ReturnProductIsOnSale,d.SpecialPrice as ReturnProductSpecialPrice from Exchange a inner join Orders b on a.OrderID=b.OrderID inner join Products c on a.ExchangeProductID=c.ProductID inner join Products d on a.ReturnProductID=d.ProductID where UserID=@UserID";
                dbc.AddIntParameter("@UserID", userID);
                if (orderID != null)
                {
                    dbc.AddIntParameter("@OrderID", (int)orderID);
                    sql += " and a.OrderID=@OrderID";
                }

                IList <Tuple <ExchangeInfo, OrderObj, ProductObj, ProductObj> > result = null;

                dbc.Read(sql, System.Data.CommandType.Text, dr =>
                {
                    if (dr.HasRows)
                    {
                        result = new List <Tuple <ExchangeInfo, OrderObj, ProductObj, ProductObj> >();
                        ExchangeInfo exchangeInfo;
                        OrderObj orderObj;
                        ProductObj returnProduct;
                        ProductObj exchangeProduct;
                        while (dr.Read())
                        {
                            exchangeInfo                   = new ExchangeInfo();
                            exchangeInfo.ExchangeID        = dr["ExchangeID"] == DBNull.Value ? 0 : (int)dr["ExchangeID"];
                            exchangeInfo.OrderID           = dr["OrderID"] == DBNull.Value ? 0 : (int)dr["OrderID"];
                            exchangeInfo.AddTime           = dr["AddTime"] == DBNull.Value ? DateTime.MinValue : (DateTime)dr["AddTime"];
                            exchangeInfo.Mobile            = dr["Mobile"] == DBNull.Value ? null : (string)dr["Mobile"];
                            exchangeInfo.Phone             = dr["Phone"] == DBNull.Value ? null : (string)dr["Phone"];
                            exchangeInfo.Address           = dr["Address"] == DBNull.Value ? null : (string)dr["Address"];
                            exchangeInfo.RegionID          = dr["RegionID"] == DBNull.Value ? 0 : (int)dr["RegionID"];
                            exchangeInfo.Zip               = dr["Zip"] == DBNull.Value ? null : (string)dr["Zip"];
                            exchangeInfo.ReturnProductID   = dr["ReturnProductID"] == DBNull.Value ? 0 : (int)dr["ReturnProductID"];
                            exchangeInfo.ReturnQty         = dr["ReturnQty"] == DBNull.Value ? 0 : (int)dr["ReturnQty"];
                            exchangeInfo.ExchangeProductID = dr["ExchangeProductID"] == DBNull.Value ? 0 : (int)dr["ExchangeProductID"];
                            exchangeInfo.ExchangeQty       = dr["ExchangeQty"] == DBNull.Value ? 0 : (int)dr["ExchangeQty"];
                            exchangeInfo.Reason            = dr["Reason"] == DBNull.Value ? null : (string)dr["Reason"];

                            orderObj           = new OrderObj();
                            orderObj.OrderID   = exchangeInfo.OrderID;
                            orderObj.OrderCode = dr["OrderCode"] == DBNull.Value ? null : (string)dr["OrderCode"];
                            orderObj.Receiver  = dr["Receiver"] == DBNull.Value ? null : (string)dr["Receiver"];

                            returnProduct              = new ProductObj();
                            returnProduct.ProductID    = exchangeInfo.ReturnProductID;
                            returnProduct.Name         = dr["ReturnProductName"] == DBNull.Value ? null : (string)dr["ReturnProductName"];
                            returnProduct.Price        = dr["ReturnProductPrice"] == DBNull.Value ? 0 : (decimal)dr["ReturnProductPrice"];
                            returnProduct.IsOnSale     = dr["ReturnProductIsOnSale"] == DBNull.Value ? false : (bool)dr["ReturnProductIsOnSale"];
                            returnProduct.Price        = dr["ReturnProductPrice"] == DBNull.Value ? 0 : (decimal)dr["ReturnProductPrice"];
                            returnProduct.SpecialPrice = dr["ReturnProductSpecialPrice"] == DBNull.Value ? 0 : (decimal)dr["ReturnProductSpecialPrice"];

                            exchangeProduct              = new ProductObj();
                            exchangeProduct.ProductID    = exchangeInfo.ExchangeProductID;
                            exchangeProduct.Name         = dr["ExchangeProductName"] == DBNull.Value ? null : (string)dr["ExchangeProductName"];
                            exchangeProduct.Price        = dr["ExchangeProductPrice"] == DBNull.Value ? 0 : (decimal)dr["ExchangeProductPrice"];
                            exchangeProduct.IsOnSale     = dr["ExchangeProductIsOnSale"] == DBNull.Value ? false : (bool)dr["ExchangeProductIsOnSale"];
                            exchangeProduct.Price        = dr["ExchangeProductPrice"] == DBNull.Value ? 0 : (decimal)dr["ExchangeProductPrice"];
                            exchangeProduct.SpecialPrice = dr["ExchangeProductSpecialPrice"] == DBNull.Value ? 0 : (decimal)dr["ExchangeProductSpecialPrice"];

                            result.Add(new Tuple <ExchangeInfo, OrderObj, ProductObj, ProductObj>(exchangeInfo, orderObj, returnProduct, exchangeProduct));
                        }
                    }
                });

                return(result);
            }
        }
Beispiel #17
0
        public ActionResult AddProduct()
        {
            ViewBag.success = false;
            if (!AppData.IsManagerLogin)
            {
                return(Json(new { success = false, msg = "您未登录后台或会话已过期" }));
            }
            if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 401))
            {
                return(Json(new { success = false, msg = "您没有执行该操作的权限" }));
            }

            Validation validation = new Validation();

            string     sCategories = validation.Get("categoryIds", false, "请选择商品类别", @"^\d+(\,\d+)*$", "请选择商品类别");
            ProductObj productObj  = new ProductObj();

            productObj.CategoryID             = validation.GetInt("categoryID");
            productObj.Name                   = validation.Get("name", false, "请填写商品名称");
            productObj.Type                   = validation.Get("type");
            productObj.Serial                 = validation.Get("serial");
            productObj.Model                  = validation.Get("model");
            productObj.Code                   = validation.Get("code");
            productObj.Material               = validation.Get("material");
            productObj.Weight                 = validation.Get("weight");
            productObj.Characteristic         = validation.Get("characteristic");
            productObj.Designer               = validation.Get("designer");
            productObj.Price                  = validation.GetDecimal("price");
            productObj.SpecialPrice           = validation.GetDecimal("specialPrice");
            productObj.IsRecommend            = validation.GetBool("isRecommend");
            productObj.IsOnSale               = validation.GetBool("isOnSale");
            productObj.IsNew                  = validation.GetBool("isNew");
            productObj.CanPurchasedSeparately = validation.GetBool("canPurchasedSeparately");
            productObj.Description            = HttpUtility.UrlDecode(validation.Get("description", false, "请填写商品描述"), Encoding.UTF8);
            productObj.Freight                = validation.GetDecimal("freight");
            productObj.Freight1               = validation.GetDecimal("freight1");
            productObj.Inventory              = validation.GetInt("inventory");
            productObj.Quantity               = productObj.Inventory;
            productObj.Tags                   = validation.Get("tags");
            productObj.Points                 = validation.GetInt("points");
            productObj.Sort                   = DateTime.Now;

            productObj.FreightModels = new List <int>();
            string freightModels = validation.Get("freightModels");
            var    fms           = freightModels.Split(',');

            for (int i = 0; i < fms.Length; i++)
            {
                if (!string.IsNullOrEmpty(fms[i]))
                {
                    productObj.FreightModels.Add(int.Parse(fms[i]));
                }
            }

            string strPics = validation.Get("pics", false, "请上传商品图片", @"\d+(,\d+)*", "参数错误");

            if (validation.HasError || productObj.CategoryID == 0)
            {
                return(Json(new { success = false, msg = "参数错误", errors = validation.GetErrors() }));
            }

            string[] cates = sCategories.Split(',');
            productObj.Categories = new List <int>();
            for (var i = 0; i < cates.Length; i++)
            {
                productObj.Categories.Add(int.Parse(cates[i]));
            }

            string[]          pics = strPics.Split(',');
            ProductPictureObj productPictureObj;

            productObj.ProductPictures = new List <ProductPictureObj>();
            for (int i = 0; i < pics.Length; i++)
            {
                productPictureObj           = new ProductPictureObj();
                productPictureObj.PictureID = int.Parse(pics[i]);
                productObj.ProductPictures.Add(productPictureObj);
            }

            ProductBLL productBLL = new ProductBLL();

            if (productBLL.IsProductExists(productObj.Name))
            {
                return(Json(new { success = false, msg = "该商品名称已存在!" }));
            }

            productBLL.AddProduct(productObj);

            if (productObj.ProductID != 0)
            {
                return(Json(new { success = true, id = productObj.ProductID }));
            }
            else
            {
                return(Json(new { success = false, msg = "抱歉,添加失败!" }));
            }
        }