public ActionResult Add(string categoryTitle, string categoryTitleSelected)
        {
            categoryTitle = categoryTitle.Trim();

            // if it's empty then
            if (string.IsNullOrEmpty(categoryTitle))
            {
                return(SendJsonErrorResponse("Empty category name"));
            }

            var category = new productCategory
            {
                masterID  = string.IsNullOrEmpty(categoryTitleSelected) ? repository.AddMasterProductCategory(categoryTitle).id : long.Parse(categoryTitleSelected),
                details   = "",
                subdomain = subdomainid.Value
            };


            try
            {
                repository.AddProductCategory(category, subdomainid.Value);
            }
            catch (Exception ex)
            {
                return(SendJsonErrorResponse(ex));
            }

            if (category.id == 0)
            {
                return(Json(string.Format("Category <strong>{0}</strong> already exist", categoryTitle).ToJsonFail()));
            }

            return(Json(category.ToModel().ToJsonOKData()));
        }
        public ActionResult AddSub(string id, string categoryTitle, string categoryTitleSelected)
        {
            categoryTitle = categoryTitle.Trim();

            // if it's empty then
            if (string.IsNullOrEmpty(categoryTitle))
            {
                return(SendJsonErrorResponse("Empty category name"));
            }

            // check if subcategory already exist
            if (string.IsNullOrEmpty(id))
            {
                return(SendJsonErrorResponse("Missing category id"));
            }
            var parentid      = long.Parse(id);
            var subcategories = repository.GetProductCategories(parentid, subdomainid.Value);

            if (subcategories.Where(x => x.MASTERproductCategory.name == categoryTitle).Count() != 0)
            {
                return(SendJsonErrorResponse(string.Format("Subcategory <strong>{0}</strong> already exists", categoryTitle)));
            }

            var category = new productCategory
            {
                masterID  = string.IsNullOrEmpty(categoryTitleSelected) ? repository.AddMasterProductCategory(categoryTitle).id : long.Parse(categoryTitleSelected),
                details   = "",
                subdomain = subdomainid.Value,
                parentID  = parentid
            };

            try
            {
                repository.AddProductCategory(category, subdomainid.Value);
            }
            catch (Exception ex)
            {
                return(SendJsonErrorResponse(ex));
            }

            if (category.id == 0)
            {
                return(SendJsonErrorResponse(string.Format("Subcategory <strong></strong> already exists", categoryTitle)));
            }

            return(Json(category.ToModel().ToJsonOKData()));
        }