public JsonResult MultiLabelQuery(string ShopUrl, string Address1, string Address2, string Suburb, string Postcode, float Weight, string Instruction, string Type)
        {
            //DB connection to query store details
            DbEngine newDB = new DbEngine();
            //get store details with provided url
            StoreRecord storeDetails = newDB.GetShopRecord(ShopUrl);
            //Labeldetails entity to query
            Labeldetails label = new Labeldetails();

            //populate store details for query
            label.apiKey       = storeDetails.FastwayApiKey;
            label.fromAddress1 = storeDetails.StoreAddress1;
            label.fromCity     = storeDetails.Suburb;
            label.fromPostcode = storeDetails.Postcode;
            //populate delivery details for query
            label.toAddress1 = Address1;
            label.toAddress2 = Address2;
            label.toCity     = Suburb;
            label.toPostcode = Postcode;
            //populate parcel details for query
            label.weight      = (double)Weight;
            label.countryCode = storeDetails.CountryCode;

            List <string> labelNumbers = new List <string>();
            string        destRF       = "";

            try
            {
                if (Type != "Parcel")
                {
                    if (Weight > 5)
                    {
                        labelNumbers.Add("No Service Found");
                    }
                    else
                    {
                        label.specialInstruction1 = Instruction;

                        //new fastwayAPI object to query
                        FastwayAPI getLabel = new FastwayAPI();
                        //get label with V2 method
                        Labeldetails l = new Labeldetails();

                        if (Type == "SAT-NAT-A3")
                        {
                            List <UsableLabel> services = getLabel.ServiceQuery(label);
                            if (services.First().BaseLabelColour == "BROWN")
                            {
                                label.labelColour = services[services.FindIndex(a => a.BaseLabelColour == "SAT-LOC-A3")].BaseLabelColour;
                            }
                            else
                            {
                                label.labelColour = Type;
                            }
                        }
                        else
                        {
                            label.labelColour = Type;
                        }
                        l = getLabel.LabelQueryV2(label);
                        labelNumbers.Add(l.labelNumber);
                        labelNumbers.Add(l.ruralNumber);
                        destRF = l.toRfName;
                    }
                }
                else
                {
                    //new fastwayAPI object to query
                    FastwayAPI getLabel = new FastwayAPI();
                    //get label with V2 method
                    Labeldetails       l        = new Labeldetails();
                    List <UsableLabel> services = getLabel.ServiceQuery(label);
                    label.labelColour = services.First().BaseLabelColour;
                    l = getLabel.LabelQueryV2(label);
                    labelNumbers.Add(l.labelNumber);
                    labelNumbers.Add(l.ruralNumber);
                    destRF = l.toRfName;
                }
            }
            catch (Exception)
            {
                labelNumbers.Add("No Service Found");
            }
            return(Json(new
            {//return details about availabel service
                BaseLabel = labelNumbers[0],
                RuralLabel = labelNumbers[1],
                Service = label.labelColour,
                DestRF = destRF
            }));
        }
        public JsonResult LabelPrintingV2(string ShopUrl, string DeliveryDetails, string PackagingDetails, bool Saturday)
        {
            //labeldetails object to call Fastway API
            Labeldetails label = new Labeldetails();
            //DB connection to query sender details
            DbEngine conn = new DbEngine();

            label.apiKey = conn.GetStringValues(ShopUrl, "FastwayApiKey");
            //assign sender details
            label.fromAddress1 = conn.GetStringValues(ShopUrl, "StoreAddress1");
            label.fromPostcode = conn.GetStringValues(ShopUrl, "Postcode");
            label.fromCity     = conn.GetStringValues(ShopUrl, "Suburb");
            label.fromCompany  = conn.GetStringValues(ShopUrl, "StoreName");
            label.countryCode  = conn.GetIntergerValues(ShopUrl, "CountryCode");
            label.fromPhone    = conn.GetStringValues(ShopUrl, "Phone");

            //parse delivery details
            JObject d = JObject.Parse(DeliveryDetails);

            //assign receiver details
            label.toAddress1 = d["Address1"].ToString();
            label.toAddress2 = d["Address2"].ToString();
            label.toPostcode = d["Postcode"].ToString();
            label.toCity     = d["Suburb"].ToString();

            label.specialInstruction1 = d["SpecialInstruction1"].ToString();

            if (d["Company"].ToString() != "" && d["Company"].ToString() != "null" && d["Company"].ToString() != null)
            {
                label.toCompany     = d["Company"].ToString();
                label.toContactName = d["ContactName"].ToString();
            }
            else
            {
                label.toCompany = d["ContactName"].ToString();
            }

            label.toContactPhone = d["ContactPhone"].ToString();
            //pull through email address for expect messaging
            label.toEmail = d["ContactEmail"].ToString();

            //parse packaging details
            JArray p = JArray.Parse(PackagingDetails);
            //list of labelDetails that hold the labels being used
            List <Labeldetails> labelDetails = new List <Labeldetails>();
            List <string>       labelNumbers = new List <string>();



            for (int i = 0; i < p.Count; i++)
            {
                for (int j = 0; j < (int)p[i]["Items"]; j++)
                {
                    //package details
                    label.weight      = (double)p[i]["Weight"];
                    label.labelColour = p[i]["BaseLabel"].ToString();
                    label.reference   = p[i]["Reference"].ToString();
                    label.saturday    = Saturday;

                    //new fastwayAPI object to query
                    FastwayAPI getLabel = new FastwayAPI();
                    //get label with V2 method
                    Labeldetails l = new Labeldetails();
                    l = getLabel.LabelQueryV2(label);
                    labelDetails.Add(l);
                    labelNumbers.Add(l.labelNumber);
                }
            }

            PdfDocument doc = new PdfDocument();

            if (labelDetails.Count > 0)
            {
                FastwayAPI getBase = new FastwayAPI();
                doc = getBase.PrintLabels(labelDetails, doc);
            }

            MemoryStream pdfStream = new MemoryStream();

            doc.Save(pdfStream, false);
            byte[] pdfBytes = pdfStream.ToArray();

            var pdfString = Convert.ToBase64String(pdfBytes);

            try
            {
                return(Json(new
                {//return status success
                    Labels = String.Join(",", labelNumbers),
                    PdfBase64Stream = pdfString
                }));
            }
            catch (Exception e)
            {//error
                throw e;
            }
        }