예제 #1
0
        public HttpResponseMessage Post()
        {
            try
            {
                //--
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                //--

                #region Authentication

                var re      = Request;
                var headers = re.Headers;

                string username = "", password = "";

                if (headers.Contains("username"))
                {
                    username = headers.GetValues("username").First();
                    DB.LogGenera(iam, "username", username);
                }
                else
                {
                    DB.LogGenera(iam, "username", "none found");
                }

                if (headers.Contains("password"))
                {
                    password = headers.GetValues("password").First();
                    DB.LogGenera(iam, "password", password);
                }
                else
                {
                    DB.LogGenera(iam, "password", "none found");
                }

                #endregion

                string data = this.Request.Content.ReadAsStringAsync().Result;

                DB.LogGenera("Get_LTL_ratesController " + AppCodeConstants.mode, "Public API data", data);

                string url_string = "", request_format = "", error_response = "", response_string = "",
                       content_type = "application/json";

                LTLQuoteRequest ltl_quote_request = new LTLQuoteRequest();
                QuoteData       quoteData         = new QuoteData();

                #region Parse/Deserialize request, make sure JSON is valid

                // Parse/Deserialize request, make sure JSON is valid
                Validator vld = new Validator();
                vld.Validate_request_json(ref data, ref url_string, ref error_response, ref request_format,
                                          ref ltl_quote_request);

                #endregion

                // Xml_helper xml_helper = new Xml_helper();
                Json_helper json_helper = new Json_helper();

                Models.Public.LTL.Helper public_helper = new Models.Public.LTL.Helper();

                //DB.LogGenera(iam, "Public API url_string", url_string);
                //DB.LogGenera(iam, "Public API error_response", error_response);

                //DB.LogGenera(iam, "Public API url_string", url_string);

                string sql = "";
                if (error_response == "")
                {
                    // Do nothing
                }
                else
                {
                    //return error_response;
                    response_string = error_response;
                    var response_message = public_helper.Get_response_message(ref response_string, ref content_type);
                    sql = string.Concat("INSERT INTO Genera_Rating(QuoteID,Request_Data,Response_Data,TotalCube) VALUES(",
                                        "0,'", data, "','", response_string, "',", ltl_quote_request.totalCube,
                                        ")");
                    HelperFuncs.ExecuteNonQuery(AppCodeConstants.connStringAesAPI, ref sql, "Get_LTL_ratesController");

                    return(response_message);
                }


                // If got to here, request is valid JSON or XML
                // Convert JSON or XML to URL Encoded string and get GCM rates

                url_string = string.Concat("username="******"&password="******"&mode=ws&subdomain=www&showDLSRates=True",
                                           "&isHHG=False&isUSED=False",
                                           url_string);

                //DB.LogGenera(iam, "Public API url_string", url_string);



                Models.LTL.Helper helper = new Models.LTL.Helper();

                helper.Set_parameters(ref ltl_quote_request, ref quoteData);
                quoteData.username     = username;
                quoteData.showDLSRates = true;
                quoteData.subdomain    = "www";

                #region Check for > 4 line items

                if (quoteData.m_lPiece.Length > 4)
                {
                    DB.LogGenera(iam, "m_lPiece.Length > 4", "true");
                    response_string = json_helper.Build_error_response("35",
                                                                       "Too many freight item nodes, maximum number of item nodes is 4");

                    return(public_helper.Get_response_message(ref response_string, ref content_type));
                }
                else
                {
                    DB.LogGenera(iam, "m_lPiece.Length > 4", "false");
                }

                #endregion

                Validator validator = new Validator(ref quoteData);
                RateServiceNotification validation_result = validator.Validate_rating_request();

                #region If validation was not successful return error result

                if (validation_result.Code == "0")
                {
                    // Do nothing
                    DB.LogGenera(iam, "validation_result.Code", validation_result.Code);
                }
                else
                {
                    DB.LogGenera(iam, "validation_result.Code", validation_result.Code);

                    response_string = json_helper.Build_error_response(validation_result.Code, validation_result.Message);

                    var response_message = public_helper.Get_response_message(ref response_string, ref content_type);

                    sql = string.Concat("INSERT INTO Genera_Rating(QuoteID,Request_Data,Response_Data,TotalCube) VALUES(",
                                        "0,'", data, "','", response_string, "',", ltl_quote_request.totalCube,
                                        ")");
                    HelperFuncs.ExecuteNonQuery(AppCodeConstants.connStringAesAPI, ref sql, "Get_LTL_ratesController");

                    return(response_message);
                }

                #endregion

                quoteData.destCity = quoteData.destCity.Replace(" Twp", " Township");
                quoteData.origCity = quoteData.origCity.Replace(" Twp", " Township");

                LTL_Carriers             carriers = new LTL_Carriers(quoteData);
                SharedLTL.CarriersResult result   = carriers.GetRates();

                #region If any rates were found return rates, if not give error result

                if (result.totalQuotes == null || result.totalQuotes.Length == 0)
                {
                    #region If did not find any rates return error result

                    // If did not find any rates return error result

                    response_string = json_helper.Build_error_response("2",
                                                                       string.Concat("Could not find any rates. Please try again."));

                    var response_message = public_helper.Get_response_message(ref response_string, ref content_type);
                    sql = string.Concat("INSERT INTO Genera_Rating(QuoteID,Request_Data,Response_Data,TotalCube) VALUES(",
                                        "0,'", data, "','", response_string, "',", ltl_quote_request.totalCube,
                                        ")");
                    HelperFuncs.ExecuteNonQuery(AppCodeConstants.connStringAesAPI, ref sql, "Get_LTL_ratesController");

                    return(response_message);

                    #endregion
                }
                else
                {
                    string[] additionalServices = new string[0];

                    string requestId;

                    public_helper.StoreLTLRequestsSql(
                        ref quoteData, ref result.totalQuotes, result.totalQuotes[0].NewLogId, data, response_string,
                        out requestId);

                    response_string = json_helper.Build_response(ref result.totalQuotes);

                    var response_message = public_helper.Get_response_message(ref response_string, ref content_type);

                    #region INSERT INTO Genera_Rating

                    sql = string.Concat("INSERT INTO Genera_Rating(QuoteID,Request_Data,Response_Data,TotalCube) VALUES(",
                                        result.totalQuotes[0].NewLogId, ",'", data, "','", response_string, "',", ltl_quote_request.totalCube,
                                        ")");
                    HelperFuncs.ExecuteNonQuery(AppCodeConstants.connStringAesAPI, ref sql, "Get_LTL_ratesController");

                    #endregion

                    #region INSERT INTO ResponseTimes
                    // INSERT INTO ResponseTimes

                    int UPS_freight_milliseconds = 0, SMTL_milliseconds = 0, BestOvernite_milliseconds = 0, NewPenn_milliseconds = 0,
                        RL_milliseconds = 0, RRD_Truckload_milliseconds = 0;

                    foreach (GCMRateQuote quote in result.totalQuotes)
                    {
                        //DB.LogGenera("quote.DisplayName", "quote.DisplayName", quote.DisplayName);
                        if (quote.DisplayName == "UPS - Genera")
                        {
                            UPS_freight_milliseconds = quote.Elapsed_milliseconds;
                        }
                        else if (quote.DisplayName == "SMTL - Genera")
                        {
                            SMTL_milliseconds = quote.Elapsed_milliseconds;
                        }
                        else if (quote.DisplayName == "Best Overnite - Genera")
                        {
                            BestOvernite_milliseconds = quote.Elapsed_milliseconds;
                        }
                        else if (quote.DisplayName == "New Penn - Genera")
                        {
                            NewPenn_milliseconds = quote.Elapsed_milliseconds;
                        }
                        else if (quote.DisplayName == "R&L Carrier - Genera")
                        {
                            RL_milliseconds = quote.Elapsed_milliseconds;
                        }
                        else if (quote.DisplayName == "RRD Truckload")
                        {
                            RRD_Truckload_milliseconds = quote.Elapsed_milliseconds;
                        }
                    }

                    stopwatch.Stop();
                    int elapsedMilliseconds = (int)stopwatch.ElapsedMilliseconds;

                    //int seconds = elapsedMilliseconds / 1000;

                    //int gcm_time = 0;
                    sql = string.Concat("INSERT INTO Rate_response_times(",
                                        "QuoteID,RequestID,GCM_API,DLS,UPS_freight,SMTL,BestOvernite,NewPenn,RL,P44,Truckload) VALUES(",
                                        result.totalQuotes[0].NewLogId, ",'", requestId, "',", elapsedMilliseconds, ",", result.elapsed_milliseconds_DLS_Genera,
                                        ",", UPS_freight_milliseconds, ",", SMTL_milliseconds, ",", BestOvernite_milliseconds, ",", NewPenn_milliseconds,
                                        ",", RL_milliseconds, ",", result.elapsed_milliseconds_P44, ",", RRD_Truckload_milliseconds,
                                        ")");

                    HelperFuncs.ExecuteNonQuery(AppCodeConstants.conn_string_Genera, ref sql, "Get_LTL_ratesController");

                    #endregion

                    return(response_message);
                }

                #endregion
            }
            catch (Exception e)
            {
                #region Unknown error

                DB.LogGenera(iam, "get_ltl_rates_test", e.ToString());

                Json_helper json_helper = new Json_helper();

                string response_string = "";

                response_string = json_helper.Build_error_response("2",
                                                                   string.Concat("Could not find any rates. Please try again."));

                Models.Public.LTL.Helper public_helper = new Models.Public.LTL.Helper();
                string content_type = "application/json";
                return(public_helper.Get_response_message(ref response_string, ref content_type));

                #endregion
            }
        }
