public int SaveUpdateItemAndAttributes(ItemsInfo.ItemSaveBasicInfo itemObj, AspxCommonInfo aspxCommonObj)
        {
            bool   isModified = false;
            bool   updateFlag = false;
            int    storeId    = aspxCommonObj.StoreID;
            int    portalId   = aspxCommonObj.PortalID;
            string culture    = aspxCommonObj.CultureName;
            string userName   = aspxCommonObj.UserName;

            if (itemObj.ItemId > 0)
            {
                isModified = true;
                updateFlag = true;
            }
            StoreSettingConfig ssc       = new StoreSettingConfig();
            int itemLargeThumbNailHeight =
                Convert.ToInt32(ssc.GetStoreSettingsByKey(StoreSetting.ItemLargeThumbnailImageHeight, storeId, portalId, culture));
            int itemLargeThumbNailWidth =
                Convert.ToInt32(ssc.GetStoreSettingsByKey(StoreSetting.ItemLargeThumbnailImageWidth, storeId, portalId, culture));
            int itemMediumThumbNailHeight =
                Convert.ToInt32(ssc.GetStoreSettingsByKey(StoreSetting.ItemMediumThumbnailImageHeight, storeId, portalId, culture));
            int itemMediumThumbNailWidth =
                Convert.ToInt32(ssc.GetStoreSettingsByKey(StoreSetting.ItemMediumThumbnailImageWidth, storeId, portalId, culture));
            int itemSmallThumbNailHeight =
                Convert.ToInt32(ssc.GetStoreSettingsByKey(StoreSetting.ItemSmallThumbnailImageHeight, storeId, portalId, culture));
            int itemSmallThumbNailWidth =
                Convert.ToInt32(ssc.GetStoreSettingsByKey(StoreSetting.ItemSmallThumbnailImageWidth, storeId, portalId, culture));
            int  _attributeID           = 0;
            int  _inputTypeID           = 0;
            int  _ValidationTypeID      = 8;
            int  _attributeSetGroupID   = 0;
            bool _isIncludeInPriceRule  = false;
            bool _isIncludeInPromotions = false;
            int  _displayOrder          = 0;

            string sku               = "";
            string activeFrom        = "";
            string activeTo          = "";
            string hidePrice         = "";
            string isHideInRSS       = "";
            string isHideToAnonymous = "";

            bool   toInsertIntoDB    = true;
            bool   isFormValid       = true;
            string imageVar          = string.Empty;
            int    imageCounterFirst = 0;

            ItemsManagementSqlProvider obj = new ItemsManagementSqlProvider();
            var formVars = JSONHelper.Deserialise <List <AspxNameValue> >(itemObj.FormVars);

            //    for (int i = 0; i < formVars.Length; i++)
            for (int i = 0; i < formVars.Count; i++)
            {
                string attribValue = formVars[i].value;
                //string jsonResult = formVars[i].name.Replace('%', '_');
                string         jsonResult     = formVars[i].name.Replace('-', ' ');
                string[]       jsonVar        = jsonResult.Split('_');
                FormValidation formValidation = new FormValidation();

                if (jsonVar.Length > 1)
                {
                    _attributeID           = Int32.Parse(jsonVar[0]);
                    _inputTypeID           = Int32.Parse(jsonVar[1]);
                    _ValidationTypeID      = Int32.Parse(jsonVar[2]);
                    _attributeSetGroupID   = Int32.Parse(jsonVar[4]);
                    _isIncludeInPriceRule  = bool.Parse(jsonVar[5]);
                    _isIncludeInPromotions = bool.Parse(jsonVar[6]);
                    _displayOrder          = Int32.Parse(jsonVar[7]);

                    //Save To Database 1. [aspx_Items] 2. Others
                    if (_attributeID == 4)
                    {
                        sku = formVars[i].value;
                    }
                    else if (_attributeID == 22)
                    {
                        activeFrom = formVars[i].value;
                    }
                    else if (_attributeID == 23)
                    {
                        activeTo = formVars[i].value;
                    }
                    else if (_attributeID == 26)
                    {
                        hidePrice = formVars[i].value;
                    }
                    else if (_attributeID == 27)
                    {
                        isHideInRSS = formVars[i].value;
                    }
                    else if (_attributeID == 28)
                    {
                        isHideToAnonymous = formVars[i].value;
                    }


                    if (itemObj.ItemId == 0 && updateFlag == false)
                    {
                        itemObj.ItemId = obj.AddItem(itemObj, aspxCommonObj, true, isModified, sku, activeFrom, activeTo,
                                                     hidePrice, isHideInRSS, isHideToAnonymous, updateFlag);
                    }
                    else if (itemObj.ItemId > 0 && i == (formVars.Count - 1))
                    {
                        itemObj.ItemId = obj.AddItem(itemObj, aspxCommonObj, true, isModified, sku, activeFrom, activeTo,
                                                     hidePrice, isHideInRSS, isHideToAnonymous, updateFlag);
                    }
                    if (itemObj.ItemId > 0)
                    {
                        if (_inputTypeID == 1)
                        {
                            if (_ValidationTypeID == 3)
                            {
                                if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID, formVars[i].value))
                                {
                                    attribValue = formVars[i].value;
                                }
                                else
                                {
                                    isFormValid = false;
                                    break;
                                }
                            }
                            else if (_ValidationTypeID == 5)
                            {
                                if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID, formVars[i].value))
                                {
                                    attribValue = formVars[i].value;
                                }
                                else
                                {
                                    isFormValid = false;
                                    break;
                                }
                            }
                            else
                            {
                                if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID, formVars[i].value))
                                {
                                    attribValue = formVars[i].value;
                                }
                                else
                                {
                                    isFormValid = false;
                                    break;
                                }
                            }
                        }
                        else if (_inputTypeID == 2)
                        {
                            if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID, formVars[i].value))
                            {
                                attribValue = formVars[i].value;
                            }
                            else
                            {
                                isFormValid = false;
                                break;
                            }
                        }
                        else if (_inputTypeID == 3)
                        {
                            if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID, formVars[i].value))
                            {
                                if (!string.IsNullOrEmpty(formVars[i].value))
                                {
                                    attribValue = formVars[i].value;
                                }
                            }
                            else
                            {
                                isFormValid = false;
                                break;
                            }
                        }
                        else if (_inputTypeID == 4)
                        {
                            if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID, formVars[i].value))
                            {
                                if (!string.IsNullOrEmpty(formVars[i].value))
                                {
                                    attribValue = formVars[i].value;
                                }
                            }
                            else
                            {
                                isFormValid = false;
                                break;
                            }
                        }
                        else if (_inputTypeID == 5 || _inputTypeID == 6 || _inputTypeID == 9 || _inputTypeID == 10 ||
                                 _inputTypeID == 11 || _inputTypeID == 12)
                        {
                            if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID, formVars[i].value))
                            {
                                attribValue = formVars[i].value;
                            }
                            else
                            {
                                isFormValid = false;
                                break;
                            }
                        }
                        else if (_inputTypeID == 7)
                        {
                            if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID, formVars[i].value))
                            {
                                attribValue = formVars[i].value;
                            }
                            else
                            {
                                isFormValid = false;
                                break;
                            }
                        }

                        else if (_inputTypeID == 8)
                        {
                            if (imageCounterFirst % 2 == 0)
                            {
                                toInsertIntoDB = false;
                                if (!string.IsNullOrEmpty(formVars[i].value) &&
                                    formVars[i].value.ToLower() != "undefined")
                                {
                                    if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID,
                                                                     formVars[i].value))
                                    {
                                        imageVar = attribValue;
                                    }
                                    else
                                    {
                                        isFormValid = false;
                                        break;
                                    }
                                }
                                else
                                {
                                    imageVar = "";
                                }
                            }
                            else
                            {
                                toInsertIntoDB = true;

                                if (attribValue != imageVar)
                                {
                                    //_imageVar = _imageVar.Replace("../", "");
                                    imageVar = imageVar.Replace("/", "\\");
                                    //attribValue = attribValue.Replace("../", "");
                                    attribValue = attribValue.Replace("/", "\\");

                                    string tempFolder            = @"Upload\temp";
                                    FileHelperController fileObj = new FileHelperController();
                                    attribValue = fileObj.MoveFileToModuleFolder(tempFolder, attribValue, imageVar,
                                                                                 itemLargeThumbNailHeight,
                                                                                 itemLargeThumbNailWidth,
                                                                                 itemMediumThumbNailHeight,
                                                                                 itemMediumThumbNailWidth,
                                                                                 itemSmallThumbNailHeight,
                                                                                 itemSmallThumbNailWidth,
                                                                                 @"Modules\AspxCommerce\AspxItemsManagement\uploads\",
                                                                                 itemObj.ItemId, "item_");
                                }
                            }
                            imageCounterFirst++;
                        }
                    }
                    if (isFormValid && toInsertIntoDB)
                    {
                        obj.SaveUpdateItemAttributes(itemObj.ItemId, itemObj.AttributeSetId, aspxCommonObj, true,
                                                     isModified,
                                                     attribValue,
                                                     _attributeID, _inputTypeID, _ValidationTypeID, _attributeSetGroupID,
                                                     _isIncludeInPriceRule, _isIncludeInPromotions,
                                                     _displayOrder);
                    }
                }
            }
            if (itemObj.ItemTypeId == 1 || itemObj.ItemTypeId == 2)
            {
                obj.InsertBrandMapping(itemObj.ItemId, itemObj.BrandId, storeId, portalId, userName, culture);
            }
            if (itemObj.ItemVideoIDs != "" || updateFlag == true)
            {
                obj.InsertAndUpdateItemVideos(itemObj.ItemId, itemObj.ItemVideoIDs, aspxCommonObj);
            }
            return(itemObj.ItemId);
        }
        public static int SaveUpdateItemAndAttributes(ItemsInfo.ItemSaveBasicInfo itemObj, AspxCommonInfo aspxCommonObj)
        {
            bool   isModified = false;
            bool   updateFlag = false;
            int    storeId    = aspxCommonObj.StoreID;
            int    portalId   = aspxCommonObj.PortalID;
            string culture    = aspxCommonObj.CultureName;
            string userName   = aspxCommonObj.UserName;

            if (itemObj.ItemId > 0)
            {
                isModified = true;
                updateFlag = true;
            }
            StoreSettingConfig ssc     = new StoreSettingConfig();
            int itemLargeThumbNailSize =
                Convert.ToInt32(ssc.GetStoreSettingsByKey(StoreSetting.ItemLargeThumbnailImageSize, storeId, portalId,
                                                          culture));
            int itemMediumThumbNailSize =
                Convert.ToInt32(ssc.GetStoreSettingsByKey(StoreSetting.ItemMediumThumbnailImageSize, storeId, portalId,
                                                          culture));
            int itemSmallThumbNailSize =
                Convert.ToInt32(ssc.GetStoreSettingsByKey(StoreSetting.ItemSmallThumbnailImageSize, storeId, portalId,
                                                          culture));
            int  _attributeID          = 0;
            int  _inputTypeID          = 0;
            int  _ValidationTypeID     = 8;
            int  _GroupID              = 0;
            bool _isIncludeInPriceRule = false;
            int  _displayOrder         = 0;

            bool   toInsertIntoDB               = true;
            bool   isFormValid                  = true;
            string imageVar                     = string.Empty;
            int    imageCounterFirst            = 0;
            var    formVars                     = JSONHelper.Deserialise <List <AspxNameValue> >(itemObj.FormVars);
            ItemInformationDetailsInfo itemInfo = new ItemInformationDetailsInfo();

            itemInfo.NewFromDate  = "1900/01/01";
            itemInfo.NewToDate    = "2999/12/30";
            itemInfo.FeaturedFrom = "1900/01/01";
            itemInfo.FeaturedTo   = "2999/12/30";
            itemInfo.SpecialFrom  = "1900/01/01";
            itemInfo.SpecialTo    = "2999/12/30";
            List <ItemAttributeDetailsInfo> listItemAttributes = new List <ItemAttributeDetailsInfo>();
            bool   hasSystemAttributesOnly = true;
            string attributeIDs            = "1,2,3,4,5,6,7,8,9,10,11,13,14,15,19,20,23,24,25,26,27,28,29,30,31,32,33,34";

            for (int i = 0; i < formVars.Count; i++)
            {
                string attribValue = formVars[i].value;
                //string jsonResult = formVars[i].name.Replace('%', '_');
                string                   jsonResult     = formVars[i].name.Replace('-', ' ');
                string[]                 jsonVar        = jsonResult.Split('_');
                FormValidation           formValidation = new FormValidation();
                ItemAttributeDetailsInfo itemAttribute  = new ItemAttributeDetailsInfo();

                if (jsonVar.Length > 1)
                {
                    _attributeID                       = Int32.Parse(jsonVar[0]);
                    _inputTypeID                       = Int32.Parse(jsonVar[1]);
                    _ValidationTypeID                  = Int32.Parse(jsonVar[2]);
                    _GroupID                           = Int32.Parse(jsonVar[4]);
                    _isIncludeInPriceRule              = bool.Parse(jsonVar[5]);
                    _displayOrder                      = Int32.Parse(jsonVar[6]);
                    itemAttribute.AttributeID          = _attributeID;
                    itemAttribute.InputTypeID          = _inputTypeID;
                    itemAttribute.ValidationTypeID     = _ValidationTypeID;
                    itemAttribute.GroupID              = _GroupID;
                    itemAttribute.IsIncludeInPriceRule = _isIncludeInPriceRule;
                    itemAttribute.DisplayOrder         = _displayOrder;
                    if (_attributeID > 43)
                    {
                        if (hasSystemAttributesOnly)
                        {
                            hasSystemAttributesOnly = false;
                        }
                    }

                    if (_attributeID == 4)
                    {
                        itemInfo.SKU = formVars[i].value;
                    }
                    else if (_attributeID == 19)
                    {
                        itemInfo.ActiveFrom = formVars[i].value;
                    }
                    else if (_attributeID == 20)
                    {
                        itemInfo.ActiveTo = formVars[i].value;
                    }
                    else if (_attributeID == 23)
                    {
                        itemInfo.HidePrice = Convert.ToBoolean(formVars[i].value);
                    }
                    else if (_attributeID == 24)
                    {
                        itemInfo.HideInRSSFeed = Convert.ToBoolean(formVars[i].value);
                    }
                    else if (_attributeID == 25)
                    {
                        itemInfo.HideToAnonymous = Convert.ToBoolean(formVars[i].value);
                    }
                    else if (_attributeID == 1)
                    {
                        itemInfo.Name = formVars[i].value;
                    }
                    else if (_attributeID == 2)
                    {
                        itemInfo.Description = formVars[i].value;
                    }
                    else if (_attributeID == 3)
                    {
                        itemInfo.ShortDescription = formVars[i].value;
                    }
                    else if (_attributeID == 5)
                    {
                        itemInfo.Weight = Convert.ToDecimal(formVars[i].value);
                    }
                    else if (_attributeID == 6)
                    {
                        itemInfo.NewFromDate = formVars[i].value;
                    }
                    else if (_attributeID == 7)
                    {
                        itemInfo.NewToDate = formVars[i].value;
                    }
                    else if (_attributeID == 8)
                    {
                        itemInfo.Price = Convert.ToDecimal(formVars[i].value);
                    }
                    else if (_attributeID == 9)
                    {
                        itemInfo.MetaTitle = formVars[i].value;
                    }
                    else if (_attributeID == 10)
                    {
                        itemInfo.MetaKeyword = formVars[i].value;
                    }
                    else if (_attributeID == 11)
                    {
                        itemInfo.MetaDescription = formVars[i].value;
                    }
                    else if (_attributeID == 13 && formVars[i].value != "")
                    {
                        itemInfo.ListPrice = Convert.ToDecimal(formVars[i].value);
                    }
                    else if (_attributeID == 14)
                    {
                        itemInfo.VisibilityOptionValueID = Convert.ToInt32(formVars[i].value);
                    }
                    else if (_attributeID == 15)
                    {
                        itemInfo.Quantity = Convert.ToInt32(formVars[i].value);
                    }
                    else if (_attributeID == 26)
                    {
                        itemInfo.IsFeaturedOptionValueID = Convert.ToInt32(formVars[i].value);
                    }
                    else if (_attributeID == 27)
                    {
                        itemInfo.FeaturedFrom = formVars[i].value;
                    }
                    else if (_attributeID == 28)
                    {
                        itemInfo.FeaturedTo = formVars[i].value;
                    }
                    else if (_attributeID == 29)
                    {
                        itemInfo.IsSpecialOptionValueID = Convert.ToInt32(formVars[i].value);
                    }
                    else if (_attributeID == 30)
                    {
                        itemInfo.SpecialFrom = formVars[i].value;
                    }
                    else if (_attributeID == 31)
                    {
                        itemInfo.SpecialTo = formVars[i].value;
                    }
                    else if (_attributeID == 32)
                    {
                        itemInfo.Length = Convert.ToDecimal(formVars[i].value);
                    }
                    else if (_attributeID == 33)
                    {
                        itemInfo.Height = Convert.ToDecimal(formVars[i].value);
                    }
                    else if (_attributeID == 34)
                    {
                        itemInfo.Width = Convert.ToDecimal(formVars[i].value);
                    }
                    else if (_attributeID == 35)
                    {
                        itemInfo.IsPromo = Convert.ToInt32(formVars[i].value);
                    }
                    else if (_attributeID == 37)
                    {
                        itemInfo.ServiceDuration = Convert.ToInt32(formVars[i].value);
                    }
                }

                if (_attributeID == 37)
                {
                    if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID, formVars[i].value))
                    {
                        itemAttribute.IntValue = int.Parse(formVars[i].value);
                        listItemAttributes.Add(itemAttribute);
                    }
                    else
                    {
                        isFormValid = false;
                        break;
                    }
                }
                else if (_attributeID == 35)
                {
                    if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID, formVars[i].value))
                    {
                        itemAttribute.OptionValues = formVars[i].value;
                        listItemAttributes.Add(itemAttribute);
                    }
                    else
                    {
                        isFormValid = false;
                        break;
                    }
                }

                if (_attributeID > 43)
                {
                    if (_inputTypeID == 1)
                    {
                        if (_ValidationTypeID == 3)
                        {
                            if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID, formVars[i].value))
                            {
                                itemAttribute.DecimalValue = decimal.Parse(formVars[i].value);
                            }
                            else
                            {
                                isFormValid = false;
                                break;
                            }
                        }
                        else if (_ValidationTypeID == 5)
                        {
                            if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID, formVars[i].value))
                            {
                                itemAttribute.IntValue = int.Parse(formVars[i].value);
                            }
                            else
                            {
                                isFormValid = false;
                                break;
                            }
                        }
                        else
                        {
                            if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID, formVars[i].value))
                            {
                                itemAttribute.NvarcharValue = formVars[i].value;
                            }
                            else
                            {
                                isFormValid = false;
                                break;
                            }
                        }
                    }
                    else if (_inputTypeID == 2)
                    {
                        if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID, formVars[i].value))
                        {
                            itemAttribute.TextValue = formVars[i].value;
                        }
                        else
                        {
                            isFormValid = false;
                            break;
                        }
                    }
                    else if (_inputTypeID == 3)
                    {
                        if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID, formVars[i].value))
                        {
                            if (!string.IsNullOrEmpty(formVars[i].value))
                            {
                                itemAttribute.DateValue = DateTime.Parse(formVars[i].value);
                            }
                        }
                        else
                        {
                            isFormValid = false;
                            break;
                        }
                    }
                    else if (_inputTypeID == 4)
                    {
                        if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID, formVars[i].value))
                        {
                            if (!string.IsNullOrEmpty(attribValue))
                            {
                                itemAttribute.BooleanValue = (formVars[i].value == "1" ||
                                                              formVars[i].value.ToLower() == "true")
                                                                 ? true
                                                                 : false;
                            }
                            else
                            {
                                itemAttribute.BooleanValue = false;
                            }
                        }
                        else
                        {
                            isFormValid = false;
                            break;
                        }
                    }
                    else if (_inputTypeID == 5 || _inputTypeID == 6 || _inputTypeID == 9 || _inputTypeID == 10 ||
                             _inputTypeID == 11 || _inputTypeID == 12)
                    {
                        if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID, formVars[i].value))
                        {
                            itemAttribute.OptionValues = formVars[i].value;
                        }
                        else
                        {
                            isFormValid = false;
                            break;
                        }
                    }
                    else if (_inputTypeID == 7)
                    {
                        if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID, formVars[i].value))
                        {
                            itemAttribute.DecimalValue = decimal.Parse(formVars[i].value);
                        }
                        else
                        {
                            isFormValid = false;
                            break;
                        }
                    }

                    else if (_inputTypeID == 8)
                    {
                        if (imageCounterFirst % 2 == 0)
                        {
                            toInsertIntoDB = false;
                            if (!string.IsNullOrEmpty(formVars[i].value) &&
                                formVars[i].value.ToLower() != "undefined")
                            {
                                if (formValidation.ValidateValue(formVars[i].name, _ValidationTypeID,
                                                                 formVars[i].value))
                                {
                                    imageVar = attribValue;
                                }
                                else
                                {
                                    isFormValid = false;
                                    break;
                                }
                            }
                            else
                            {
                                imageVar = "";
                            }
                        }
                        else
                        {
                            toInsertIntoDB = true;

                            if (attribValue != imageVar)
                            {
                                //_imageVar = _imageVar.Replace("../", "");
                                imageVar = imageVar.Replace("/", "\\");
                                //attribValue = attribValue.Replace("../", "");
                                attribValue = attribValue.Replace("/", "\\");

                                string tempFolder            = @"Upload\temp";
                                FileHelperController fileObj = new FileHelperController();
                                attribValue = fileObj.MoveFileToModuleFolder(tempFolder, attribValue, imageVar,
                                                                             itemLargeThumbNailSize,
                                                                             itemMediumThumbNailSize,
                                                                             itemSmallThumbNailSize,
                                                                             @"Modules\AspxCommerce\AspxItemsManagement\uploads\",
                                                                             itemObj.ItemId, "item_");
                                itemAttribute.FileValue =
                                    attribValue.Replace(@"Modules\AspxCommerce\AspxItemsManagement\uploads\", " ");
                            }
                            else
                            {
                                itemAttribute.FileValue =
                                    attribValue.Replace(@"Modules\AspxCommerce\AspxItemsManagement\uploads\", " ");
                            }
                        }
                        imageCounterFirst++;
                    }
                    if (toInsertIntoDB)
                    {
                        listItemAttributes.Add(itemAttribute);
                    }
                }
            }
            if (isFormValid)
            {
                itemObj.ItemId = AspxItemMgntProvider.SaveUpdateItemAttributes(itemObj, aspxCommonObj, true,
                                                                               isModified, itemInfo,
                                                                               listItemAttributes, attributeIDs,
                                                                               hasSystemAttributesOnly, updateFlag);
            }
            else
            {
                throw new Exception("Form is not valid one");
            }

            return(itemObj.ItemId);
        }
        //public int SaveCategory(Int32 storeID, Int32 portalID, Int32 categoryID, Int32 parentID, AspxNameValue[] formVars, string selectedItems, string userName, string culture, int categoryLargeThumbImage, int categoryMediumThumbImage, int categorySmallThumbImage)
        //{
        public int SaveCategory(CategoryInfo.CategorySaveBasicInfo categoryObj, AspxCommonInfo aspxCommonObj)
        {
            try
            {
                int            catID;
                CategoryInfo   categoryInfo   = new CategoryInfo();
                FormValidation formValidation = new FormValidation();
                List <CategoryAttributeInfo> listCategoryAttributes = new List <CategoryAttributeInfo>();
                categoryInfo.CategoryID      = categoryObj.CategoryId; //categoryID;
                categoryInfo.ParentID        = categoryObj.ParentId;   //parentID;
                categoryInfo.IsShowInCatalog = true;
                categoryInfo.IsShowInMenu    = true;
                categoryInfo.IsShowInSearch  = true;
                categoryInfo.PortalID        = aspxCommonObj.PortalID;
                categoryInfo.StoreID         = aspxCommonObj.StoreID;
                categoryInfo.ActiveFrom      = new DateTime(1970, 1, 1);
                categoryInfo.ActiveTo        = new DateTime(2999, 12, 30);
                bool toInsertIntoDB = true;
                bool isFormValid    = true;
                //int _imageCounter = 0;
                string imageVar          = string.Empty;
                int    imageCounterFirst = 0;

                var formVarss = JSONHelper.Deserialise <List <AspxNameValue> >(categoryObj.FormVars);


                foreach (var formVars in formVarss)
                {
                    int      inputTypeID;
                    int      validationTypeID;
                    string   attribName  = formVars.name;
                    string   attribValue = formVars.value;
                    string   jsonResult  = formVars.name.Replace('-', ' ');
                    string[] jsonVar     = jsonResult.Split('_');

                    CategoryAttributeInfo categoryAttribute = new CategoryAttributeInfo();
                    categoryAttribute.AttributeID = int.Parse(jsonVar[0]);
                    inputTypeID      = int.Parse(jsonVar[1]);
                    validationTypeID = int.Parse(jsonVar[2]);
                    if (inputTypeID == 1)
                    {
                        if (validationTypeID == 3)
                        {
                            if (formValidation.ValidateValue(attribName, validationTypeID, attribValue))
                            {
                                categoryAttribute.InputTypeID      = inputTypeID;
                                categoryAttribute.ValidationTypeID = validationTypeID;
                                categoryAttribute.DecimalValue     = decimal.Parse(attribValue);
                            }
                            else
                            {
                                isFormValid = false;
                                break;
                            }
                        }
                        else if (validationTypeID == 5)
                        {
                            if (formValidation.ValidateValue(attribName, validationTypeID, attribValue))
                            {
                                categoryAttribute.InputTypeID      = inputTypeID;
                                categoryAttribute.ValidationTypeID = validationTypeID;
                                categoryAttribute.IntValue         = Int32.Parse(attribValue);
                            }
                            else
                            {
                                isFormValid = false;
                                break;
                            }
                        }
                        else
                        {
                            if (formValidation.ValidateValue(attribName, validationTypeID, attribValue))
                            {
                                categoryAttribute.InputTypeID      = inputTypeID;
                                categoryAttribute.ValidationTypeID = validationTypeID;
                                categoryAttribute.NvarcharValue    = attribValue;
                            }
                            else
                            {
                                isFormValid = false;
                                break;
                            }
                        }
                    }
                    else if (inputTypeID == 2)
                    {
                        if (formValidation.ValidateValue(attribName, validationTypeID, attribValue))
                        {
                            categoryAttribute.InputTypeID      = inputTypeID;
                            categoryAttribute.ValidationTypeID = validationTypeID;
                            categoryAttribute.TextValue        = attribValue;
                        }
                        else
                        {
                            isFormValid = false;
                            break;
                        }
                    }
                    else if (inputTypeID == 3)
                    {
                        if (formValidation.ValidateValue(attribName, validationTypeID, attribValue))
                        {
                            categoryAttribute.InputTypeID      = inputTypeID;
                            categoryAttribute.ValidationTypeID = validationTypeID;
                            if (!string.IsNullOrEmpty(attribValue))
                            {
                                categoryAttribute.DateValue = DateTime.Parse(attribValue);
                            }
                        }
                        else
                        {
                            isFormValid = false;
                            break;
                        }
                    }
                    else if (inputTypeID == 4)
                    {
                        if (formValidation.ValidateValue(attribName, validationTypeID, attribValue))
                        {
                            categoryAttribute.InputTypeID      = inputTypeID;
                            categoryAttribute.ValidationTypeID = validationTypeID;
                            if (!string.IsNullOrEmpty(attribValue))
                            {
                                categoryAttribute.BooleanValue = (attribValue == "1" || attribValue.ToLower() == "true")? true: false;
                            }
                            else
                            {
                                categoryAttribute.BooleanValue = false;
                            }
                        }
                        else
                        {
                            isFormValid = false;
                            break;
                        }
                    }
                    else if (inputTypeID == 5 || inputTypeID == 6 || inputTypeID == 9 || inputTypeID == 10 ||
                             inputTypeID == 11 || inputTypeID == 12)
                    {
                        if (formValidation.ValidateValue(attribName, validationTypeID, attribValue))
                        {
                            categoryAttribute.InputTypeID      = inputTypeID;
                            categoryAttribute.ValidationTypeID = validationTypeID;
                            categoryAttribute.OptionValues     = attribValue;
                        }
                        else
                        {
                            isFormValid = false;
                            break;
                        }
                    }
                    else if (inputTypeID == 7)
                    {
                        if (formValidation.ValidateValue(attribName, validationTypeID, attribValue))
                        {
                            categoryAttribute.InputTypeID      = inputTypeID;
                            categoryAttribute.ValidationTypeID = validationTypeID;
                            categoryAttribute.DecimalValue     = decimal.Parse(attribValue);
                        }
                        else
                        {
                            isFormValid = false;
                            break;
                        }
                    }
                    else if (inputTypeID == 8)
                    {
                        if (imageCounterFirst % 2 == 0)
                        {
                            toInsertIntoDB = false;
                            if (!string.IsNullOrEmpty(attribValue) && attribValue.ToLower() != "undefined")
                            {
                                if (formValidation.ValidateValue(attribName, validationTypeID, attribValue))
                                {
                                    imageVar = attribValue;
                                }
                                else
                                {
                                    isFormValid = false;
                                    break;
                                }
                            }
                            else
                            {
                                imageVar = "";
                            }
                        }
                        else
                        {
                            toInsertIntoDB = true;

                            categoryAttribute.InputTypeID      = inputTypeID;
                            categoryAttribute.ValidationTypeID = validationTypeID;
                            //_imageVar = _imageVar.Replace("../", "");

                            if (attribValue != imageVar)
                            {
                                imageVar = imageVar.Replace("/", "\\");
                                //attribValue = attribValue.Replace("../", "");
                                attribValue = attribValue.Replace("/", "\\");

                                string tempFolder            = @"Upload\temp";
                                FileHelperController fileObj = new FileHelperController();
                                //attribValue = fileObj.MoveFileToModuleFolder(tempFolder, attribValue, imageVar,categoryLargeThumbImage,categoryMediumThumbImage,categorySmallThumbImage,
                                //                                             @"Modules\AspxCommerce\AspxCategoryManagement\uploads\",
                                //                                             categoryID, "cat_");
                                attribValue = fileObj.MoveFileToModuleFolder(tempFolder, attribValue, imageVar,
                                                                             categoryObj.LargeThumbNailImageSize,
                                                                             categoryObj.MediumImageSize,
                                                                             categoryObj.SmallImageSize,
                                                                             @"Modules\AspxCommerce\AspxCategoryManagement\uploads\",
                                                                             categoryObj.CategoryId, "cat_");
                                categoryAttribute.FileValue = attribValue;
                            }
                            //else if (_imageVar == "")
                            //{
                            //    categoryAttribute.FileValue = _imageVar;
                            //}
                            else
                            {
                                categoryAttribute.FileValue = attribValue;
                            }
                        }
                        imageCounterFirst++;
                    }
                    if (toInsertIntoDB)
                    {
                        listCategoryAttributes.Add(categoryAttribute);
                    }
                }

                if (isFormValid)
                {
                    CategorySqlProvider categorySqlProvider = new CategorySqlProvider();
                    //    categoryInfo = categorySqlProvider.CategoryAddUpdate(categoryInfo, selectedItems, listCategoryAttributes, userName, culture);
                    // catID = categorySqlProvider.CategoryAddUpdate(categoryInfo, selectedItems, listCategoryAttributes, userName, culture);
                    catID = categorySqlProvider.CategoryAddUpdate(categoryInfo, categoryObj.SelectedItems,
                                                                  listCategoryAttributes, aspxCommonObj.UserName,
                                                                  aspxCommonObj.CultureName);
                }
                else
                {
                    throw new Exception("Form is not valid one");
                }
                //return categoryInfo;
                return(catID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }