public ActionResult Edit(string id = null, string Category=null)
        {
            ModelCategory model = new ModelCategory();

            if (string.IsNullOrWhiteSpace(id))
            {
                model.Parentcateg = Category;
                model.Createdate = DateTime.Now;
                ViewBag.Categorys = base.QueryCategoryAll(string.IsNullOrWhiteSpace(Category) ? null : Category);
                return View(model);
            }
            else
            {
                var idx = 0;
                int.TryParse(id, out idx);
                var resultMsg = string.Empty;
                LogicCategory logic = new LogicCategory();
                model = logic.CategoryDetail(out resultMsg,base.AuthorizeInfo, idx);
                if (model != null && string.IsNullOrWhiteSpace(model.Parentcateg)==false)
                {
                    ViewBag.Categorys = base.QueryCategoryAll(model.Parentcateg.ToString());
                }
                else
                {
                    ViewBag.Categorys = base.QueryCategoryAll();
                }

                if (resultMsg.Contains(BaseDict.ErrorPrefix))
                {
                    ViewBag.CustomScript = UtilityScript.ShowMessage(resultMsg, isCreate: true, isSuccess: true);
                }
                return View(model);
            }
        }
 public void CategoryDetailTest()
 {
     var resultMsg = string.Empty;
     LogicCategory logic = new LogicCategory();
     var model = logic.CategoryDetail(out resultMsg,"", 2);
     ModelCategory model1 = null;
     Assert.AreNotEqual(model, model1);
 }
 /// <summary>
 /// 查询版块下所有分类
 /// </summary>
 /// <param name="selected">选中项</param> 
 protected IList<SelectListItem> QueryCategoryAll(string selected = null)
 {
     string resultMsg = string.Empty;
     LogicCategory dalCategory = new LogicCategory();
     var list = dalCategory.CategoryAllThree(out resultMsg,this.AuthorizeInfo, ParentCateg: 0);
     var slist = (from ModelCategory model in list
                  select new SelectListItem()
                  {
                      Selected = model.Id.ToString().Equals(selected) ? true : false,
                      Text = model.Name,
                      Value = model.Id.ToString()
                  }).ToList();
     return slist;
 }
        public ActionResult Delete(string Id)
        {
            int idx = 0;
            int.TryParse(Id, out idx);
            var result = new ResultBase();
            var resultMsg = string.Empty;
            LogicCategory logic = new LogicCategory();
            var res = logic.CategoryDelete(out resultMsg,base.AuthorizeInfo, idx);
            if (res > 0)
            {
                result.result = 1;
                result.resultMsg = "删除成功!";
            }
            else
            {
                result.result = -1;
                result.resultMsg = string.IsNullOrWhiteSpace(resultMsg) ? "删除失败!" : resultMsg;
            }

            return Json(result);
        }
        public ActionResult Edit(ModelCategory model, FormCollection fc)
        {
            var resultMsg = string.Empty;
            ViewBag.Categorys = base.QueryCategoryAll(model.Parentcateg);
            var result = new ResultBase();

            //图片上传
            var fileName = CommonMethod.ImageUpload(out result, this.HttpContext);
            if (result.result == -2)
            {
                ViewBag.CustomScript = UtilityScript.ShowMessage(result.resultMsg, isCreate: true);
                return View(model);
            }
            model.Parentcateg = string.IsNullOrWhiteSpace(model.Parentcateg) ? "0" : model.Parentcateg;
            model.Thumbnails = string.IsNullOrWhiteSpace(fileName) ? model.Thumbnails : fileName;
            model.Introduction = fc["editorValue"];

            //数据保存
            LogicCategory logic = new LogicCategory();
            var res = logic.CategoryInsertUpdate(out resultMsg,base.AuthorizeInfo, model);
            if (res > 0)
            {
                resultMsg = "操作成功!";
                ViewBag.CustomScript = UtilityScript.ShowMessage(resultMsg, isCreate: true, isSuccess: true, funName: "Goto");
            }
            else
            {
                resultMsg = "操作失败,请检查数据是否正确后重新操作!";
                ViewBag.CustomScript = UtilityScript.ShowMessage(resultMsg, isCreate: true, isSuccess: true, funName: "BtnShow");
            }
            return View(model);
        }
        public ActionResult Tree(FormCollection fc)
        {
            string resultMsg = string.Empty;
            LogicCategory logic = new LogicCategory();
            var list = logic.CategoryAllThree(out resultMsg,base.AuthorizeInfo, ParentCateg: 0);

            var listTree = (from ModelCategory model in list
                            select new ModelTree() {
                                id = model.Id.ToString(),
                                name = model.Name,
                                pId = model.Parentcateg.ToString() }).ToList();

            return Json(listTree);
        }