using System;
using System.Linq;
using System.Collections.Generic;
using DAL;
using BLL;
using Common;
using System.Web.Mvc;
using ^m_Application^.Models;
using Models;
namespace ^m_Application^.Controllers
{
    /// <summary>
    /// ^ReplaceClassName^树形结构
    /// </summary>
    public class ^ReplaceClassCode^TreeController : BaseController
    {
        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 获取树形页面的数据
        /// </summary>
        /// <returns></returns>
        public ActionResult GetTree()
        {
            List<SystemTree> listSystemTree = new List<SystemTree>();
            
            IBLL.I^ReplaceClassCode^BLL db = new ^ReplaceClassCode^BLL();
         
            ^ReplaceClassCode^TreeNodeCollection tree = new ^ReplaceClassCode^TreeNodeCollection();

            var trees = db.GetAll().OrderBy(o => o.^m_Id^);
            if (trees != null)
            {
                string parentId = Request["parentid"];//父节点编号
                if (string.IsNullOrWhiteSpace(parentId))
                {
                    tree.Bind(trees, null, ref listSystemTree);
                }
                else
                {
                    tree.Bind(trees, ^parentId^, ref listSystemTree);
                }
            }           
            return Json(listSystemTree, JsonRequestBehavior.AllowGet);
        }
    }
}