예제 #2
0
    public string MakeBookingViaSOAP(ref LTLBookRequest ltl_book_request, ref string username, ref string password)
    {
        //gcmAPI.gcmWebService.LTLBookingReply lbr;

        try
        {
            //return "{ \"Notification\" : \"temporily stopped service\" }";

            #region Testing

            StringBuilder logger = new StringBuilder();

            //ltl_book_request.lineItems.Length;
            logger.Append(string.Concat("lineItems.Length: ", ltl_book_request.items.Count, ", "));
            logger.Append(string.Concat("shipmentDate: ", ltl_book_request.pickupDate, ", "));
            logger.Append(string.Concat("bookingKey: ", ltl_book_request.bookingKey, ", "));
            logger.Append(string.Concat("customerType: ", ltl_book_request.customerType, ", "));

            logger.Append(string.Concat("origName: ", ltl_book_request.originName, ", "));
            logger.Append(string.Concat("origEmail: ", ltl_book_request.originEmail, ", "));
            logger.Append(string.Concat("origCompany: ", ltl_book_request.originCompany, ", "));
            logger.Append(string.Concat("origPhone: ", ltl_book_request.originPhone, ", "));
            logger.Append(string.Concat("origFax: ", ltl_book_request.originFax, ", "));
            logger.Append(string.Concat("origAddress1: ", ltl_book_request.originAddress1, ", "));
            logger.Append(string.Concat("origAddress2: ", ltl_book_request.originAddress2, ", "));
            logger.Append(string.Concat("origCity: ", ltl_book_request.originCity, ", "));
            logger.Append(string.Concat("origState: ", ltl_book_request.originState, ", "));
            logger.Append(string.Concat("origZip: ", ltl_book_request.originZip, ", "));

            logger.Append(string.Concat("destName: ", ltl_book_request.destinationName, ", "));
            logger.Append(string.Concat("destEmail: ", ltl_book_request.destinationEmail, ", "));
            logger.Append(string.Concat("destCompany: ", ltl_book_request.destinationCompany, ", "));
            logger.Append(string.Concat("destPhone: ", ltl_book_request.destinationPhone, ", "));
            logger.Append(string.Concat("destFax: ", ltl_book_request.destinationFax, ", "));
            logger.Append(string.Concat("destAddress1: ", ltl_book_request.destinationAddress1, ", "));
            logger.Append(string.Concat("destAddress2: ", ltl_book_request.destinationAddress2, ", "));
            logger.Append(string.Concat("destCity: ", ltl_book_request.destinationCity, ", "));
            logger.Append(string.Concat("destState: ", ltl_book_request.destinationState, ", "));
            logger.Append(string.Concat("destZip: ", ltl_book_request.destinationZip, ", "));


            HelperFuncs.writeToSiteErrors("LTL Booking Restful", logger.ToString());

            #endregion

            #region Not used
            //logger.Append(string.Concat("shipmentDate: ", ltl_book_request.shipmentDate, ", "));

            //if(j

            //if (!DateTime.TryParse(ltl_book_request.shipmentDate, out shipmentDate))
            //{
            //    shipmentDate = DateTime.Today.AddDays(1);
            //}



            // Authenticate to the web service/API
            //string sessionId = rs.Authenticate(apiUserName, apiKey);

            //// Initialize SOAP header for authentication
            //rs.AuthHeaderValue = new MyWebReference.AuthHeader();

            //// Set session id to the SOAP header
            //rs.AuthHeaderValue.SessionID = sessionId;
            #endregion

            DateTime shipmentDate = ltl_book_request.pickupDate;

            // Initialize web service/API object
            gcmAPI.gcmWebService.RateService2 rs = new gcmAPI.gcmWebService.RateService2();

            string bookingKey = ltl_book_request.bookingKey;

            string customerType = ltl_book_request.customerType; //Set customer type

            gcmAPI.gcmWebService.BookingThirdPartyBilling thirdPartyBilling = null;
            //DateTime shipmentDate = DateTime.Now.Date; //Set shipment date

            string readyTime = "02:15 PM"; //Set ready time of the shipment
            string closeTime = "06:15 PM"; //Set close time of the shipment

            //string readyTime = "10"; //Set ready time of the shipment
            //string closeTime = "3"; //Set close time of the shipment

            string bolSendTo = "EML"; //Set BOL sending option
            //string poNumber = "45455"; //Set PO Number
            string poNumber = null;   //Set PO Number

            #region Origin and Destination

            // Set pickup location
            gcmAPI.gcmWebService.BookingPickupLocation pickupLocation = new gcmAPI.gcmWebService.BookingPickupLocation();
            pickupLocation.Name                = ltl_book_request.originName;
            pickupLocation.Email               = ltl_book_request.originEmail;
            pickupLocation.Company             = ltl_book_request.originCompany;
            pickupLocation.Phone               = ltl_book_request.originPhone;
            pickupLocation.Fax                 = ltl_book_request.originFax;
            pickupLocation.Address1            = ltl_book_request.originAddress1;
            pickupLocation.Address2            = ltl_book_request.originAddress2;
            pickupLocation.City                = ltl_book_request.originCity;
            pickupLocation.State               = ltl_book_request.originState;
            pickupLocation.Zip                 = ltl_book_request.originZip;
            pickupLocation.DispatchAddressesId = 1;

            // Set destination location
            gcmAPI.gcmWebService.BookingDestinationLocation destinationLocation = new gcmAPI.gcmWebService.BookingDestinationLocation();
            destinationLocation.Name     = ltl_book_request.destinationName;
            destinationLocation.Email    = ltl_book_request.destinationEmail;
            destinationLocation.Company  = ltl_book_request.destinationCompany;
            destinationLocation.Phone    = ltl_book_request.destinationPhone;
            destinationLocation.Fax      = ltl_book_request.destinationFax;
            destinationLocation.Address1 = ltl_book_request.destinationAddress1;
            destinationLocation.Address2 = ltl_book_request.destinationAddress2;
            destinationLocation.City     = ltl_book_request.destinationCity;
            destinationLocation.State    = ltl_book_request.destinationState;
            destinationLocation.Zip      = ltl_book_request.destinationZip;

            #endregion

            //string SessionID = ltl_book_request.SessionID;
            //logger.Append(string.Concat("SessionID: ", ltl_book_request.SessionID, ", "));

            //int testInt;
            List <gcmAPI.gcmWebService.LTLBookingPiece> bookingLineItems = new List <gcmAPI.gcmWebService.LTLBookingPiece>();

            for (byte i = 0; i < ltl_book_request.items.Count; i++)
            {
                gcmAPI.gcmWebService.LTLBookingPiece lineItem = new gcmAPI.gcmWebService.LTLBookingPiece();
                lineItem.Tag         = ltl_book_request.items[i].tag;
                lineItem.Description = ltl_book_request.items[i].description;
                if (ltl_book_request.items[i].units > 0)
                {
                    lineItem.NumberOfPallet = ltl_book_request.items[i].units;
                }
                else if (ltl_book_request.items[i].pieces > 0)
                {
                    lineItem.NumberOfPallet = ltl_book_request.items[i].pieces;
                }
                else
                {
                    lineItem.NumberOfPallet = 1;
                }


                // Testing
                logger.Append(string.Concat("Tag", i.ToString(), ": ", lineItem.Tag, ", "));
                logger.Append(string.Concat("Description", i.ToString(), ": ", lineItem.Description, ", "));
                logger.Append(string.Concat("NumberOfPallet", i.ToString(), ": ", lineItem.NumberOfPallet, ", "));

                bookingLineItems.Add(lineItem);
            }


            HelperFuncs.writeToSiteErrors("LTL Booking Restful", logger.ToString());

            #region Not used
            //Set other line items
            //gcmWebService.LTLBookingPiece[] bookingLineItems = new gcmWebService.LTLBookingPiece[1];

            //Set first line item for booking
            //bookingLineItems[0] = new gcmWebService.LTLBookingPiece();

            //// This tag is related to the object(LTLPiece) in lineItems array which is used in GetLTLBookingRate function call
            //bookingLineItems[0].Tag = form.Get("Tag");

            ////bookingLineItems[0].NMFC = 50;
            //bookingLineItems[0].NumberOfPallet = 1;
            //bookingLineItems[0].Description = form.Get("Description");

            //Set second line item for booking
            //bookingLineItems[1] = new MyWebReference.LTLBookingPiece();

            ////// This tag is related to the object(LTLPiece) in lineItems array which is used in GetLTLBookingRate function call
            //bookingLineItems[1].Tag = "2";

            //bookingLineItems[1].NMFC = 60;
            //bookingLineItems[1].NumberOfPallet = 10;
            //bookingLineItems[1].Description = "TEST";
            #endregion

            string comments = "TEST";
            //string comments = null;
            //bool insuranceRequired = true;
            bool   insuranceRequired = false;
            double declaredValue     = 100;

            //
            //Book an LTL rate and getting the BOL and insurance certificate PDF url
            gcmAPI.gcmWebService.LTLBookingReply lbr = rs.CreateLTLBooking_3(username, password, bookingKey, customerType, thirdPartyBilling, shipmentDate, readyTime, closeTime, bolSendTo,
                                                                             poNumber, pickupLocation, destinationLocation, bookingLineItems.ToArray(), comments, insuranceRequired, declaredValue);

            HelperFuncs.writeToSiteErrors("LTL Booking Restful result", string.Concat("notification=", lbr.Notification,
                                                                                      "&shipmentID=", lbr.ShipmentId, "&=BOLURL", lbr.BOLURL));

            //
            DB.Log("before DLS Shipment Import", "before DLS Shipment Import");
            #region DLS Shipment Import

            try
            {
                var          repo = new gcmAPI.Models.Public.LTL.Repository();
                AES_API_info api_info;
                repo.Get_booking_info_by_booking_key(ltl_book_request.bookingKey, out api_info);

                HelperFuncs.dlsShipInfo     dlsInfo         = new HelperFuncs.dlsShipInfo();
                HelperFuncs.DispatchInfo    dispatchInfo    = new HelperFuncs.DispatchInfo();
                HelperFuncs.AccessorialsObj AccessorialsObj = new HelperFuncs.AccessorialsObj();

                DLS_ShipmentImport shipment_import = new DLS_ShipmentImport(ref dlsInfo, ref dispatchInfo, ref api_info, ref AccessorialsObj,
                                                                            ref username, lbr.ShipmentId);
                shipment_import.Set_DLS_ShipmentImport_objects(ref ltl_book_request, ref api_info);

                //DB.Log("dispatchInfo.username", dispatchInfo.username);

                string DLS_PrimaryReferencePNW = "";

                DB.Log("before ShipmentImportDLS", "before ShipmentImportDLS");

                //shipment_import.ShipmentImportDLS(ref DLS_PrimaryReferencePNW);

                DB.Log("after ShipmentImportDLS", "after ShipmentImportDLS");
            }
            catch (Exception e)
            {
                DB.Log("MakeBookingViaSOAP DLS Shipment Import", e.ToString());
            }
            DB.Log("after DLS Shipment Import", "after DLS Shipment Import");
            #endregion

            // Insert DLS_PrimaryReferencePNW into DB


            return(lbr.ToJSON());

            //return string.Concat("{ \"notification\" : \"", lbr.Notification, "\", \"shipmentID\" : ", lbr.ShipmentId, ", \"BOLURL", lbr.BOLURL, " }");

            //return "test test";
        }
        catch (Exception e)
        {
            HelperFuncs.writeToSiteErrors("LTL Booking Restful", e.ToString());
            Json_helper json_helper = new Json_helper();
            return(json_helper.Build_error_response("1", "An error occurred while processing the request"));

            //return "{ \"Notification\" : \"error\" }";
            //return lbr.ToJSON;
        }
    }
