示例#1
0
        public List <ProductAttributeResponse.InsertData> InsertProductAttribute(ProductAttributeTable objProductAttributeTable)
        {
            List <ProductAttributeResponse.InsertData> getProductCategoryList = new List <ProductAttributeResponse.InsertData>();

            try
            {
                var values = new { AttributeId = objProductAttributeTable.AttributeId, ProductId = objProductAttributeTable.ProductId, AttributeValue = objProductAttributeTable.AttributeValue, Action = "1" };
                using (IDbConnection con = new SqlConnection(ConString.GetConnectionString))
                {
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }

                    getProductCategoryList = con.Query <ProductAttributeResponse.InsertData>("[dbo].[InsertOrUpdateOrDeleteProductAttribute]", values, commandType: CommandType.StoredProcedure).ToList();
                }
                return(getProductCategoryList);
            }
            catch (Exception)
            {
                return(getProductCategoryList);
            }
        }
        public ActionResult Put(ProductAttributeUpdateParam 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
                    }));
                }
                ProductAttributeTable objProduct = new ProductAttributeTable();
                objProduct.AttributeId    = objProductUpdateParam.AttributeId;
                objProduct.ProductId      = objProductUpdateParam.ProductId;
                objProduct.AttributeValue = objProductUpdateParam.AttributeValue;
                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
                    }));
                }
                ProductAttributeDBAccess obj = ProductAttributeDBAccess.getInstance;
                List <ProductAttributeResponse.UpdateData> objListData = obj.UpdateProductAttribute(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 ProductAttributeResponse.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
                }));
            }
        }