示例#1
0
        public void CreateProduct(string[] operationParamaters)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(operationParamaters[1]))
                {
                    throw new ArgumentNullException("Code is Invalid");
                }
                decimal price = 0;
                if (!decimal.TryParse(operationParamaters[2], out price))
                {
                    throw new FormatException("Price format is wrong");
                }
                int stock = 0;
                if (!int.TryParse(operationParamaters[3], out stock))
                {
                    throw new FormatException("Stock format is wrong");
                }

                var response = _restClientHelper.CreateProduct(new CreateProductRequest
                {
                    Code  = operationParamaters[1],
                    Price = price,
                    Stock = stock
                });
                Console.WriteLine(response);
            }
            catch (ArgumentNullException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (FormatException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }