Ejemplo n.º 1
0
        /// <summary>
        /// 新增商品
        /// </summary>
        /// <param name="param"></param>
        public void InsertProduct(ProductInsertParam param)
        {
            using (var conn = new MySqlConnection(_configuration["ConnectString"]))
            {
                if (!_category.ExistCategory(param.CategoryID.Value))
                {
                    throw new Exception("CategoryID不存在");
                }

                var result = conn.Insert("MALL.PRODUCT", param);
                if (result == 0)
                {
                    throw new Exception("商品不存在");
                }
            }
        }
Ejemplo n.º 2
0
        public ActionResult Post(ProductInsertParam objProductInsertParam)
        {
            try
            {
                if (objAutorized.ValidateTokenResult == null)
                {
                    return(Ok(new CommonResponse()
                    {
                        error_code = Convert.ToInt32(ErrorCode.Failure), message = "Invalid access."
                    }));
                }
                if (objAutorized.ValidateTokenResult.isValid == false)
                {
                    return(Ok(new CommonResponse()
                    {
                        error_code = Convert.ToInt32(ErrorCode.Failure), message = objAutorized.ValidateTokenResult.error_message
                    }));
                }
                ProductTable objProduct = new ProductTable();
                objProduct.ProdCatId       = objProductInsertParam.ProdCatId;
                objProduct.ProdName        = objProductInsertParam.ProdName;
                objProduct.ProdDescription = objProductInsertParam.ProdDescription;
                ValidationContext vc    = new ValidationContext(objProduct);
                var  validationsResults = new List <ValidationResult>();
                bool correct            = Validator.TryValidateObject(objProduct, vc, validationsResults, true);
                if (!correct)
                {
                    string errorMessage = "";
                    foreach (var item in validationsResults.Select(ov => ov.ErrorMessage))
                    {
                        errorMessage = string.Concat(errorMessage, item);
                    }
                    return(Ok(new CommonResponse()
                    {
                        error_code = Convert.ToInt32(ErrorCode.Failure), message = errorMessage
                    }));
                }
                ProductDBAccess obj = ProductDBAccess.getInstance;
                List <ProductResponse.InsertData> objListData = obj.InsertProduct(objProduct);
                if (objListData.Count == 0)
                {
                    return(Ok(new CommonResponse()
                    {
                        error_code = Convert.ToInt32(ErrorCode.Failure), message = "No data insert."
                    }));
                }

                if (objListData[0].RowEffect == 0)
                {
                    return(Ok(new CommonResponse()
                    {
                        error_code = Convert.ToInt32(ErrorCode.Failure), message = objListData[0].message
                    }));
                }

                return(Ok(new ProductResponse.InsertData()
                {
                    error_code = Convert.ToInt32(ErrorCode.Success),
                    message = objListData[0].message,
                    RowEffect = objListData[0].RowEffect,
                    ProductId = objListData[0].ProductId
                }));
            }
            catch (Exception ex)
            {
                return(Ok(new CommonResponse()
                {
                    error_code = Convert.ToInt32(ErrorCode.Failure), message = ex.Message
                }));
            }
        }
Ejemplo n.º 3
0
 public Response CreateProduct(ProductInsertParam param)
 {
     _product.InsertProduct(param);
     return(new Response("操作成功"));
 }