protected void Application_Error(object sender, EventArgs e)
 {
     Exception ex = Server.GetLastError();
     if (null != HttpContext.Current)
     {
         string url = HttpContext.Current.Request.Url.ToString();
         ApplicationController objAppController = new ApplicationController();
         if (objAppController.IsImageRequest(url))
         {
             ErrorHandler erHandler = new ErrorHandler();
             erHandler.LogCommonException(ex);
         }
     }
 }
 protected void Application_Error(object sender, EventArgs e)
 {
     Exception ex = Server.GetLastError();
     string url = HttpContext.Current.Request.Url.ToString();
     if (!url.EndsWith("png") && !url.EndsWith("jpg") && !url.EndsWith("gif") && !url.EndsWith("jpeg") && !url.EndsWith("bmp"))           
     {
         ErrorHandler erHandler = new ErrorHandler();
         erHandler.LogCommonException(ex);
     }                  
 }
        public string GetCategoryCheckedItems(int CategoryID, AspxCommonInfo aspxCommonObj)
        {
            try
            {

                string categoryItem = AspxCategoryManageController.GetCategoryCheckedItems(CategoryID, aspxCommonObj);
                return categoryItem;
            }
            catch (Exception e)
            {
                ErrorHandler errHandler = new ErrorHandler();
                errHandler.LogWCFException(e);
                throw e;
            }
        }
        public string SaveChangesCategoryTree(string categoryIDs, AspxCommonInfo aspxCommonObj)
        {
            try
            {

                AspxCategoryManageController.SaveChangesCategoryTree(categoryIDs, aspxCommonObj);
                CacheHelper.Clear("CategoryInfo" + aspxCommonObj.StoreID + aspxCommonObj.PortalID + "_" + aspxCommonObj.CultureName);
                CacheHelper.Clear("CategoryForSearch" + aspxCommonObj.StoreID + aspxCommonObj.PortalID + "_" + aspxCommonObj.CultureName);
                return "({ \"returnStatus\" : 1 , \"Message\" : \"Category tree saved successfully.\" })";

            }
            catch (Exception e)
            {
                ErrorHandler errHandler = new ErrorHandler();
                if (errHandler.LogWCFException(e))
                {
                    return "({ \"returnStatus\" : -1 , \"errorMessage\" : \"" + e.Message + "\" })";
                }
                else
                {
                    return "({ \"returnStatus\" : -1, \"errorMessage\" : \"Error while saving category tree!\" })";
                }
            }
        }
        public string DeleteCategory(Int32 storeID, Int32 portalID, Int32 categoryID, string userName, string culture)
        {
            try
            {
                AspxCategoryManageController.DeleteCategory(storeID, portalID, categoryID, userName, culture);
                CacheHelper.Clear("CategoryInfo" + storeID.ToString() + portalID.ToString());
                CacheHelper.Clear("CategoryForSearch" + storeID.ToString() + portalID.ToString());
                return "({ \"returnStatus\" : 1 , \"Message\" : \"Category has been deleted successfully.\" })";

            }
            catch (Exception e)
            {
                ErrorHandler errHandler = new ErrorHandler();
                if (errHandler.LogWCFException(e))
                {
                    return "({ \"returnStatus\" : -1 , \"errorMessage\" : \"" + e.Message + "\" })";
                }
                else
                {
                    return "({ \"returnStatus\" : -1, \"errorMessage\" : \"Error while deleting category!\" })";
                }
            }
        }
        public List<CategoryItemInfo> GetCategoryItems(Int32 offset, System.Nullable<int> limit, GetCategoryItemInfo categoryItemsInfo, AspxCommonInfo aspxCommonObj, bool serviceBit)
        {
            try
            {

                List<CategoryItemInfo> listCategoryItem = AspxCategoryManageController.GetCategoryItems(offset, limit, categoryItemsInfo, aspxCommonObj, serviceBit);
                return listCategoryItem;
            }
            catch (Exception e)
            {
                ErrorHandler errHandler = new ErrorHandler();
                errHandler.LogWCFException(e);
                throw e;
            }
        }
 public List<CategoryInfo> GetCategoryAll(bool isActive, AspxCommonInfo aspxCommonObj)
 {
     try
     {
         List<CategoryInfo> catList = AspxCategoryManageController.GetCategoryAll(isActive, aspxCommonObj);
         return catList;
     }
     catch (Exception e)
     {
         ErrorHandler errHandler = new ErrorHandler();
         errHandler.LogWCFException(e);
         throw e;
     }
 }
 public string SaveCategory(CategoryInfo.CategorySaveBasicInfo categoryObj, AspxCommonInfo aspxCommonObj)
 {
     try
     {
         int categoryId = AspxCategoryManageController.SaveCategory(categoryObj, aspxCommonObj);
         CacheHelper.Clear("CategoryInfo" + aspxCommonObj.StoreID + aspxCommonObj.PortalID + "_" + aspxCommonObj.CultureName);
         CacheHelper.Clear("CategoryForSearch" + aspxCommonObj.StoreID + aspxCommonObj.PortalID + "_" + aspxCommonObj.CultureName);
         if (categoryObj.ParentId > 0)
         {
             return
                 "({\"returnStatus\":1,\"Message\":\"Sub category has been saved successfully.\",\"categoryID\":" +
                 categoryId + "})";
         }
         else
         {
             return "({\"returnStatus\":1,\"Message\":\"Category has been saved successfully.\",\"categoryID\":" +
                    categoryId + "})";
         }
     }
     catch (Exception e)
     {
         ErrorHandler errHandler = new ErrorHandler();
         if (errHandler.LogWCFException(e))
         {
             return "({\"returnStatus\":-1,\"errorMessage\":'" + e.Message + "'})";
         }
         else
         {
             return "({\"returnStatus\":-1,\"errorMessage\":\"Error while saving category!\"})";
         }
     }
 }
        public List<AttributeFormInfo> GetCategoryFormAttributes(Int32 categoryID, AspxCommonInfo aspxCommonObj)
        {
            try
            {

                List<AttributeFormInfo> frmFieldList = AspxCategoryManageController.GetCategoryFormAttributes(categoryID, aspxCommonObj);
                return frmFieldList;
            }
            catch (Exception e)
            {
                ErrorHandler errHandler = new ErrorHandler();
                errHandler.LogWCFException(e);
                throw e;
            }
        }
 public bool IsUnique(Int32 storeID, Int32 portalID, Int32 itemID, Int32 attributeID, Int32 attributeType, string attributeValue)
 {
     try
     {
         /*
     1	TextField
     2	TextArea
     3	Date
     4	Boolean
     5	MultipleSelect
     6	DropDown
     7	Price
     8	File
     9	Radio
     10	RadioButtonList
     11	CheckBox
     12	CheckBoxList
      */
         bool isUnique = AspxCategoryManageController.IsUnique(storeID, portalID, itemID, attributeID, attributeType, attributeValue);
         return isUnique;
     }
     catch (Exception e)
     {
         ErrorHandler errHandler = new ErrorHandler();
         errHandler.LogWCFException(e);
         return false;
     }
 }
        public string DeleteMultipleCartPricingRules(string cartRulesIds, AspxCommonInfo aspxCommonObj)
        {
            try
            {

                AspxCartPriceRuleController.CartPriceMultipleRulesDelete(cartRulesIds, aspxCommonObj);
                return "({ \"returnStatus\" : 1 , \"Message\" : \"Deleting multiple cart pricing rules successfully.\" })";
            }
            catch (Exception ex)
            {
                ErrorHandler errHandler = new ErrorHandler();
                if (errHandler.LogWCFException(ex))
                {
                    return "({ \"returnStatus\" : -1 , \"errorMessage\" : \"" + ex.Message + "\" })";
                }
                else
                {
                    return "({ \"returnStatus\" : -1, \"errorMessage\" : \"Error while deleting cart pricing rule!\" })";
                }
            }
        }
        public string SaveCartPricingRule(CartPricingRuleInfo objCartPriceRule, AspxCommonInfo aspxCommonObj, List<int> parentID)
        {
            try
            {
                List<KeyValuePair<string, object>> p1 = new List<KeyValuePair<string, object>>();
                //P1.Add(new KeyValuePair<string,object>("@StoreID", storeID));
                p1.Add(new KeyValuePair<string, object>("PortalID", aspxCommonObj.PortalID));
                SQLHandler sql = new SQLHandler();
                int count = sql.ExecuteAsScalar<int>("usp_Aspx_CartPrincingRuleCount", p1);
                int maxAllowed = 3;
                int cartPriceRuleId = objCartPriceRule.CartPriceRule.CartPriceRuleID;
                if (cartPriceRuleId > 0)
                {
                    maxAllowed++;
                }
                if (count < maxAllowed)
                {

                    AspxCartPriceRuleController.SaveCartPricingRule(objCartPriceRule, aspxCommonObj, parentID);
                    //return "({ \"returnStatus\" : 1 , \"Message\" : \"Saving cart pricing rule successfully.\" })";
                    return "success";
                }
                else
                {
                    //return "({ \"returnStatus\" : -1 , \"Message\" : \"No more than 3 rules are allowed in Free version of AspxCommerce!\" })";
                    return "notify";
                }
            }
            catch (Exception ex)
            {
                ErrorHandler errHandler = new ErrorHandler();
                if (errHandler.LogWCFException(ex))
                {
                    return "({ \"returnStatus\" : -1 , \"errorMessage\" : \"" + ex.Message + "\" })";
                }
                else
                {
                    return "({ \"returnStatus\" : -1, \"errorMessage\" : \"Error while saving cart pricing rule!\" })";
                }
            }
        }
        //public Task<string> SavePricingRuleAsync(CatalogPricingRuleInfo objCatalogPricingRuleInfo, AspxCommonInfo aspxCommonObj, List<int> parentID)
        //{
        //    Task<string> result = new Task<string>();

        //    try
        //    {
        //        List<KeyValuePair<string, object>> p1 = new List<KeyValuePair<string, object>>();
        //        p1.Add(new KeyValuePair<string, object>("@StoreID", aspxCommonObj.StoreID));
        //        p1.Add(new KeyValuePair<string, object>("@PortalID", aspxCommonObj.PortalID));
        //        SQLHandler sql = new SQLHandler();
        //        int count = sql.ExecuteAsScalar<int>("usp_Aspx_CatalogPriceRuleCount", p1);
        //        int maxAllowed = 3;
        //        int catalogPriceRuleId = objCatalogPricingRuleInfo.CatalogPriceRule.CatalogPriceRuleID;
        //        if (catalogPriceRuleId > 0)
        //        {
        //            maxAllowed++;
        //        }
        //        if (count < maxAllowed)
        //        {
        //            AspxCatalogPriceRuleController.SaveCatalogPricingRule(objCatalogPricingRuleInfo, aspxCommonObj, parentID);
        //            //return "({ \"returnStatus\" : 1 , \"Message\" : \"Saving catalog pricing rule successfully.\" })";
        //            result = Task<string>.Factory.StartNew(() => "success");
        //            return result;
        //        }
        //        else
        //        {
        //            //return "({ \"returnStatus\" : -1 , \"Message\" : \"No more than 3 rules are allowed in Free version of AspxCommerce!\" })";
        //            result = Task<string>.Factory.StartNew(() => "notify");
        //            return result;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        ErrorHandler errHandler = new ErrorHandler();
        //        if (errHandler.LogWCFException(ex))
        //        {
        //            result = Task<string>.Factory.StartNew(() => "({ \"returnStatus\" : -1 , \"errorMessage\" : \"" + ex.Message + "\" })");
        //            return result;
        //        }
        //        else
        //        {
        //            result = Task<string>.Factory.StartNew(() => "({ \"returnStatus\" : -1, \"errorMessage\" : \"Error while saving catalog pricing rule!\" })");
        //            return result;
        //        }
        //    }
        //}

        public string DeletePricingRule(Int32 catalogPricingRuleID, AspxCommonInfo aspxCommonObj)
        {
            try
            {
                AspxCatalogPriceRuleController.CatalogPriceRuleDelete(catalogPricingRuleID, aspxCommonObj);
                return "({ \"returnStatus\" : 1 , \"Message\" : \"Deleting catalog pricing rule successfully.\" })";
            }
            catch (Exception ex)
            {
                ErrorHandler errHandler = new ErrorHandler();
                if (errHandler.LogWCFException(ex))
                {
                    return "({ \"returnStatus\" : -1 , \"errorMessage\" : \"" + ex.Message + "\" })";
                }
                else
                {
                    return "({ \"returnStatus\" : -1, \"errorMessage\" : \"Error while deleting catalog pricing rule!\" })";
                }
            }
        }