/// <summary>
        /// 课程分类
        /// </summary>
        /// <returns></returns>
        public ActionResult GetCateTreeSelectJson()
        {
            var data     = _coreCategoryService.GetCourseCategoryList();
            var treeList = new List <TreeSelectModel>();

            foreach (var item in data)
            {
                TreeSelectModel treeModel = new TreeSelectModel();
                treeModel.id       = item.CategoryId + "";
                treeModel.text     = item.CourseCategoryName;
                treeModel.parentId = item.ParentId + "";
                treeList.Add(treeModel);
            }
            return(Content(treeList.TreeSelectJson()));
        }
Beispiel #2
0
        public ActionResult saveOrUpdate(string strlist)
        {
            try
            {
                //因为页面操作是修改删除添加全由一个保存按钮来实现的
                //所以这里的保存要原来的数据全部删掉然后再重新添加最简单
                //但是如果部门表有关联表且关联的是id可能会有问题,可以改为关联名称,且名称不重复就能避免
                JavaScriptSerializer jss = new JavaScriptSerializer();
                var treelist             = jss.Deserialize <List <TreeView> >(strlist);
                var dtolist = treelist.TreeViewToCDto();
                foreach (var item in dtolist)
                {
                    if (item.IsNew)
                    {
                        if (item.ParentId > 0)
                        {
                            var date = _corecategoryService.GetCourseCategoryList().FirstOrDefault(t => t.CategoryId == item.ParentId);
                            if (date != null)
                            {
                                item.Path = date.Path + item.CategoryId + "/";
                            }
                        }
                        else
                        {
                            item.Path = item.CategoryId + "/";
                        }

                        item.IsNew = false;
                        _corecategoryService.CreateCourseCategory(item);
                    }
                    else
                    {
                        string sqlstr = "update px_course_category set name=@name ,update_time=@update_time, updater=@updater where category_id=@category_id";
                        var    i      = _sqlExecuter.Execute(sqlstr,
                                                             new MySqlParameter("@name", item.CourseCategoryName),
                                                             new MySqlParameter("@update_time", DateTime.Now),
                                                             new MySqlParameter("@updater", 1),
                                                             new MySqlParameter("@category_id", item.CategoryId));
                    }
                }
                return(Content("添加成功!"));
            }
            catch (Exception e)
            {
                return(Content("添加失败!"));
            }
        }