public void ProcessRequest(HttpContext context)
        {
            #region "Initialize"

            var strOut = "";

            var paramCmd = Utils.RequestQueryStringParam(context, "cmd");
            var itemId = Utils.RequestQueryStringParam(context, "itemid");
            var ctlType = Utils.RequestQueryStringParam(context, "ctltype");
            var idXref = Utils.RequestQueryStringParam(context, "idxref");
            var xpathpdf = Utils.RequestQueryStringParam(context, "pdf");
            var xpathref = Utils.RequestQueryStringParam(context, "pdfref");
            var lang = Utils.RequestQueryStringParam(context, "lang");
            var language = Utils.RequestQueryStringParam(context, "language");
            var moduleId = Utils.RequestQueryStringParam(context, "mid");
            var moduleKey = Utils.RequestQueryStringParam(context, "mkey");
            var parentid = Utils.RequestQueryStringParam(context, "parentid");
            var entryid = Utils.RequestQueryStringParam(context, "entryid");
            var entryxid = Utils.RequestQueryStringParam(context, "entryxid");
            var catid = Utils.RequestQueryStringParam(context, "catid");
            var catxid = Utils.RequestQueryStringParam(context, "catxid");
            var templatePrefix = Utils.RequestQueryStringParam(context, "tprefix");
            var value = Utils.RequestQueryStringParam(context, "value");
            var itemListName = Utils.RequestQueryStringParam(context, "listname");
            if (itemListName == "") itemListName = "ItemList";
            if (itemListName == "*") itemListName = "ItemList";

            #region "setup language"

            // because we are using a webservice the system current thread culture might not be set correctly,
            //  so use the lang/lanaguge param to set it.
            if (lang == "") lang = language;
            if (!string.IsNullOrEmpty(lang)) _lang = lang;
            // default to current thread if we have no language.
            if (_lang == "") _lang = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();

            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(_lang);

            #endregion

            #endregion

            #region "Do processing of command"

            var intModuleId = 0;
            if (Utils.IsNumeric(moduleId)) intModuleId = Convert.ToInt32(moduleId);

            var objCtrl = new NBrightBuyController();

            var uInfo = new UserDataInfo(UserController.GetCurrentUserInfo().PortalID, intModuleId, objCtrl, ctlType);
            strOut = "ERROR!! - No Security rights for current user!";
            switch (paramCmd)
            {
                case "test":
                    strOut = "<root>" + UserController.GetCurrentUserInfo().Username + "</root>";
                    break;
                case "setdata":
                    break;
                case "deldata":
                    break;
                //case "setcategoryadminform":
                //    if (CheckRights()) strOut = SetCategoryForm(context);
                //    break;
                case "getdata":
                    strOut = GetReturnData(context);
                    break;
                case "additemlist":
                    if (Utils.IsNumeric(itemId))
                    {
                        var cw = new ItemListData(itemListName);
                        cw.Add(itemId);
                        strOut = cw.ItemList;
                    }
                    break;
                case "removeitemlist":
                    if (Utils.IsNumeric(itemId))
                    {
                        var cw1 = new ItemListData(itemListName);
                        cw1.Remove(itemId);
                        strOut = cw1.ItemList;
                    }
                    break;
                case "deleteitemlist":
                        var cw2 = new ItemListData(itemListName);
                        cw2.Delete();
                        strOut = "deleted";
                    break;
                case "getproductselectlist":
                    strOut = GetProductList(context);
                    break;
                case "getproductlist":
                    strOut = GetProductList(context);
                    break;
                case "getcategoryproductlist":
                    strOut = GetCategoryProductList(context);
                    break;
                case "setdefaultcategory":
                    if (CheckRights()) strOut = SetDefaultCategory(context);
                    break;
                case "deletecatxref":
                    if (CheckRights()) strOut = DeleteCatXref(context);
                    break;
                case "selectcatxref":
                    if (CheckRights()) strOut = SelectCatXref(context);
                    break;
                case "deleteallcatxref":
                    if (CheckRights()) strOut = DeleteAllCatXref(context);
                    break;
                case "copyallcatxref":
                    if (CheckRights()) strOut = CopyAllCatXref(context);
                    break;
                case "moveallcatxref":
                    if (CheckRights()) strOut = CopyAllCatXref(context,true);
                    break;
                case "editproduct":
                    if (CheckRights()) strOut = GetProductGeneralData(context);
                    break;
                case "productdescription":
                    if (CheckRights()) strOut = GetProductDescription(context);
                    break;
                case "productmodels":
                    if (CheckRights()) strOut = GetProductModels(context);
                    break;
                case "productoptions":
                    if (CheckRights()) strOut = GetProductOptions(context);
                    break;
                case "productoptionvalues":
                    if (CheckRights()) strOut = GetProductOptionValues(context);
                    break;
                case "productimages":
                    if (CheckRights()) strOut = GetProductImages(context);
                    break;
                case "productdocs":
                    if (CheckRights()) strOut = GetProductDocs(context);
                    break;
                case "productrelatedproducts":
                    if (CheckRights()) strOut = GetProductModels(context);
                    break;
                case "productcategories":
                    if (CheckRights()) strOut = GetProductCategories(context);
                    break;
                case "productisincategory":
                    if (CheckRights()) strOut = ProductIsInCategory(context).ToString();
                    break;
                case "productgroupcategories":
                    if (CheckRights()) strOut = GetProductGroupCategories(context);
                    break;
                case "productrelated":
                    if (CheckRights()) strOut = GetProductRelated(context);
                    break;
                case "addproductmodels":
                    if (CheckRights()) strOut = AddProductModels(context);
                    break;
                case "addproductoptions":
                    if (CheckRights()) strOut = AddProductOptions(context);
                    break;
                case "addproductoptionvalues":
                    if (CheckRights()) strOut = AddProductOptionValues(context);
                    break;
                case "addproductcategory":
                    if (CheckRights()) strOut = AddProductCategory(context);
                    break;
                case "addproductgroupcategory":
                    if (CheckRights()) strOut = AddProductGroupCategory(context);
                    break;
                case "removeproductcategory":
                    if (CheckRights()) strOut = RemoveProductCategory(context);
                    break;
                case "removeproductgroupcategory":
                    if (CheckRights()) strOut = RemoveProductGroupCategory(context);
                    break;
                case "populatecategorylist":
                    if (CheckRights()) strOut = GetGroupCategoryListBox(context);
                    break;
                case "addrelatedproduct":
                    if (CheckRights()) strOut = AddRelatedProduct(context);
                    break;
                case "removerelatedproduct":
                    if (CheckRights()) strOut = RemoveRelatedProduct(context);
                    break;
                case "clientdiscountcodes":
                    if (CheckRights()) strOut = GetClientDiscountCodes(context);
                    break;
                case "addclientdiscountcode":
                    if (CheckRights()) strOut = AddClientDiscountCodes(context);
                    break;
                case "clientvouchercodes":
                    if (CheckRights()) strOut = GetClientVoucherCodes(context);
                    break;
                case "addclientvouchercode":
                    if (CheckRights()) strOut = AddClientVoucherCodes(context);
                    break;
                case "moveproductadmin":
                    if (CheckRights()) strOut = MoveProductAdmin(context);
                    break;
                case "fileupload":
                    if (CheckRights() && Utils.IsNumeric(itemId))
                    {
                        strOut = FileUpload(context);
                    }
                    break;
                case "updateproductimages":
                    if (CheckRights())
                    {
                        UpdateProductImages(context);
                        strOut = GetProductImages(context);
                    }
                    break;
            }

            #endregion

            #region "return results"

                //send back xml as plain text
                context.Response.Clear();
                context.Response.ContentType = "text/plain";
                context.Response.Write(strOut);
                context.Response.End();

            #endregion
        }
        public void ProcessRequest(HttpContext context)
        {
            #region "Initialize"

            var strOut = "";

            var paramCmd = Utils.RequestQueryStringParam(context, "cmd");
            var itemId = Utils.RequestQueryStringParam(context, "itemid");
            var ctlType = Utils.RequestQueryStringParam(context, "ctltype");
            var idXref = Utils.RequestQueryStringParam(context, "idxref");
            var xpathpdf = Utils.RequestQueryStringParam(context, "pdf");
            var xpathref = Utils.RequestQueryStringParam(context, "pdfref");
            var lang = Utils.RequestQueryStringParam(context, "lang");
            var language = Utils.RequestQueryStringParam(context, "language");
            var moduleId = Utils.RequestQueryStringParam(context, "mid");
            var moduleKey = Utils.RequestQueryStringParam(context, "mkey");
            var parentid = Utils.RequestQueryStringParam(context, "parentid");
            var entryid = Utils.RequestQueryStringParam(context, "entryid");
            var entryxid = Utils.RequestQueryStringParam(context, "entryxid");
            var catid = Utils.RequestQueryStringParam(context, "catid");
            var catxid = Utils.RequestQueryStringParam(context, "catxid");
            var templatePrefix = Utils.RequestQueryStringParam(context, "tprefix");
            var value = Utils.RequestQueryStringParam(context, "value");
            var itemListName = Utils.RequestQueryStringParam(context, "listname");
            if (itemListName == "") itemListName = "ItemList";
            if (itemListName == "*") itemListName = "ItemList";

            #region "setup language"

            // because we are using a webservice the system current thread culture might not be set correctly,
            SetContextLangauge(context);

            #endregion

            #endregion

            try
            {

                #region "Do processing of command"

                var intModuleId = 0;
                if (Utils.IsNumeric(moduleId)) intModuleId = Convert.ToInt32(moduleId);

                var objCtrl = new NBrightBuyController();

                var uInfo = new UserDataInfo(UserController.Instance.GetCurrentUserInfo().PortalID, intModuleId, objCtrl,
                    ctlType);
                strOut = "ERROR!! - No Security rights for current user!";
                switch (paramCmd)
                {
                    case "test":
                        strOut = "<root>" + UserController.Instance.GetCurrentUserInfo().Username + "</root>";
                        break;
                    case "setdata":
                        break;
                    case "deldata":
                        break;
                    //case "setcategoryadminform":
                    //    if (NBrightBuyUtils.CheckRights()) strOut = SetCategoryForm(context);
                    //    break;
                    case "getdata":
                        strOut = GetReturnData(context);
                        break;
                    case "additemlist":
                        if (Utils.IsNumeric(itemId))
                        {
                            var cw = new ItemListData(itemListName);
                            cw.Add(itemId);
                            strOut = cw.ItemList;
                        }
                        break;
                    case "removeitemlist":
                        if (Utils.IsNumeric(itemId))
                        {
                            var cw1 = new ItemListData(itemListName);
                            cw1.Remove(itemId);
                            strOut = cw1.ItemList;
                        }
                        break;
                    case "deleteitemlist":
                        var cw2 = new ItemListData(itemListName);
                        cw2.Delete();
                        strOut = "deleted";
                        break;
                    case "getproductselectlist":
                        strOut = GetProductList(context);
                        break;
                    case "getproductlist":
                        strOut = GetProductList(context);
                        break;
                    case "getcategoryproductlist":
                        strOut = GetCategoryProductList(context);
                        break;
                    case "setdefaultcategory":
                        if (NBrightBuyUtils.CheckRights()) strOut = SetDefaultCategory(context);
                        break;
                    case "deletecatxref":
                        if (NBrightBuyUtils.CheckRights()) strOut = DeleteCatXref(context);
                        break;
                    case "selectcatxref":
                        if (NBrightBuyUtils.CheckRights()) strOut = SelectCatXref(context);
                        break;
                    case "deleteallcatxref":
                        if (NBrightBuyUtils.CheckRights()) strOut = DeleteAllCatXref(context);
                        break;
                    case "copyallcatxref":
                        if (NBrightBuyUtils.CheckRights()) strOut = CopyAllCatXref(context);
                        break;
                    case "moveallcatxref":
                        if (NBrightBuyUtils.CheckRights()) strOut = CopyAllCatXref(context, true);
                        break;
                    case "editproduct":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductGeneralData(context);
                        break;
                    case "productdescription":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductDescription(context);
                        break;
                    case "productmodels":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductModels(context);
                        break;
                    case "productoptions":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductOptions(context);
                        break;
                    case "productoptionvalues":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductOptionValues(context);
                        break;
                    case "productimages":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductImages(context);
                        break;
                    case "productdocs":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductDocs(context);
                        break;
                    case "productrelatedproducts":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductModels(context);
                        break;
                    case "productcategories":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductCategories(context);
                        break;
                    case "productisincategory":
                        if (NBrightBuyUtils.CheckRights()) strOut = ProductIsInCategory(context).ToString();
                        break;
                    case "productgroupcategories":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductGroupCategories(context);
                        break;
                    case "productrelated":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductRelated(context);
                        break;
                    case "productclients":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductClients(context);
                        break;
                    case "getclientselectlist":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetClientSelectList(context);
                        break;
                    case "addproductmodels":
                        if (NBrightBuyUtils.CheckRights()) strOut = AddProductModels(context);
                        break;
                    case "addproductoptions":
                        if (NBrightBuyUtils.CheckRights()) strOut = AddProductOptions(context);
                        break;
                    case "addproductoptionvalues":
                        if (NBrightBuyUtils.CheckRights()) strOut = AddProductOptionValues(context);
                        break;
                    case "addproductcategory":
                        if (NBrightBuyUtils.CheckRights()) strOut = AddProductCategory(context);
                        break;
                    case "addproductgroupcategory":
                        if (NBrightBuyUtils.CheckRights()) strOut = AddProductGroupCategory(context);
                        break;
                    case "removeproductcategory":
                        if (NBrightBuyUtils.CheckRights()) strOut = RemoveProductCategory(context);
                        break;
                    case "removeproductgroupcategory":
                        if (NBrightBuyUtils.CheckRights()) strOut = RemoveProductGroupCategory(context);
                        break;
                    case "populatecategorylist":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetGroupCategoryListBox(context);
                        break;
                    case "addrelatedproduct":
                        if (NBrightBuyUtils.CheckRights()) strOut = AddRelatedProduct(context);
                        break;
                    case "removerelatedproduct":
                        if (NBrightBuyUtils.CheckRights()) strOut = RemoveRelatedProduct(context);
                        break;
                    case "addproductclient":
                        if (NBrightBuyUtils.CheckRights()) strOut = AddProductClient(context);
                        break;
                    case "removeproductclient":
                        if (NBrightBuyUtils.CheckRights()) strOut = RemoveProductClient(context);
                        break;
                    case "clientdiscountcodes":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetClientDiscountCodes(context);
                        break;
                    case "addclientdiscountcode":
                        if (NBrightBuyUtils.CheckRights()) strOut = AddClientDiscountCodes(context);
                        break;
                    case "clientvouchercodes":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetClientVoucherCodes(context);
                        break;
                    case "addclientvouchercode":
                        if (NBrightBuyUtils.CheckRights()) strOut = AddClientVoucherCodes(context);
                        break;
                    case "moveproductadmin":
                        if (NBrightBuyUtils.CheckRights()) strOut = MoveProductAdmin(context);
                        break;
                    case "fileupload":
                        if (NBrightBuyUtils.CheckRights() && Utils.IsNumeric(itemId))
                        {
                            strOut = FileUpload(context);
                        }
                        break;
                    case "fileclientupload":
                        if (StoreSettings.Current.GetBool("allowupload"))
                        {
                            strOut = FileUpload(context, itemId);
                        }
                        break;
                    case "updateproductimages":
                        if (NBrightBuyUtils.CheckRights())
                        {
                            UpdateProductImages(context);
                            strOut = GetProductImages(context);
                        }
                        break;
                    case "updateproductdocs":
                        if (NBrightBuyUtils.CheckRights())
                        {
                            UpdateProductDocs(context);
                            strOut = GetProductDocs(context);
                        }
                        break;
                    case "addtobasket":
                        strOut = AddToBasket(context);
                        break;
                    case "addalltobasket":
                        strOut = AddAllToBasket(context);
                        break;
                    case "addcookietobasket":
                        break;
                    case "docdownload":
                        var fname = Utils.RequestQueryStringParam(context, "filename");
                        strOut = fname; // return this is error.
                        var downloadname = Utils.RequestQueryStringParam(context, "downloadname");
                        var fpath = HttpContext.Current.Server.MapPath(fname);
                        if (downloadname == "") downloadname = Path.GetFileName(fname);
                        Utils.ForceDocDownload(fpath, downloadname, context.Response);
                        break;
                    case "printproduct":
                        break;
                    case "removefromcart":
                        RemoveFromCart(context);
                        strOut = "removefromcart";
                        break;
                    case "recalculatecart":
                        RecalculateCart(context);
                        strOut = "recalculatecart";
                        break;
                    case "recalculatesummary":
                        RecalculateSummary(context);
                        strOut = "recalculatecart";
                        break;
                    case "redirecttopayment":
                        strOut = RedirectToPayment(context);
                        break;
                    case "updatebilladdress":
                        strOut = UpdateCartAddress(context, "bill");
                        break;
                    case "updateshipaddress":
                        strOut = UpdateCartAddress(context, "ship");
                        break;
                    case "updateshipoption":
                        strOut = UpdateCartAddress(context, "shipoption");
                        break;
                    case "rendercart":
                        strOut = RenderCart(context);
                        break;
                    case "renderpostdata":
                        strOut = RenderPostData(context);
                        break;
                    case "clearcart":
                        var currentcart = new CartData(PortalSettings.Current.PortalId);
                        currentcart.DeleteCart();
                        strOut = "clearcart";
                        break;
                    case "shippingprovidertemplate":
                        strOut = GetShippingProviderTemplates(context);
                        break;
                    case "getsettings":
                        strOut = GetSettings(context);
                        break;
                    case "savesettings":
                        if (NBrightBuyUtils.CheckRights()) strOut = SaveSettings(context);
                        break;
                    case "updateprofile":
                        strOut = UpdateProfile(context);
                        break;
                    case "dosearch":
                        strOut = DoSearch(context);
                        break;
                    case "resetsearch":
                        strOut = ResetSearch(context);
                        break;
                    case "orderby":
                        strOut = DoOrderBy(context);
                        break;
                    case "orderadmin_getlist":
                        strOut = OrderAdminList(context);
                        break;
                    case "orderadmin_getdetail":
                        strOut = OrderAdminDetail(context);
                        break;
                    case "orderadmin_reorder":
                        strOut = OrderAdminReOrder(context);
                        break;
                    case "orderadmin_edit":
                        strOut = OrderAdminEdit(context);
                        break;
                    case "orderadmin_save":
                        strOut = OrderAdminSave(context);
                        break;
                    case "orderadmin_removeinvoice":
                        strOut = OrderAdminRemoveInvoice(context);
                        break;
                    case "orderadmin_sendemail":
                        strOut = OrderAdminEmail(context);
                        break;
                }

                #endregion

            }
            catch (Exception ex)
            {
                strOut = ex.ToString();
                Exceptions.LogException(ex);
            }

            #region "return results"

            //send back xml as plain text
            context.Response.Clear();
            context.Response.ContentType = "text/plain";
            context.Response.Write(strOut);
            context.Response.End();

            #endregion
        }