Esempio n. 1
0
        // GET: Rates
        public ActionResult GetRates(RatesRequest jsonRatesRequest)
        {
            RatesResponse jsonRatesResponse = null;
            bool          isValid           = false;

            //Validate credentials
            try
            {
                isValid = _ratesService.ValidateCredentials();
            }
            catch (Exception ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized, ex.Message));
            }

            if (!isValid)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized, "Invalid Credentials"));
            }

            //Validate request
            try
            {
                isValid = _ratesService.ValidateRequest(jsonRatesRequest);
            }
            catch (Exception ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, ex.Message));
            }

            if (!isValid)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Bad Request"));
            }

            //Proceed to calculates the rates
            try
            {
                jsonRatesResponse = _ratesService.GetShippingRates(jsonRatesRequest);
            }
            catch { }

            if (jsonRatesResponse == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            return(Json(jsonRatesResponse));
        }