Beispiel #1
0
        /// <summary>
        /// 更新商品部分信息
        /// </summary>
        /// <param name="param"></param>
        public void UpdateProduct(long id, ProductUpdateParam param)
        {
            using (var conn = new MySqlConnection(_configuration["ConnectString"]))
            {
                if (param.CategoryID.HasValue && !_category.ExistCategory(param.CategoryID.Value))
                {
                    throw new Exception("CategoryID不存在");
                }

                var result = conn.Update(_productTableName, id, param);
                if (result == 0)
                {
                    throw new Exception("商品不存在");
                }
            }
        }
Beispiel #2
0
        public ActionResult Put(ProductUpdateParam objProductUpdateParam)
        {
            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.ProductId       = objProductUpdateParam.ProductId;
                objProduct.ProdCatId       = objProductUpdateParam.ProdCatId;
                objProduct.ProdName        = objProductUpdateParam.ProdName;
                objProduct.ProdDescription = objProductUpdateParam.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.UpdateData> objListData = obj.UpdateProduct(objProduct);
                if (objListData.Count == 0)
                {
                    return(Ok(new CommonResponse()
                    {
                        error_code = Convert.ToInt32(ErrorCode.Failure), message = "No data update."
                    }));
                }

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

                return(Ok(new ProductResponse.UpdateData()
                {
                    error_code = Convert.ToInt32(ErrorCode.Success),
                    message = objListData[0].message,
                    RowEffect = objListData[0].RowEffect
                }));
            }
            catch (Exception ex)
            {
                return(Ok(new CommonResponse()
                {
                    error_code = Convert.ToInt32(ErrorCode.Failure), message = ex.Message
                }));
            }
        }
 public Response UpdateProduct([Required] long?id, ProductUpdateParam param)
 {
     _product.UpdateProduct(id.Value, param);
     return(new Response("更新商品信息成功"));
 }