public void Validate_booking_request_json(ref string data, ref string error_response, ref string request_format, ref LTLBookRequest ltl_book_request) { Models.Public.LTL.Helper public_helper = new Models.Public.LTL.Helper(); Parser parser = new Parser(); bool is_request_valid_json = false; //Xml_helper xml_helper = new Xml_helper(); Json_helper json_helper = new Json_helper(); StringBuilder logger = new StringBuilder(); if ((data.StartsWith("{") && data.EndsWith("}")) || // For object (data.StartsWith("[") && data.EndsWith("]"))) // For array { #region JSON request_format = "JSON"; DB.LogGenera(iam, "Public API request_format", request_format); is_request_valid_json = json_helper.Is_request_valid_json(ref data); if (is_request_valid_json == true) { try { ltl_book_request = new JavaScriptSerializer().Deserialize <LTLBookRequest>(data); if (string.IsNullOrEmpty(ltl_book_request.bookingKey)) { error_response = json_helper.Build_error_response("401", "Please give bookingKey"); return; } int units = 0; for (byte i = 0; i < ltl_book_request.items.Count; i++) { //units += ltl_book_request.items[i].units; } #region Log info #region Not used /* * DB.LogGenera(iam, "ltl_book_request.bookingKey", ltl_book_request.bookingKey); * DB.LogGenera(iam,"ltl_book_request.originZip", ltl_book_request.originZip); * DB.LogGenera(iam,"ltl_book_request.originCity", ltl_book_request.originCity); * DB.LogGenera(iam,"ltl_book_request.originState", ltl_book_request.originState); * * DB.LogGenera(iam,"ltl_book_request.destinationZip", ltl_book_request.destinationZip); * DB.LogGenera(iam,"ltl_book_request.destinationCity", ltl_book_request.destinationCity); * DB.LogGenera(iam,"ltl_book_request.destinationState", ltl_book_request.destinationState); * * DB.LogGenera(iam,"ltl_book_request.pickupDate", ltl_book_request.pickupDate.ToShortDateString()); * * DB.LogGenera(iam,"ltl_book_request.originAddress1", ltl_book_request.originAddress1); * DB.LogGenera(iam,"ltl_book_request.originAddress2", ltl_book_request.originAddress2); * DB.LogGenera(iam,"ltl_book_request.originState", ltl_book_request.originState); * //DB.LogGenera(iam,"additionalServices.TSD", ltl_book_request.additionalServices.TSD.ToString()); * * //DB.LogGenera(iam,"ltl_book_request.linealFeet", ltl_book_request.linealFeet.ToString()); * * //DB.LogGenera(iam,"ltl_book_request.totalCube", ltl_book_request.totalCube.ToString()); */ #endregion logger.Append( string.Concat( "bookingKey: ", ltl_book_request.bookingKey, "linealFeet: ", ltl_book_request.linealFeet.ToString(), "totalCube: ", ltl_book_request.totalCube.ToString(), "originZip: ", ltl_book_request.originZip, "originCity: ", ltl_book_request.originCity, "originState: ", ltl_book_request.originState, "destinationZip: ", ltl_book_request.destinationZip, "destinationCity: ", ltl_book_request.destinationCity, "destinationState: ", ltl_book_request.destinationState, "pickupDate: ", ltl_book_request.pickupDate.ToShortDateString(), "originAddress1: ", ltl_book_request.originAddress1, "originAddress2: ", ltl_book_request.originAddress2, "originState: ", ltl_book_request.originState ) ); #region Add freight items to logger for (byte i = 0; i < ltl_book_request.items.Count; i++) { logger.Append( string.Concat( "items[", i, "].freightClass ", ltl_book_request.items[i].freightClass, ", ", "items[", i, "].weight", ltl_book_request.items[i].weight, ", ", "items[", i, "].commodity ", ltl_book_request.items[i].commodity, ", ", "items[", i, "].type ", ltl_book_request.items[i].type, ", ", "items[", i, "].description ", ltl_book_request.items[i].description, ", ", "items[", i, "].hazmat ", ltl_book_request.items[i].hazmat, ", ", "items[", i, "].length ", ltl_book_request.items[i].length, ", ", "items[", i, "].width ", ltl_book_request.items[i].width, ", ", "items[", i, "].height ", ltl_book_request.items[i].height, ", ", "items[", i, "].units ", ltl_book_request.items[i].units, ", ", "items[", i, "].pieces ", ltl_book_request.items[i].pieces, ", ", "items[", i, "].tag ", ltl_book_request.items[i].tag ) ); #region Not used /* * DB.LogGenera(iam,"Item", * string.Concat( * "items[", i, "].freightClass ", * ltl_book_request.items[i].freightClass, ", ", * "items[", i, "].weight", * ltl_book_request.items[i].weight, ", ", * * "items[", i, "].commodity ", * ltl_book_request.items[i].commodity, ", ", * "items[", i, "].type ", * ltl_book_request.items[i].type, ", ", * "items[", i, "].description ", * ltl_book_request.items[i].description, ", ", * * "items[", i, "].hazmat ", * ltl_book_request.items[i].hazmat, ", ", * "items[", i, "].length ", * ltl_book_request.items[i].length, ", ", * "items[", i, "].width ", * ltl_book_request.items[i].width, ", ", * "items[", i, "].height ", * ltl_book_request.items[i].height, ", ", * "items[", i, "].units ", * ltl_book_request.items[i].units, ", ", * "items[", i, "].pieces ", * ltl_book_request.items[i].pieces, ", ", * * "items[", i, "].tag ", * ltl_book_request.items[i].tag * * ) * * * ); */ #endregion #endregion } DB.LogGenera(iam, "Logger", logger.ToString()); #endregion } catch (Exception e) { DB.LogGenera(iam, "Deserialize", e.ToString()); error_response = json_helper.Build_error_response("400", ""); } } else { error_response = json_helper.Build_booking_error_response("400", "JSON Request was not properly formatted"); } #endregion } else { #region Request format was not valid DB.LogGenera(iam, "WS Request was not valid JSON", data); //Xml_helper xml_helper = new Xml_helper(); //error_response = xml_helper.Build_error_response("400", "Request was not properly formatted", // ref request_format); error_response = json_helper.Build_error_response("400", "Request was not properly formatted"); #endregion } }
public void Validate_request_json(ref string data, ref string url_string, ref string error_response, ref string request_format, ref LTLQuoteRequest ltl_quote_request) { //StringBuilder log = new StringBuilder(); Parser parser = new Parser(); bool is_request_valid_json = false; Xml_helper xml_helper = new Xml_helper(); Json_helper json_helper = new Json_helper(); if ((data.StartsWith("{") && data.EndsWith("}")) || // For object (data.StartsWith("[") && data.EndsWith("]"))) // For array { #region JSON //is_json = true; // Request is JSON request_format = "JSON"; //DB.LogGenera(iam,"Public API request_format", request_format); is_request_valid_json = json_helper.Is_request_valid_json(ref data); if (is_request_valid_json == true) { ltl_quote_request = new JavaScriptSerializer().Deserialize <LTLQuoteRequest>(data); //DB.LogGenera(iam,"ltl_quote_request.originZip", ltl_quote_request.originZip); //DB.LogGenera(iam,"ltl_quote_request.originCity", ltl_quote_request.originCity); //DB.LogGenera(iam,"ltl_quote_request.originState", ltl_quote_request.originState); //DB.LogGenera(iam,"ltl_quote_request.originZip", ltl_quote_request.destinationZip); //DB.LogGenera(iam,"ltl_quote_request.destinationCity", ltl_quote_request.destinationCity); //DB.LogGenera(iam,"ltl_quote_request.destinationState", ltl_quote_request.destinationState); //DB.LogGenera(iam,"ltl_quote_request.pickupDate", ltl_quote_request.pickupDate.ToShortDateString()); //for (byte i = 0; i < ltl_quote_request.items.Count; i++) //{ // DB.LogGenera(iam,"ltl_quote_request.items[i].freightClass", ltl_quote_request.items[i].freightClass + " " + // ltl_quote_request.items[i].weight); //} //DB.LogGenera(iam,"additionalServices.TSD", ltl_quote_request.additionalServices.TSD.ToString()); //DB.LogGenera(iam,"ltl_quote_request.linealFeet", ltl_quote_request.linealFeet.ToString()); //DB.LogGenera(iam,"ltl_quote_request.totalCube", ltl_quote_request.totalCube.ToString()); } else { error_response = json_helper.Build_error_response("400", "JSON Request was not properly formatted"); } #endregion } else { #region Request format was not valid DB.LogGenera(iam, "WS Request was not valid JSON or XML", data); error_response = xml_helper.Build_error_response("400", "Request was not properly formatted", ref request_format); #endregion } }