Esempio n. 1
0
 public JsonResult CreateNewCategory(string name, int parent_id)
 {
     using (IPosEntities ctx = new IPosEntities())
     {
         try
         {
             Product_Categories _new_category = new Product_Categories();
             _new_category.ID        = ctx.Product_Categories.Any() ? ctx.Product_Categories.Max(b => b.ID) + 1 : 1;
             _new_category.Name      = name;
             _new_category.Parent_ID = parent_id;
             ctx.Product_Categories.Add(_new_category);
             ctx.SaveChanges();
             return(Json("OK", JsonRequestBehavior.AllowGet));
         }
         catch (Exception ex)
         {
             string msg = ex.Message;
             while (ex.InnerException != null)
             {
                 ex  = ex.InnerException;
                 msg = ex.Message;
             }
             return(Json("ERR:" + msg, JsonRequestBehavior.AllowGet));
         }
     }
 }
Esempio n. 2
0
        public String RenameCategory(string catgName, int id)
        {
            using (Liquor_ShopEntities _dbContext = new Liquor_ShopEntities())
            {
                if (_dbContext.Product_Categories.Any(c => c.CategoryName == catgName))
                {
                    return("titletaken");
                }

                Product_Categories catg = _dbContext.Product_Categories.Find(id);
                catg.CategoryName = catgName;
                catg.Slug         = catgName.Replace(" ", "-").ToLower();
                _dbContext.SaveChanges();
            };
            return("ok");
        }
Esempio n. 3
0
        public string AddCategory(string category)
        {
            string id;

            using (Liquor_ShopEntities _dbContext = new Liquor_ShopEntities())
            {
                if (_dbContext.Product_Categories.Any(c => c.CategoryName == category))
                {
                    return("titletaken");
                }

                Product_Categories cat = new Product_Categories
                {
                    CategoryName = category,
                    Slug         = category.Replace(" ", "-").ToLower(),
                    Sorting      = 100,
                };
                _dbContext.Product_Categories.Add(cat);
                _dbContext.SaveChanges();
                id = cat.CatgId.ToString();
            }
            return(id);
        }