예제 #3
0
        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
            }
        }
예제 #4
0
        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
            }
        }
예제 #5
0
        public HttpResponseMessage Post()
        {
            try
            {
                #region Authentication

                var re      = Request;
                var headers = re.Headers;

                string username = "", password = "";

                if (headers.Contains("username"))
                {
                    username = headers.GetValues("username").First();
                    DB.LogGenera(iam, "username", username);
                }
                else
                {
                    DB.LogGenera(iam, "username", "none found");
                }

                if (headers.Contains("password"))
                {
                    password = headers.GetValues("password").First();
                    DB.LogGenera(iam, "password", password);
                }
                else
                {
                    DB.LogGenera(iam, "password", "none found");
                }

                #endregion

                string data = this.Request.Content.ReadAsStringAsync().Result;

                DB.LogGenera(iam, "Public API cancel_ltl_book_test data", data);

                LTLCancelBookRequest ltl_cancel_book_request = new LTLCancelBookRequest();
                ltl_cancel_book_request = new JavaScriptSerializer().Deserialize <LTLCancelBookRequest>(data);

                Models.Public.LTL.Helper public_helper = new Models.Public.LTL.Helper();
                string content_type    = "application/json";
                string response_string = "success";

                if (ltl_cancel_book_request == null || ltl_cancel_book_request.PNW == null)
                {
                    response_string = "To cancel booking please give a valid PNW number, you gave: null";
                    return(public_helper.Get_response_message(ref response_string, ref content_type));
                }


                if (ltl_cancel_book_request.PNW.Contains("PNW"))
                {
                    // Do nothing
                }
                else
                {
                    response_string = "To cancel booking please give a valid PNW number, you gave: " + ltl_cancel_book_request.PNW;
                    return(public_helper.Get_response_message(ref response_string, ref content_type));
                }

                string po = "", our_first_carrier = "", genera_first_carrier = "",
                       our_first_cost_str = "", genera_first_cost_str = "";
                decimal our_first_cost = 0m, genera_first_cost = 0m;

                public_helper.Get_cancelled_pnw_info(ltl_cancel_book_request.PNW, ref po,
                                                     ref our_first_carrier, ref genera_first_carrier, ref our_first_cost, ref genera_first_cost);

                //
                if (genera_first_cost > 0m)
                {
                    genera_first_cost_str = genera_first_cost.ToString();
                }
                //

                //StringBuilder email_body = new StringBuilder();
                //email_body.Append(string.Concat("Please cancel Pickup for ", ltl_cancel_book_request.PNW));

                #region Send email to CS
                // Send email to CS
                EmailInfo info = new EmailInfo();
                //info.body = string.Concat("Please cancel Pickup for ", ltl_cancel_book_request.PNW);
                info.body = string.Concat("Please cancel Pickup for ", ltl_cancel_book_request.PNW, "<br><br>",
                                          "<span style='font-weight: bold;'>BOL/PO#</span>: ", po, "<br><br>",
                                          "<span style='font-weight: bold;'>Our carrier</span>: ", our_first_carrier, "<br><br>",
                                          "<span style='font-weight: bold;'>Rate</span>: ", our_first_cost, "<br><br>",
                                          "<span style='font-weight: bold;'>Genera carrier</span>: ", genera_first_carrier, "<br><br>",
                                          "<span style='font-weight: bold;'>Rate</span>: ", genera_first_cost_str, "<br><br>"

                                          );
                info.fromAddress = AppCodeConstants.Alex_email;
                info.to          = string.Concat("cs" + AppCodeConstants.email_domain, " ", AppCodeConstants.BobsEmail, " ", AppCodeConstants.AnnesEmail);
                info.fromName    = "Genera";
                //info.bcc = AppCodeConstants.Alex_email;
                info.subject = "Cancellation # " + ltl_cancel_book_request.PNW;

                Mail mail = new Mail(ref info);
                mail.SendEmail();

                #endregion

                #region Update DB tables

                string sql = string.Concat("INSERT INTO Genera_Cancel_Booking(PNW) VALUES(",
                                           "'", ltl_cancel_book_request.PNW, "')");

                HelperFuncs.ExecuteNonQuery(AppCodeConstants.connStringAesAPI, ref sql, "Cancel_LTL_bookingController");

                DB.LogGenera(iam, "cancel_ltl_book_test", response_string);

                //

                //sql = string.Concat("UPDATE SQL_STATS_GCM SET PNW='Cancelled' ",
                //    "WHERE PNW='", ltl_cancel_book_request.PNW, "'");
                //HelperFuncs.ExecuteNonQuery(AppCodeConstants.connStringRater2009, ref sql, "Cancel_LTL_bookingController");

                sql = string.Concat("UPDATE SQL_STATS_GCM SET PNW_Cancelled='True' ",
                                    "WHERE PNW='", ltl_cancel_book_request.PNW, "'");
                HelperFuncs.ExecuteNonQuery(AppCodeConstants.connStringRater2009, ref sql, "Cancel_LTL_bookingController");


                //

                //response_string = "test done";

                #endregion

                return(public_helper.Get_response_message(ref response_string, ref content_type));
            }
            catch (Exception e)
            {
                #region Unknown error

                DB.LogGenera(iam, "cancel_ltl_book_test", e.ToString());
                //Xml_helper xml_helper = new Xml_helper();
                Json_helper json_helper = new Json_helper();
                // string request_format = "XML";
                //return xml_helper.Build_error_response("2",
                //            string.Concat("Could not find any rates. Please try again."), ref request_format);
                string response_string = json_helper.Build_error_response("2",
                                                                          string.Concat("Could not cancel booking. Please try again."));

                Models.Public.LTL.Helper public_helper = new Models.Public.LTL.Helper();
                string content_type = "application/json";
                return(public_helper.Get_response_message(ref response_string, ref content_type));

                //return new HttpResponseMessage()
                //{
                //    Content = new StringContent(response_string, Encoding.UTF8, "application/json")
                //};
                #endregion
            }
        }