예제 #1
0
        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;
            }
        }
예제 #2
0
 public List<CategoryItemInfo> GetCategoryItems(Int32 offset, Int32 limit, Int32 categoryID, string sku, string name, System.Nullable<decimal> priceFrom, System.Nullable<decimal> priceTo, Int32 storeID, Int32 portalID, string userName, string culture)
 {
     try
     {
         List<CategoryItemInfo> listCategoryItem = new List<CategoryItemInfo>();
         CategorySqlProvider categorySqlProvider = new CategorySqlProvider();
         listCategoryItem = categorySqlProvider.GetCategoryItems(offset, limit, categoryID, sku, name, priceFrom, priceTo, storeID, portalID, userName, culture);
         return listCategoryItem;
     }
     catch (Exception ex)
     {
         ErrorHandler errHandler = new ErrorHandler();
         errHandler.LogWCFException(ex);
         throw ex;
     }
 }
예제 #3
0
 public string SaveChangesCategoryTree(Int32 storeID, Int32 portalID, string categoryIDs, string userName)
 {
     try
     {
         CategorySqlProvider categorySqlProvider = new CategorySqlProvider();
         categorySqlProvider.SaveChangesCategoryTree(storeID, portalID, categoryIDs, userName);
         return "({ \"returnStatus\" : 1 , \"Message\" : \"Save category tree 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 tree!\" })";
         }
     }
 }
예제 #4
0
 public string DeleteCategory(Int32 storeID, Int32 portalID, Int32 categoryID, string userName, string culture)
 {
     try
     {
         CategorySqlProvider categorySqlProvider = new CategorySqlProvider();
         categorySqlProvider.DeleteCategory(storeID, portalID, categoryID, userName, culture);
         return "({ \"returnStatus\" : 1 , \"Message\" : \"Category delete 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 category!\" })";
         }
     }
 }
예제 #5
0
 public List<CategoryAttributeInfo> GetCategoryByCategoryID(Int32 categoryID, Int32 storeID, Int32 portalID, string userName, string culture)
 {
     CategorySqlProvider categorySqlProvider = new CategorySqlProvider();
     List<CategoryAttributeInfo> catList = categorySqlProvider.GetCategoryByCategoryID(categoryID, storeID, portalID, userName, culture);
     return catList;
 }
예제 #6
0
 public List<CategoryInfo> GetCategoryAll(bool isActive, Int32 storeID, Int32 portalID, string userName, string culture)
 {
     try
     {
         CategorySqlProvider categorySqlProvider = new CategorySqlProvider();
         List<CategoryInfo> catList = categorySqlProvider.GetCategoryAll(isActive, storeID, portalID, userName, culture);
         return catList;
     }
     catch (Exception ex)
     {
         ErrorHandler errHandler = new ErrorHandler();
         errHandler.LogWCFException(ex);
         throw ex;
     }
 }
예제 #7
0
 public List<AttributeFormInfo> GetCategoryFormAttributes(Int32 categoryID, Int32 portalID, Int32 storeID, string userName, string culture)
 {
     try
     {
         CategorySqlProvider categorySqlProvider = new CategorySqlProvider();
         List<AttributeFormInfo> frmFieldList = categorySqlProvider.GetCategoryFormAttributes(categoryID, portalID, storeID, userName, culture);
         return frmFieldList;
     }
     catch (Exception ex)
     {
         ErrorHandler errHandler = new ErrorHandler();
         errHandler.LogWCFException(ex);
         throw ex;
     }
 }
예제 #8
0
 public bool CheckUniqueCategoryName(string catName, int catId, int storeId, int portalId, string cultureName)
 {
     try
     {
         CategorySqlProvider obj = new CategorySqlProvider();
         return obj.CheckUniqueName(catName, catId, storeId, portalId, cultureName);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }