Exemplo n.º 1
0
        //[ValidateAntiForgeryToken]
        public JsonResult EditMainImage(int id, int primary)
        {
            var oldMain = _db.images.Where(x => x.articlesId == id && x.isMain == true).FirstOrDefault();

            var newMain = _db.images.Where(x => x.articlesId == id && x.Id == primary).FirstOrDefault();

            if (oldMain != null)
            {
                oldMain.isMain = false;
            }
            if (newMain != null)
            {
                newMain.isMain = true;
            }
            else
            {
                oldMain.isMain = true;
            }
            _db.SaveChanges();
            return(Json(new { success = true }));
        }
        //add new category
        public ActionResult AddNewCategory(string categoryName)
        {
            var categories = _db.categories;

            if (categories.Count(e => e.name == categoryName) == 0)
            {
                _db.categories.Add(new categories()
                {
                    Id = 0, name = categoryName
                });
                _db.SaveChanges();
            }

            var list = _db.categories.ToList();

            list.Insert(list.Count, new categories()
            {
                Id = 0, name = "სხვა"
            });
            var result = list.OrderByDescending(e => e.Id).Select(c => new { Id = c.Id, name = c.name });

            return(Json(result, JsonRequestBehavior.AllowGet));
        }