예제 #1
0
        public static async Task AddRentalAsync(string title, int quantity)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string> {
                { "Title", title }, { "Quantity", quantity.ToString() }
            };
            FormUrlEncodedContent encodedContent = new FormUrlEncodedContent(parameters);

            using (HttpResponseMessage response = await ShoppingCartController.AddRental(encodedContent))
            {
                int    status = (int)response.StatusCode;
                string body   = await response.Content.ReadAsStringAsync();

                if (status == 200)
                {
                    return;
                }
                else if (status == 400)
                {
                    throw new ArgumentException(body);
                }
                else if (status == 401)
                {
                    throw new UnauthenticatedException();
                }
                else if (status == 404)
                {
                    throw new RentalDoesNotExistException();
                }
                else if (status == 500)
                {
                    throw new ServerException();
                }
                else
                {
                    throw new Exception("An uncaught error occurred.");
                }
            }
        }