public IActionResult UpdateCanvasProductView()
        {
            var model   = new CanvasProductModel();
            var request = _httpContextAccessor.HttpContext.Request;

            try
            {
                var miscPlugins = _pluginFinder.GetPlugins <MyOrderServicePlugin>(storeId: _storeContext.CurrentStore.Id).ToList();
                if (miscPlugins.Count > 0)
                {
                    model.orderItemID = Int32.Parse(request.Query["orderitemid"]);
                    var productType = request.Query["productType"];
                    var webPlatform = request.Query["webPlatform"];
                    model.productType = productType;
                    model.webPlatform = webPlatform;

                    IWorkContext _workContext = EngineContext.Current.Resolve <IWorkContext>();

                    var customerID = _workContext.CurrentCustomer.Id;
                    model.canvasServerBaseURL = _ccSettings.ServerHostUrl;
                    var    tempModel = new CanvasProductModel();
                    string stateID   = GetCcStateID(model.orderItemID, productType, out tempModel, webPlatform);

                    model.userID     = tempModel.userID;
                    model.username   = tempModel.username;
                    model.gbsOrderId = tempModel.gbsOrderId;

                    model.stateID = stateID;
                    //get the product file names and put them in the model.
                    List <ProductFileModel>             productFiles = GetProductFiles(model.orderItemID, stateID, productType, tempModel.ccId, webPlatform);
                    GBSFileService.GBSFileServiceClient FileService  = new GBSFileService.GBSFileServiceClient();
                    string fileServiceaddress = _gbsOrderSettings.GBSPrintFileWebServiceBaseAddress;
                    model.productFileModels = FileService.populateProductFilesFromProductionFileName(productFiles, fileServiceaddress, _gbsOrderSettings.LoginId, _gbsOrderSettings.Password);
                    model.sessionID         = _httpContextAccessor.HttpContext.Session.Id;


                    return(View("~/Plugins/Order.GBS/Views/OrderGBS/UpdateCanvasProduct.cshtml", model));
                }
                else
                {
                    throw new Exception("This store does not have the OrdPlugin installed");
                }
            }
            catch (Exception ex)
            {
                var customer = _workContext.CurrentCustomer;
                _logger.Error("Error trying to load UpdateCanvasProductView = orderitemid = " + model.orderItemID, ex, customer);
                throw ex;
            }
        }
        public IActionResult CopyFilesToProduction(IFormCollection ccFiles)
        {
            try
            {
                List <ProductFileModel> productFiles  = JsonConvert.DeserializeObject <List <ProductFileModel> >(ccFiles["FilesToCopy"]);
                List <ProductFileModel> filesToRemove = new List <ProductFileModel>();
                List <ProductFileModel> filesToUpdate = new List <ProductFileModel>();

                foreach (ProductFileModel product in productFiles)
                {
                    if (!ccFiles["surfaces"].Contains(product.product.surface))
                    {
                        filesToRemove.Add(product);
                    }
                }
                foreach (ProductFileModel removeMe in filesToRemove)
                {
                    productFiles.Remove(removeMe);
                }
                foreach (ProductFileModel product in productFiles)
                {
                    if (string.IsNullOrEmpty(product.product.productionFileName))
                    {
                        filesToUpdate.Add(product);
                    }
                }


                //pass to the file service
                GBSFileService.GBSFileServiceClient FileService = new GBSFileService.GBSFileServiceClient();
                string fileServiceaddress = _gbsOrderSettings.GBSPrintFileWebServiceAddress;
                string response           = FileService.CopyFilesToProduction(productFiles, fileServiceaddress, _gbsOrderSettings.LoginId, _gbsOrderSettings.Password);
                if (response.Contains("WebServices"))
                {
                    throw new Exception(response);
                }
                List <ProductFileModel> responseFiles = JsonConvert.DeserializeObject <List <ProductFileModel> >(response);

                var surfaces  = "";
                var fileNames = "";
                foreach (ProductFileModel product in responseFiles)
                {
                    surfaces  += "," + (product.product.surface == "F" ? "front" : product.product.surface == "B" ? "back" : product.product.surface);
                    fileNames += "," + product.product.productionFileName;
                }
                surfaces  = surfaces.Substring(1);
                fileNames = fileNames.Substring(1);

                //update NOP DB with new production filenames
                DBManager manager = new DBManager();
                foreach (ProductFileModel product in responseFiles)
                {
                    if (!String.IsNullOrEmpty(product.product.productionFileName) && !product.product.productionFileName.ToLower().Contains("exception") && filesToUpdate.Where(x => x.product.surface == product.product.surface).Any())
                    {
                        Dictionary <string, string> paramDicEx = new Dictionary <string, string>();
                        paramDicEx.Add("@nopOrderItemID", ccFiles["OPID"]);
                        paramDicEx.Add("@ProductType", ccFiles["productType"]);
                        paramDicEx.Add("@FileName", product.product.productionFileName);
                        var insert = "EXEC Insert_tblNOPProductionFiles @nopOrderItemID,@ProductType,@FileName";
                        manager.SetParameterizedQueryNoData(insert, paramDicEx);
                    }
                }

                var msg = new Message();
                msg.message = "Successfully updated the product print files. Please wait a few minutes for updated/new files to be synced to the Intranet before applying any further action that may be intended for this update";

                //call Intranet to update product options in order
                string    intranetBaseAddress = _gbsOrderSettings.IntranetBaseAddress;
                WebClient client = new WebClient();
                client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                if (!string.IsNullOrEmpty(intranetBaseAddress))
                {
                    var    address        = intranetBaseAddress + "/admin/inc/updateCanvasProduct.asp?OPID=" + ccFiles["OPID"] + "&productType=" + ccFiles["productType"] + "&surfaces=" + surfaces + "&fileNames=" + fileNames + "&webPlatform=" + ccFiles["webPlatform"];
                    string responseString = client.DownloadString(address);
                    if (responseString != "Success!")
                    {
                        throw new Exception("Error updating Intranet - address = " + address);
                    }
                }
                else
                {
                    msg.message = "Intranet Base Address not configured in plugin, please configure and try again";
                }



                return(View("~/Plugins/Order.GBS/Views/OrderGBS/UpdateCanvasProductComplete.cshtml", msg));
            }
            catch (Exception ex)
            {
                var customer = _workContext.CurrentCustomer;
                _logger.Error("Error trying to Copy Files to Production for :  " + ccFiles["FilesToCopy"], ex, customer);
                throw ex;
            }
        }