public CategoryInfo SaveCategory(Int32 storeID, Int32 portalID, Int32 categoryID, Int32 parentID, AspxNameValue[] formVars, string selectedItems, string userName, string culture, int categoryLargeThumbImage, int categoryMediumThumbImage, int categorySmallThumbImage) { try { CategoryInfo categoryInfo = new CategoryInfo(); FormValidation formValidation = new FormValidation(); List<CategoryAttributeInfo> listCategoryAttributes = new List<CategoryAttributeInfo>(); categoryInfo.CategoryID = categoryID; categoryInfo.ParentID = parentID; categoryInfo.IsShowInCatalog = true; categoryInfo.IsShowInMenu = true; categoryInfo.IsShowInSearch = true; categoryInfo.PortalID = portalID; categoryInfo.StoreID = 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; for (int i = 0; i < formVars.Length; i++) { int inputTypeID; int validationTypeID; string attribName = formVars[i].name; string attribValue = formVars[i].value; string jsonResult = formVars[i].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_"); 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); } else { throw new Exception("Form is not valid one"); } return categoryInfo; } catch (Exception ex) { throw ex; } }
public string SaveCategory(Int32 storeID, Int32 portalID, Int32 categoryID, Int32 parentID, AspxNameValue[] formVars, string selectedItems, string userName, string culture, int categoryLargeThumbImage, int categoryMediumThumbImage, int categorySmallThumbImage) { try { CategoryController categoryController = new CategoryController(); categoryController.SaveCategory(storeID, portalID, categoryID, parentID, formVars, selectedItems, userName, culture, categoryLargeThumbImage, categoryMediumThumbImage, categorySmallThumbImage); if (parentID > 0) { return "({\"returnStatus\":1,\"Message\":\"Sub category has been saved successfully.\"})"; } else { return "({\"returnStatus\":1,\"Message\":\"Category has been saved 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 saving category!\"})"; } } }
public void SaveItemAndAttributes(int itemID, int itemTypeID, int attributeSetID, int storeID, int portalID, string userName, string culture, int taxRuleID, string categoriesIds, string relatedItemsIds, string upSellItemsIds, string crossSellItemsIds, string downloadItemsValue, string sourceFileCol, string dataCollection, AspxNameValue[] formVars) { try { string uplodedDownlodableFormValue = string.Empty; if (itemTypeID == 2 && downloadItemsValue != "") { FileHelperController downLoadableObj = new FileHelperController(); string tempFolder = @"Upload\temp"; uplodedDownlodableFormValue = downLoadableObj.MoveFileToDownlodableItemFolder(tempFolder, downloadItemsValue, @"Modules/AspxCommerce/AspxItemsManagement/DownloadableItems/", itemID, "item_"); } ItemsController itemController = new ItemsController(); itemID = itemController.SaveUpdateItemAndAttributes(itemID, itemTypeID, attributeSetID, storeID, portalID, userName, culture, taxRuleID, categoriesIds, relatedItemsIds, upSellItemsIds, crossSellItemsIds, uplodedDownlodableFormValue, formVars); //return "({\"returnStatus\":1,\"Message\":'Item saved successfully.'})"; if (itemID > 0 && sourceFileCol != "" && dataCollection != "") { 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)); dataCollection = dataCollection.Replace("../", ""); SaveImageContents(itemID, @"Modules/AspxCommerce/AspxItemsManagement/uploads/", sourceFileCol, dataCollection, itemLargeThumbNailSize, itemMediumThumbNailSize, itemSmallThumbNailSize, "item_"); } else if (itemID > 0 && sourceFileCol == "" && dataCollection == "") { DeleteImageContents(itemID); } //if (itemID==0) //{ // //SaveImageContents(itemID, @"Modules/AspxCommerce/AspxItemsManagement/uploads/", sourceFileCol, dataCollection, "item_"); // //TODO:: DELTE UPLOADED FILE FROM DOWNLOAD FOLDER //} } catch (Exception ex) { throw ex; //ErrorHandler errHandler = new ErrorHandler(); //if (errHandler.LogWCFException(ex)) //{ // return "({\"returnStatus\":-1,\"errorMessage\":'" + ex.Message + "'})"; //} //else //{ // return "({\"returnStatus\":-1,\"errorMessage\":'Error while saving item!'})"; //} } }
public int SaveUpdateItemAndAttributes(int itemID, int itemTypeID, int attributeSetID, int storeID, int portalID, string userName, string culture, int taxClassID, string categoriesIDs, string relatedItemsIDs, string upSellItemsIDs, string crossSellItemsIDs, string downloadItemsValue, AspxNameValue[] formVars) { bool isModified = false; bool updateFlag = false; if (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 _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(); for (int i = 0; i < formVars.Length; 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 (itemID == 0 && updateFlag == false) { itemID = obj.AddItem(itemID, itemTypeID, attributeSetID, taxClassID, storeID, portalID, userName, culture, true, isModified, sku, activeFrom, activeTo, hidePrice, isHideInRSS, isHideToAnonymous, categoriesIDs, relatedItemsIDs, upSellItemsIDs, crossSellItemsIDs, downloadItemsValue, updateFlag); } else if (itemID > 0 && i == formVars.Length - 1) { itemID = obj.AddItem(itemID, itemTypeID, attributeSetID, taxClassID, storeID, portalID, userName, culture, true, isModified, sku, activeFrom, activeTo, hidePrice, isHideInRSS, isHideToAnonymous, categoriesIDs, relatedItemsIDs, upSellItemsIDs, crossSellItemsIDs, downloadItemsValue, updateFlag); } if (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, itemLargeThumbNailSize, itemMediumThumbNailSize, itemSmallThumbNailSize, @"Modules\AspxCommerce\AspxItemsManagement\uploads\", itemID, "item_"); } } imageCounterFirst++; } } if (isFormValid && toInsertIntoDB) { obj.SaveUpdateItemAttributes(itemID, attributeSetID, storeID, portalID, userName, culture, true, isModified, attribValue, _attributeID, _inputTypeID, _ValidationTypeID, _attributeSetGroupID, _isIncludeInPriceRule, _isIncludeInPromotions, _displayOrder); } } } return itemID; }